1#ifndef GAME_CONTROLLER_H
2#define GAME_CONTROLLER_H
77 std::map<side, game_coordinate> m_cursor_pos;
86 std::map<side, std::optional<piece_id>> m_selected_piece_id;
95 void apply_action_type_attack_to_game(
game& g,
const side s);
96 void apply_action_type_attack_en_passant_to_game(
game& g,
const side s);
97 void apply_action_type_castle_kingside_to_game(
game& g,
const side s);
98 void apply_action_type_castle_queenside_to_game(
game& g,
const side s);
99 void apply_action_type_move_to_game(
game& g,
const side s);
100 void apply_action_type_promote_to_game(
game& g,
const piece_type promote_to_type,
const side s);
101 void apply_action_type_select_to_game(
game& g,
const side s);
102 void apply_action_type_unselect_to_game(
game& g,
const side s);
117 const side player_side
123 const side player_side
129 const side player_side
135 const side player_side
140 const side player_side
152 const side player_side
157 const side player_side
163 const side player_side
168 const side player_side
214 const side player_side
226 const side player_side
239 const side player_side
283 const side player_side,
291 const side player_side,
309 const side player_side
317 const side player_side
332 const std::string& square_str
360 const std::string& square_str,
361 const side player_side
370 const side player_side
380 const side player_side
391std::ostream& operator<<(std::ostream& os, const
game_controller& g) noexcept;
chess_color
A chess piece color.
Definition chess_color.h:10
Options on how to convert a chessboard to text.
Definition board_to_text_options.h:10
A chess move.
Definition chess_move.h:22
A change of in_game_time}.
Definition delta_t.h:12
The class that acts as a controller for game}.
Definition game_controller.h:31
void tick(const delta_t &dt=delta_t(1.0))
Make the game go forward.
Definition game_controller.cpp:2618
const auto & get_lobby_options() const noexcept
Get the game.
Definition game_controller.h:54
const game_coordinate & get_cursor_pos(const side player_side) const noexcept
Get the a player's cursor position.
Definition game_controller.cpp:747
void add_user_input(const user_input &a)
Add a user input. These will be processed in 'game::tick'.
Definition game_controller.cpp:30
const physical_controller & get_physical_controller(const side player_side) const noexcept
Get a player's physical controller.
game & get_game() noexcept
Get the game.
Definition game_controller.h:51
void set_selected_piece_id(const side s, const std::optional< piece_id > &selected_piece_id) noexcept
Set the selected square, if any.
Definition game_controller.cpp:1101
const game & get_game() const noexcept
Get the game.
Definition game_controller.h:48
const std::optional< piece_id > & get_selected_piece_id(const side s) const noexcept
Get the selected squares, if any.
Definition game_controller.cpp:884
void set_cursor_pos(const game_coordinate &pos, const side player_side) noexcept
Set a player's cursor's position.
Definition game_controller.cpp:1094
const auto & get_user_inputs() const noexcept
Get the game users' inputs.
Definition game_controller.h:60
void apply_user_inputs_to_game()
Process all actions and apply these on the game.
Definition game_controller.cpp:48
An exact coordinate anywhere on the board.
Definition game_coordinate.h:32
The Game dialog.
Definition game_view.h:27
The game logic.
Definition game.h:28
The in-game time, in chess moves.
Definition in_game_time.h:16
The options that are set in the lobby.
Definition lobby_options.h:16
A physical controller.
Definition physical_controller.h:19
A chess piece.
Definition piece.h:24
A chess square.
Definition square.h:58
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?
Definition game_controller.cpp:612
bool has_selected_pieces(const game_controller &c, const chess_color player_color)
See if there is at least 1 piece selected.
Definition game_controller.cpp:966
void add_user_inputs(game_controller &c, const user_inputs &input)
Add a user_inputs. These will be processed in 'game::tick'.
Definition game_controller.cpp:40
int count_piece_actions(const game_controller &g)
Count the total number of actions to be done by pieces of both players.
bool is_selected(const piece &p, const game_controller &c)
Determine if the piece is selected, based on its action history.
Definition game_controller.cpp:1029
bool is_cursor_on_selected_piece(const game_controller &c, const side player_side) noexcept
Definition game_controller.cpp:987
int count_user_inputs(const game_controller &c) noexcept
Count the total number of user_input}s to be done by the game_controller}.
Definition game_controller.cpp:742
bool can_attack_en_passant(const game_controller &c, const side player_side) noexcept
Can the player do an en-passant attack?
Definition game_controller.cpp:521
bool can_move(const game_controller &c, const side player_side) noexcept
Definition game_controller.cpp:594
std::vector< message > collect_messages(const game_controller &g) noexcept
Get all the sound effects to be processed.
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.
Definition game_controller.cpp:785
square get_cursor_square(const game_controller &c, const side player_side)
Get the a player's cursor position, as a square}.
Definition game_controller.cpp:768
const game_coordinate & get_cursor_pos(const game_controller &c, const side player_side) noexcept
Get the a player's cursor position.
Definition game_controller.cpp:752
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.
Definition game_controller.cpp:690
bool is_draw(const game_controller &c)
Determine if the game is a draw.
Definition game_controller.cpp:1001
game play_random_game(const int n_turns=2, const int seed=42)
Play a random game, used for profiling.
Definition game_controller.cpp:1066
const user_inputs & get_user_inputs(const game_controller &c) noexcept
Get the game users' inputs.
Definition game_controller.cpp:889
bool can_castle_queenside(const game_controller &c, const side player_side) noexcept
Can the player castle queenside?
Definition game_controller.cpp:574
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.
Definition game_controller.cpp:894
const in_game_time & get_in_game_time(const game_controller &c) noexcept
Definition game_controller.cpp:778
bool can_select(const game_controller &c, const side player_side) noexcept
Definition game_controller.cpp:661
int count_selected_units(const game_controller &c, const chess_color player_color)
Count the number of selected units.
Definition game_controller.cpp:737
const std::optional< chess_color > & get_winner(const game_controller &c) noexcept
Definition game_controller.cpp:961
void add_user_input(game_controller &c, const user_input &input)
Add a user input. These will be processed in 'game::tick'.
Definition game_controller.cpp:35
bool has_winner(const game_controller &c) noexcept
Does the game have a winner?
Definition game_controller.cpp:982
std::vector< piece_id > collect_selected_piece_ids(const game_controller &c)
Collect all the piece IDs of the selected pieces, if any.
Definition game_controller.cpp:677
bool can_attack(const game_controller &c, const side player_side) noexcept
Can the player attack?
Definition game_controller.cpp:494
void test_game_controller()
Test this class and its free functions.
Definition game_controller.cpp:1109
bool can_promote(const game_controller &c, const side player_side) noexcept
Definition game_controller.cpp:647
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.
Definition game_controller.cpp:850
bool can_unselect(const game_controller &c, const side player_side) noexcept
Definition game_controller.cpp:669
std::string to_board_str(const game_controller &c, const board_to_text_options &options=board_to_text_options()) noexcept
Definition game_controller.cpp:2623
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.
Definition game_controller.cpp:926
bool can_castle_kingside(const game_controller &c, const side player_side) noexcept
Can the player castle kingside?
Definition game_controller.cpp:548
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.
Definition game_controller.cpp:1085
void move_cursor_to(game_controller &c, const std::string &square_str, const side player_side)
Put the cursor (i.e.
Definition game_controller.cpp:1048
piece & get_piece_at(game_controller &c, const std::string &square_str)
Definition game_controller.cpp:839
std::vector< piece > get_selected_pieces(const game_controller &c, const chess_color player)
Get all the selected pieces.
Definition game_controller.cpp:863
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.
Definition game_controller.cpp:1039
bool is_piece_at(const game_controller &g, const square &coordinat)
Determine if there is a piece at the coordinat.
Definition game_controller.cpp:1006
chess_color get_color(const game_controller &c, const side s)
physical_controller_type
The type of controller.
Definition physical_controller_type.h:15
piece_action_type
The type of actions a piece can do.
Definition piece_action_type.h:9
piece_type
The type of chess piece.
Definition piece_type.h:9
side
The side the player/piece is on.
Definition side.h:11