Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
Classes | Functions
game_controller.h File Reference
#include "ccfwd.h"
#include "piece_action_type.h"
#include "game_coordinate.h"
#include "game.h"
#include "lobby_options.h"
#include "side.h"
#include "user_inputs.h"
#include <map>
#include <iosfwd>
Include dependency graph for game_controller.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  game_controller
 The class that acts as a controller for game}. More...
 

Functions

void add_user_input (game_controller &c, const user_input &input)
 Add a user input. These will be processed in 'game::tick'.
 
void add_user_inputs (game_controller &c, const user_inputs &input)
 Add a user_inputs. These will be processed in 'game::tick'.
 
bool can_attack (const game_controller &c, const side player_side) noexcept
 Can the player attack?
 
bool can_attack_en_passant (const game_controller &c, const side player_side) noexcept
 Can the player do an en-passant attack?
 
bool can_castle_kingside (const game_controller &c, const side player_side) noexcept
 Can the player castle kingside?
 
bool can_castle_queenside (const game_controller &c, const side player_side) noexcept
 Can the player castle queenside?
 
bool can_move (const game_controller &c, const side player_side) noexcept
 
bool can_player_select_piece_at_cursor_pos (const game_controller &c, const chess_color cursor_color)
 Can the player select a piece at the current cursor position?
 
bool can_player_select_piece_at_cursor_pos (const game_controller &c, const side player_side)
 Can the player select a piece at the current cursor position?
 
bool can_promote (const game_controller &c, const side player_side) noexcept
 
bool can_select (const game_controller &c, const side player_side) noexcept
 
bool can_unselect (const game_controller &c, const side player_side) noexcept
 
std::vector< messagecollect_messages (const game_controller &g) noexcept
 Get all the sound effects to be processed.
 
std::vector< piece_idcollect_selected_piece_ids (const game_controller &c)
 Collect all the piece IDs of the selected pieces, if any.
 
user_inputs convert_move_to_user_inputs (const game_controller &c, const chess_move &move, const physical_controller_type t)
 Convert a chess move, e.g.
 
int count_piece_actions (const game_controller &g)
 Count the total number of actions to be done by pieces of both players.
 
int count_piece_actions (const game_controller &g, const chess_color player)
 Count the total number of actions to be done by pieces of a player.
 
int count_selected_units (const game_controller &c, const chess_color player_color)
 Count the number of selected units.
 
int count_user_inputs (const game_controller &c) noexcept
 Count the total number of user_input}s to be done by the game_controller}.
 
chess_color get_color (const game_controller &c, const side s)
 
const game_coordinateget_cursor_pos (const game_controller &c, const side player_side) noexcept
 Get the a player's cursor position.
 
const game_coordinateget_cursor_pos (const game_controller &c, const chess_color cursor_color)
 Get the cursor position for a chess color.
 
square get_cursor_square (const game_controller &c, const side player_side)
 Get the a player's cursor position, as a square}.
 
const in_game_timeget_in_game_time (const game_controller &c) noexcept
 
std::vector< piece_action_typeget_piece_actions (const game_controller &c, const side player_side) noexcept
 Get the types of actions, if any, a player could by pressing an action key.
 
pieceget_piece_at (game_controller &c, const std::string &square_str)
 
pieceget_piece_at (game_controller &c, const square &s)
 
std::vector< squareget_possible_moves (const game_controller &c, const side player)
 Get the possible moves for a player's selected pieces Will be empty if no pieces are selected.
 
std::vector< pieceget_selected_pieces (const game_controller &c, const chess_color player)
 Get all the selected pieces.
 
std::vector< pieceget_selected_pieces (const game_controller &c, const side player)
 Get all the selected pieces.
 
const user_inputsget_user_inputs (const game_controller &c) noexcept
 Get the game users' inputs.
 
user_inputs get_user_inputs_to_move_cursor_from_to (const game_controller &c, const square &from, const square &to, const side player_side, const physical_controller_type t)
 Create the user inputs to move the cursor to a target square knowing it will be at the 'from' square.
 
user_inputs get_user_inputs_to_move_cursor_to (const game_controller &c, const square &to, const side player_side, const physical_controller_type t)
 Create the user inputs to move the cursor to a target square.
 
const std::optional< chess_color > & get_winner (const game_controller &c) noexcept
 
bool has_selected_pieces (const game_controller &c, const chess_color player_color)
 See if there is at least 1 piece selected.
 
bool has_selected_pieces (const game_controller &c, const side player_side)
 See if there is at least 1 piece selected.
 
bool has_winner (const game_controller &c) noexcept
 Does the game have a winner?
 
bool is_cursor_on_selected_piece (const game_controller &c, const side player_side) noexcept
 
bool is_draw (const game_controller &c)
 Determine if the game is a draw.
 
bool is_piece_at (const game_controller &g, const square &coordinat)
 Determine if there is a piece at the coordinat.
 
bool is_piece_at (const game_controller &g, const std::string &square_str)
 Determine if there is a piece at the coordinat.
 
bool is_selected (const piece &p, const game_controller &c)
 Determine if the piece is selected, based on its action history.
 
bool is_square_attacked (const game_controller &c, const square &s, const chess_color attacker_color)
 Determine if the square is attacked by (another) piece of a certain color.
 
void move_cursor_to (game_controller &c, const std::string &square_str, const side player_side)
 Put the cursor (i.e.
 
void move_cursor_to (game_controller &c, const square &s, const side player_side)
 Put the cursor (i.e.
 
game play_random_game (const int n_turns=2, const int seed=42)
 Play a random game, used for profiling.
 
void set_cursor_pos (game_controller &c, const game_coordinate &pos, const side player_side) noexcept
 Set the cursor's position to the target position.
 
void test_game_controller ()
 Test this class and its free functions.
 
std::string to_board_str (const game_controller &c, const board_to_text_options &options=board_to_text_options()) noexcept
 
std::ostream & operator<< (std::ostream &os, const game_controller &g) noexcept
 

Function Documentation

◆ add_user_input()

void add_user_input ( game_controller c,
const user_input input 
)

Add a user input. These will be processed in 'game::tick'.

◆ add_user_inputs()

void add_user_inputs ( game_controller c,
const user_inputs input 
)

Add a user_inputs. These will be processed in 'game::tick'.

◆ can_attack()

bool can_attack ( const game_controller c,
const side  player_side 
)
noexcept

Can the player attack?

◆ can_attack_en_passant()

bool can_attack_en_passant ( const game_controller c,
const side  player_side 
)
noexcept

Can the player do an en-passant attack?

◆ can_castle_kingside()

bool can_castle_kingside ( const game_controller c,
const side  player_side 
)
noexcept

Can the player castle kingside?

◆ can_castle_queenside()

bool can_castle_queenside ( const game_controller c,
const side  player_side 
)
noexcept

Can the player castle queenside?

◆ can_move()

bool can_move ( const game_controller c,
const side  player_side 
)
noexcept

◆ can_player_select_piece_at_cursor_pos() [1/2]

bool can_player_select_piece_at_cursor_pos ( const game_controller c,
const chess_color  cursor_color 
)

Can the player select a piece at the current cursor position?

◆ can_player_select_piece_at_cursor_pos() [2/2]

bool can_player_select_piece_at_cursor_pos ( const game_controller c,
const side  player_side 
)

Can the player select a piece at the current cursor position?

◆ can_promote()

bool can_promote ( const game_controller c,
const side  player_side 
)
noexcept

◆ can_select()

bool can_select ( const game_controller c,
const side  player_side 
)
noexcept

◆ can_unselect()

bool can_unselect ( const game_controller c,
const side  player_side 
)
noexcept

◆ collect_messages()

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

Get all the sound effects to be processed.

◆ collect_selected_piece_ids()

std::vector< piece_id > collect_selected_piece_ids ( const game_controller c)

Collect all the piece IDs of the selected pieces, if any.

◆ convert_move_to_user_inputs()

user_inputs convert_move_to_user_inputs ( const game_controller c,
const chess_move move,
const physical_controller_type  t 
)

Convert a chess move, e.g.

e4, to the right user inputs

◆ count_piece_actions() [1/2]

int count_piece_actions ( const game_controller 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_controller g,
const chess_color  player 
)

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

◆ count_selected_units()

int count_selected_units ( const game_controller c,
const chess_color  player_color 
)

Count the number of selected units.

As one can only select one unit, this is either zero or one.

◆ count_user_inputs()

int count_user_inputs ( const game_controller c)
noexcept

Count the total number of user_input}s to be done by the game_controller}.

◆ get_color()

chess_color get_color ( const game_controller c,
const side  s 
)

◆ get_cursor_pos() [1/2]

const game_coordinate & get_cursor_pos ( const game_controller c,
const chess_color  cursor_color 
)

Get the cursor position for a chess color.

◆ get_cursor_pos() [2/2]

const game_coordinate & get_cursor_pos ( const game_controller c,
const side  player_side 
)
noexcept

Get the a player's cursor position.

◆ get_cursor_square()

square get_cursor_square ( const game_controller c,
const side  player_side 
)

Get the a player's cursor position, as a square}.

◆ get_in_game_time()

const in_game_time & get_in_game_time ( const game_controller c)
noexcept

◆ get_piece_actions()

std::vector< piece_action_type > get_piece_actions ( const game_controller c,
const side  player_side 
)
noexcept

Get the types of actions, if any, a player could by pressing an action key.

For example, action 1 typically un-/selects pieces, where action 4 is only used to promote to a knight.

◆ get_piece_at() [1/2]

piece & get_piece_at ( game_controller c,
const square s 
)

◆ get_piece_at() [2/2]

piece & get_piece_at ( game_controller c,
const std::string &  square_str 
)

◆ get_possible_moves()

std::vector< square > get_possible_moves ( const game_controller c,
const side  player 
)

Get the possible moves for a player's selected pieces Will be empty if no pieces are selected.

◆ get_selected_pieces() [1/2]

std::vector< piece > get_selected_pieces ( const game_controller c,
const chess_color  player 
)

Get all the selected pieces.

Parameters
ga game
playerthe color of the player, which is white for player 1
See also
use 'has_selected_piece' to see if there is at least 1 piece selected

◆ get_selected_pieces() [2/2]

std::vector< piece > get_selected_pieces ( const game_controller c,
const side  player 
)

Get all the selected pieces.

Parameters
ga game
sidethe side of the player, which is white for player 1
See also
use 'has_selected_piece' to see if there is at least 1 piece selected

◆ get_user_inputs()

const user_inputs & get_user_inputs ( const game_controller c)
noexcept

Get the game users' inputs.

◆ get_user_inputs_to_move_cursor_from_to()

user_inputs get_user_inputs_to_move_cursor_from_to ( const game_controller c,
const square from,
const square to,
const side  player_side,
const physical_controller_type  t 
)

Create the user inputs to move the cursor to a target square knowing it will be at the 'from' square.

This is useful for creating future 'user_input's, e.g. for white doing e4, the cursor must be moved to e2 to select a pawn, then to e4 to select the target.

◆ get_user_inputs_to_move_cursor_to()

user_inputs get_user_inputs_to_move_cursor_to ( const game_controller c,
const square to,
const side  player_side,
const physical_controller_type  t 
)

Create the user inputs to move the cursor to a target square.

◆ get_winner()

const std::optional< chess_color > & get_winner ( const game_controller c)
noexcept

◆ has_selected_pieces() [1/2]

bool has_selected_pieces ( const game_controller c,
const chess_color  player_color 
)

See if there is at least 1 piece selected.

Parameters
ga game
playerthe color of the player, which is white for player 1
See also
use 'get_selected_pieces' to get all the selected pieces

◆ has_selected_pieces() [2/2]

bool has_selected_pieces ( const game_controller c,
const side  player_side 
)

See if there is at least 1 piece selected.

◆ has_winner()

bool has_winner ( const game_controller c)
noexcept

Does the game have a winner?

◆ is_cursor_on_selected_piece()

bool is_cursor_on_selected_piece ( const game_controller c,
const side  player_side 
)
noexcept

◆ is_draw()

bool is_draw ( const game_controller c)

Determine if the game is a draw.

◆ is_piece_at() [1/2]

bool is_piece_at ( const game_controller g,
const square coordinat 
)

Determine if there is a piece at the coordinat.

◆ is_piece_at() [2/2]

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

Determine if there is a piece at the coordinat.

◆ is_selected()

bool is_selected ( const piece p,
const game_controller c 
)

Determine if the piece is selected, based on its action history.

◆ is_square_attacked()

bool is_square_attacked ( const game_controller c,
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.

◆ move_cursor_to() [1/2]

void move_cursor_to ( game_controller c,
const square s,
const side  player_side 
)

Put the cursor (i.e.

the selector, not the mouse pointer) at the desired square. Does not select the square where the cursor is.

◆ move_cursor_to() [2/2]

void move_cursor_to ( game_controller c,
const std::string &  square_str,
const side  player_side 
)

Put the cursor (i.e.

the selector, not the mouse pointer) at the desired square

◆ operator<<()

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

◆ play_random_game()

game play_random_game ( const int  n_turns = 2,
const int  seed = 42 
)

Play a random game, used for profiling.

◆ set_cursor_pos()

void set_cursor_pos ( game_controller c,
const game_coordinate pos,
const side  player_side 
)
noexcept

Set the cursor's position to the target position.

◆ test_game_controller()

void test_game_controller ( )

Test this class and its free functions.

Test this class and its free functions.

◆ to_board_str()

std::string to_board_str ( const game_controller c,
const board_to_text_options options = board_to_text_options() 
)
noexcept