Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
Classes | Functions
game.h File Reference
#include "ccfwd.h"
#include "message.h"
#include "piece.h"
#include "pieces.h"
#include "action_history.h"
#include "starting_position_type.h"
#include "fen_string.h"
#include <iosfwd>
#include <vector>
#include <optional>
Include dependency graph for game.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  game
 The game logic. More...
 

Functions

bool can_castle_kingside (const piece &p, const game &g) noexcept
 Can this piece castle kingside?
 
bool can_castle_queenside (const piece &p, const game &g) noexcept
 Can this piece castle queenside?
 
bool can_do_attack (const game &g, const piece &selected_piece, const square &cursor_square, const chess_color player_color)
 Can a piece_action_type::attack action be done? This is not an en-passant.
 
bool can_do_castle_kingside (const game &g, const piece &selected_piece, const chess_color player_color)
 Can a piece_action_type::castle_kingside action be done?
 
bool can_do_castle_queenside (const game &g, const piece &selected_piece, const chess_color player_color)
 Can a piece_action_type::castle_queenside action be done?
 
bool can_do_en_passant (const game &g, const piece &selected_piece, const square &cursor_square, const chess_color player_color)
 Can a piece_action_type::en_passant action be done? This is not a regular attack.
 
bool can_do_move (const game &g, const piece &selected_piece, const square &cursor_square, const chess_color player_color)
 Can a piece_action_type::move action be done?
 
bool can_do_promote (const piece &selected_piece, const chess_color player_color)
 Can a piece_action_type::promote_to_bishop action be done?
 
void clear_piece_messages (game &g) noexcept
 Clear the sound effects to be processed, i.e.
 
action_history collect_action_history (const game &g)
 Collect the history of a game, i.e.
 
std::vector< piece_actioncollect_all_piece_actions (const game &g)
 Collect all valid moves and attackes at a board for all pieces.
 
std::vector< piece_actioncollect_all_piece_actions (const game &g, const chess_color player_color)
 Collect all valid moves and attackes at a board for all pieces of a certain color.
 
std::vector< piece_actioncollect_all_piece_actions (const game &g, const piece &p)
 Collect all valid moves and attackes at a board for a focal piece.
 
std::vector< piece_actioncollect_all_bishop_actions (const game &g, const piece &p)
 Collect all valid moves and attacks at a board for a focal bishop.
 
std::vector< piece_actioncollect_all_king_actions (const game &g, const piece &p)
 Collect all valid moves and attacks at a board for a focal king.
 
std::vector< piece_actioncollect_all_knight_actions (const game &g, const piece &p)
 Collect all valid moves and attacks at a board for a focal knight.
 
std::vector< piece_actioncollect_all_pawn_actions (const game &g, const piece &p)
 Collect all valid moves and attacks at a board for a focal pawn.
 
std::vector< piece_actioncollect_all_pawn_attack_actions (const game &g, const piece &p)
 Collect all valid attack actions at a board for a focal pawn.
 
std::vector< piece_actioncollect_all_pawn_en_passant_actions (const game &g, const piece &p)
 Collect all valid attack actions at a board for a focal pawn.
 
std::vector< piece_actioncollect_all_pawn_move_actions (const game &g, const piece &p)
 Collect all valid move actions at a board for a focal pawn.
 
std::vector< piece_actioncollect_all_queen_actions (const game &g, const piece &p)
 Collect all valid moves and attacks at a board for a focal queen.
 
std::vector< piece_actioncollect_all_rook_actions (const game &g, const piece &p)
 Collect all valid moves and attacks at a board for a focal rook.
 
std::vector< messagecollect_messages (const game &g) noexcept
 Get all the sound effects to be processed.
 
std::vector< message_typecollect_message_types (const game &g) noexcept
 See if there are messages.
 
int count_piece_actions (const game &g)
 Count the total number of actions to be done by pieces of both players.
 
int count_piece_actions (const game &g, const chess_color player)
 Count the total number of actions to be done by pieces of a player.
 
game create_game_from_fen_string (const fen_string &s) noexcept
 Create a game from a FEN string.
 
game create_game_with_standard_starting_position () noexcept
 Create a game with all default settings and the default starting position.
 
game create_game_with_starting_position (starting_position_type t, const race lhs_race=race::classic, const race rhs_race=race::classic) noexcept
 Create a game with all default settings and a specific starting position.
 
std::vector< piecefind_pieces (const game &g, const piece_type type, const chess_color color)
 Find zero, one or more chess pieces of the specified type and color.
 
const pieceget_closest_piece_to (const game &g, const game_coordinate &coordinat)
 Get the piece that is closest to the coordinat.
 
pieceget_closest_piece_to (game &g, const game_coordinate &coordinat)
 Get the piece that is closest to the coordinat.
 
int get_index_of_closest_piece_to (const game &g, const game_coordinate &coordinat)
 Get the index of the piece that is closest to the coordinat.
 
std::vector< squareget_unique_occupied_squares (const game &g) noexcept
 Get all the squares that are occupied, disallowing duplicates.
 
std::vector< squareget_occupied_squares (const game &g) noexcept
 Get all the squares that are occupied, allowing duplicates.
 
const pieceget_piece_at (const game &g, const square &coordinat)
 Get the piece that at that square, will throw if there is no piece.
 
const pieceget_piece_at (const game &g, const std::string &square_str)
 Get the piece that at that square, will throw if there is no piece.
 
pieceget_piece_at (game &g, const square &coordinat)
 Get the piece that at that square, will throw if there is no piece.
 
pieceget_piece_at (game &g, const std::string &square_str)
 Get the piece that at that square, will throw if there is no piece.
 
const pieceget_piece_with_id (const game &g, const piece_id &id)
 Get the piece with a certain ID.
 
pieceget_piece_with_id (game &g, const piece_id &id)
 Get the piece with a certain ID.
 
std::vector< piece > & get_pieces (game &g) noexcept
 Get all the pieces.
 
const std::vector< piece > & get_pieces (const game &g) noexcept
 Get all the pieces.
 
const in_game_timeget_time (const game &g) noexcept
 Get the time in the game.
 
bool has_piece_with_id (const game &g, const piece_id &id)
 Determine if there is a piece at the coordinat.
 
bool is_draw (const game &g)
 Determine if the game is a draw.
 
bool is_empty (const game &g, const square &s) noexcept
 Is the square empty?
 
bool is_empty_between (const game &g, const square &from, const square &to)
 Are all squares between these two squares empty? Returns true if the squares are adjacent.
 
bool is_empty_between (const game &g, const std::string &from_square_str, const std::string &to_square_str)
 Are all squares between these two squares empty? Returns true if the squares are adjacent.
 
bool is_idle (const game &g) noexcept
 Are all pieces idle?
 
bool is_piece_at (const game &g, const game_coordinate &coordinat, const double distance=0.5)
 Determine if there is a piece at the coordinat.
 
bool is_piece_at (const game &g, const square &coordinat)
 Determine if there is a piece at the coordinat.
 
bool is_piece_at (const game &g, const std::string &square_str)
 Determine if there is a piece at the coordinat.
 
bool is_square_attacked (const game &g, const square &s, const chess_color attacker_color)
 Determine if the square is attacked by (another) piece of a certain color.
 
void tick (game &g, const delta_t dt)
 Call game::tick safely.
 
void tick_until_idle (game &g)
 Call game::tick until all pieces are idle.
 
std::string to_board_str (const game &g, const board_to_text_options &options=board_to_text_options()) noexcept
 
fen_string to_fen_string (const game &g)
 Convert the game's position to a FEN string.
 
std::string to_pgn (const game &g)
 Convert the played game to pseudo-PGN notation.
 
std::ostream & operator<< (std::ostream &os, const game &g) noexcept
 

Function Documentation

◆ can_castle_kingside()

bool can_castle_kingside ( const piece p,
const game g 
)
noexcept

Can this piece castle kingside?

◆ can_castle_queenside()

bool can_castle_queenside ( const piece p,
const game g 
)
noexcept

Can this piece castle queenside?

◆ can_do_attack()

bool can_do_attack ( const game g,
const piece selected_piece,
const square cursor_square,
const chess_color  player_color 
)

Can a piece_action_type::attack action be done? This is not an en-passant.

See also
use can_do_en_passant} for an piece_action_type::en_passant

◆ can_do_castle_kingside()

bool can_do_castle_kingside ( const game g,
const piece selected_piece,
const chess_color  player_color 
)

Can a piece_action_type::castle_kingside action be done?

◆ can_do_castle_queenside()

bool can_do_castle_queenside ( const game g,
const piece selected_piece,
const chess_color  player_color 
)

Can a piece_action_type::castle_queenside action be done?

◆ can_do_en_passant()

bool can_do_en_passant ( const game g,
const piece selected_piece,
const square cursor_square,
const chess_color  player_color 
)

Can a piece_action_type::en_passant action be done? This is not a regular attack.

See also
use can_do_attack} for an piece_action_type::attack

◆ can_do_move()

bool can_do_move ( const game g,
const piece selected_piece,
const square cursor_square,
const chess_color  player_color 
)

Can a piece_action_type::move action be done?

◆ can_do_promote()

bool can_do_promote ( const piece selected_piece,
const chess_color  player_color 
)

Can a piece_action_type::promote_to_bishop action be done?

◆ clear_piece_messages()

void clear_piece_messages ( game g)
noexcept

Clear the sound effects to be processed, i.e.

resize to zero

◆ collect_action_history()

action_history collect_action_history ( const game g)

Collect the history of a game, i.e.

the moves played in time

◆ collect_all_bishop_actions()

std::vector< piece_action > collect_all_bishop_actions ( const game g,
const piece p 
)

Collect all valid moves and attacks at a board for a focal bishop.

◆ collect_all_king_actions()

std::vector< piece_action > collect_all_king_actions ( const game g,
const piece p 
)

Collect all valid moves and attacks at a board for a focal king.

◆ collect_all_knight_actions()

std::vector< piece_action > collect_all_knight_actions ( const game g,
const piece p 
)

Collect all valid moves and attacks at a board for a focal knight.

◆ collect_all_pawn_actions()

std::vector< piece_action > collect_all_pawn_actions ( const game g,
const piece p 
)

Collect all valid moves and attacks at a board for a focal pawn.

◆ collect_all_pawn_attack_actions()

std::vector< piece_action > collect_all_pawn_attack_actions ( const game g,
const piece p 
)

Collect all valid attack actions at a board for a focal pawn.

◆ collect_all_pawn_en_passant_actions()

std::vector< piece_action > collect_all_pawn_en_passant_actions ( const game g,
const piece p 
)

Collect all valid attack actions at a board for a focal pawn.

◆ collect_all_pawn_move_actions()

std::vector< piece_action > collect_all_pawn_move_actions ( const game g,
const piece p 
)

Collect all valid move actions at a board for a focal pawn.

◆ collect_all_piece_actions() [1/3]

std::vector< piece_action > collect_all_piece_actions ( const game g)

Collect all valid moves and attackes at a board for all pieces.

See also
use 'collect_all_user_inputs' to get all the 'user_input's from a game

◆ collect_all_piece_actions() [2/3]

std::vector< piece_action > collect_all_piece_actions ( const game g,
const chess_color  player_color 
)

Collect all valid moves and attackes at a board for all pieces of a certain color.

◆ collect_all_piece_actions() [3/3]

std::vector< piece_action > collect_all_piece_actions ( const game g,
const piece p 
)

Collect all valid moves and attackes at a board for a focal piece.

◆ collect_all_queen_actions()

std::vector< piece_action > collect_all_queen_actions ( const game g,
const piece p 
)

Collect all valid moves and attacks at a board for a focal queen.

◆ collect_all_rook_actions()

std::vector< piece_action > collect_all_rook_actions ( const game g,
const piece p 
)

Collect all valid moves and attacks at a board for a focal rook.

◆ collect_message_types()

std::vector< message_type > collect_message_types ( const game g)
noexcept

See if there are messages.

@seealso collect_messages} to get the complete message

◆ collect_messages()

std::vector< message > collect_messages ( const game g)
noexcept

Get all the sound effects to be processed.

◆ count_piece_actions() [1/2]

int count_piece_actions ( const game g)

Count the total number of actions to be done by pieces of both players.

◆ count_piece_actions() [2/2]

int count_piece_actions ( const game g,
const chess_color  player 
)

Count the total number of actions to be done by pieces of a player.

◆ create_game_from_fen_string()

game create_game_from_fen_string ( const fen_string s)
noexcept

Create a game from a FEN string.

◆ create_game_with_standard_starting_position()

game create_game_with_standard_starting_position ( )
noexcept

Create a game with all default settings and the default starting position.

◆ create_game_with_starting_position()

game create_game_with_starting_position ( starting_position_type  t,
const race  lhs_race = race::classic,
const race  rhs_race = race::classic 
)
noexcept

Create a game with all default settings and a specific starting position.

◆ find_pieces()

std::vector< piece > find_pieces ( const game g,
const piece_type  type,
const chess_color  color 
)

Find zero, one or more chess pieces of the specified type and color.

◆ get_closest_piece_to() [1/2]

const piece & get_closest_piece_to ( const game g,
const game_coordinate coordinat 
)

Get the piece that is closest to the coordinat.

◆ get_closest_piece_to() [2/2]

piece & get_closest_piece_to ( game g,
const game_coordinate coordinat 
)

Get the piece that is closest to the coordinat.

◆ get_index_of_closest_piece_to()

int get_index_of_closest_piece_to ( const game g,
const game_coordinate coordinat 
)

Get the index of the piece that is closest to the coordinat.

◆ get_occupied_squares()

std::vector< square > get_occupied_squares ( const game g)
noexcept

Get all the squares that are occupied, allowing duplicates.

At the start and end of a tick, all occupied squares must be unique. However, when updating each piece at a time, it can be that some squares are duplicate untill all pieces are processed.

All squares are not tested to be unique, use get_unique_occupied_squares} to guarantee that all squares are unique.

◆ get_piece_at() [1/4]

const piece & get_piece_at ( const game g,
const square coordinat 
)

Get the piece that at that square, will throw if there is no piece.

◆ get_piece_at() [2/4]

const piece & get_piece_at ( const game g,
const std::string &  square_str 
)

Get the piece that at that square, will throw if there is no piece.

◆ get_piece_at() [3/4]

piece & get_piece_at ( game g,
const square coordinat 
)

Get the piece that at that square, will throw if there is no piece.

◆ get_piece_at() [4/4]

piece & get_piece_at ( game g,
const std::string &  square_str 
)

Get the piece that at that square, will throw if there is no piece.

◆ get_piece_with_id() [1/2]

const piece & get_piece_with_id ( const game g,
const piece_id id 
)

Get the piece with a certain ID.

Assumes that the piece is on the board

◆ get_piece_with_id() [2/2]

piece & get_piece_with_id ( game g,
const piece_id id 
)

Get the piece with a certain ID.

Assumes that the piece is on the board

◆ get_pieces() [1/2]

const std::vector< piece > & get_pieces ( const game g)
noexcept

Get all the pieces.

◆ get_pieces() [2/2]

std::vector< piece > & get_pieces ( game g)
noexcept

Get all the pieces.

◆ get_time()

const in_game_time & get_time ( const game g)
noexcept

Get the time in the game.

◆ get_unique_occupied_squares()

std::vector< square > get_unique_occupied_squares ( const game g)
noexcept

Get all the squares that are occupied, disallowing duplicates.

At the start and end of a tick, all occupied squares must be unique. However, when updating each piece at a time, it can be that some squares are duplicate untill all pieces are processed.

All squares are tested to be unique, use get_occupied_squares} to allow duplicate squares.

◆ has_piece_with_id()

bool has_piece_with_id ( const game g,
const piece_id id 
)

Determine if there is a piece at the coordinat.

◆ is_draw()

bool is_draw ( const game g)

Determine if the game is a draw.

◆ is_empty()

bool is_empty ( const game g,
const square s 
)
noexcept

Is the square empty?

◆ is_empty_between() [1/2]

bool is_empty_between ( const game g,
const square from,
const square to 
)

Are all squares between these two squares empty? Returns true if the squares are adjacent.

◆ is_empty_between() [2/2]

bool is_empty_between ( const game g,
const std::string &  from_square_str,
const std::string &  to_square_str 
)

Are all squares between these two squares empty? Returns true if the squares are adjacent.

◆ is_idle()

bool is_idle ( const game g)
noexcept

Are all pieces idle?

◆ is_piece_at() [1/3]

bool is_piece_at ( const game g,
const game_coordinate coordinat,
const double  distance = 0.5 
)

Determine if there is a piece at the coordinat.

◆ is_piece_at() [2/3]

bool is_piece_at ( const game g,
const square coordinat 
)

Determine if there is a piece at the coordinat.

◆ is_piece_at() [3/3]

bool is_piece_at ( const game g,
const std::string &  square_str 
)

Determine if there is a piece at the coordinat.

◆ is_square_attacked()

bool is_square_attacked ( const game g,
const square s,
const chess_color  attacker_color 
)

Determine if the square is attacked by (another) piece of a certain color.

If the square is empty, it will determine if an enemy piece is looking at this square.

If the square is occupied, it will determine if an enemy piece is looking at that piece. That piece can be of any color.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const game g 
)
noexcept

◆ tick()

void tick ( game g,
const delta_t  dt 
)

Call game::tick safely.

That is, with a maximum delta t of 0.25

◆ tick_until_idle()

void tick_until_idle ( game g)

Call game::tick until all pieces are idle.

◆ to_board_str()

std::string to_board_str ( const game g,
const board_to_text_options options = board_to_text_options() 
)
noexcept

◆ to_fen_string()

fen_string to_fen_string ( const game g)

Convert the game's position to a FEN string.

◆ to_pgn()

std::string to_pgn ( const game g)

Convert the played game to pseudo-PGN notation.

Returns one string with newlines. An example string can be: '0: white pawn move from e2 to e4', where the '0' denotes the starting time of the move