Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
game_board.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
7#include <functional>
10#include <vector>
11
12using namespace std;
13using namespace gameboard;
14
16namespace gameboard {
17
19extern const int kRepeatPeriodsToCheck[3];
20extern const int kRepeatPeriodsMaxAllowed;
21extern const int kMaxMovesWithoutCapture;
22
25class GameBoard : public SpaceInfoProvider<GameBoard> {
26public:
27 GameBoard();
28 GameBoard(const BoardMapInt_t starting_board);
29 vector<BoardSpace> ImplementGetAllSpacesOccupiedBy(PieceColor color) const;
30 PieceColor ImplementGetColor(const BoardSpace &space) const;
31 PieceType ImplementGetType(const BoardSpace &space) const;
33 bool IsInCheck(PieceColor color);
35 bool IsCaptureMove(const ExecutedMove &executed_move) const;
36 void ImplementUndoMove(const ExecutedMove &executed_move);
37 GamePiece GetOccupantAt(const BoardSpace &space) const;
38 const BoardMap_t &map() const;
39 void ImplementAttachMoveCallback(const function<void(const ExecutedMove&)>& callback);
40 bool ImplementIsDraw();
41 const std::map<PieceColor, vector<ExecutedMove>>& move_log() const;
42
43private:
46
49
52 vector<function<void(const ExecutedMove&)>> move_callbacks_;
53
55 std::map<PieceColor, vector<ExecutedMove>> move_log_;
56
59
60 void UpdateStateTracker(const ExecutedMove &executed_move);
61 void SetOccupantAt(const BoardSpace &space, GamePiece piece);
62 void AddToMoveLog(const ExecutedMove &executed_move);
63 void RemoveFromMoveLog(const ExecutedMove &executed_move);
65};
66
67} // namespace gameboard
Constants, typedefs, and simple structs used by gameboard::GameBoard.
CRTP interface with methods for obtaining information about gameboard::BoardSpace objects,...
Implements SpaceInfoProvider interface; stores piece positions, and exposes methods for calculating,...
Definition: game_board.hpp:25
bool ViolatesRepeatRule(PieceColor color)
Definition: gameboard.cpp:171
vector< BoardSpace > ImplementGetAllSpacesOccupiedBy(PieceColor color) const
Definition: gameboard.cpp:52
MoveCalculator move_calculator_
Encapsulates all calculations of allowed moves.
Definition: game_board.hpp:48
void AddToMoveLog(const ExecutedMove &executed_move)
Definition: gameboard.cpp:157
void ImplementAttachMoveCallback(const function< void(const ExecutedMove &)> &callback)
Definition: gameboard.cpp:134
MoveCollection ImplementCalcFinalMovesOf(PieceColor color)
Definition: gameboard.cpp:64
void UpdateStateTracker(const ExecutedMove &executed_move)
Definition: gameboard.cpp:147
std::map< PieceColor, vector< ExecutedMove > > move_log_
Vectors of all moves that have been executed (and not un-done) by each player.
Definition: game_board.hpp:55
const std::map< PieceColor, vector< ExecutedMove > > & move_log() const
Definition: gameboard.cpp:143
vector< function< void(const ExecutedMove &)> > move_callbacks_
Stores functions that are called after any change in board config to keep boardstate::SingleZobristCo...
Definition: game_board.hpp:52
bool IsInCheck(PieceColor color)
Definition: gameboard.cpp:90
PieceType ImplementGetType(const BoardSpace &space) const
Definition: gameboard.cpp:60
void RemoveFromMoveLog(const ExecutedMove &executed_move)
Definition: gameboard.cpp:162
ExecutedMove ImplementExecuteMove(const Move &move)
Definition: gameboard.cpp:97
MoveCountType moves_since_last_capture_
Number of moves executed since last time a piece was captured.
Definition: game_board.hpp:58
bool IsCaptureMove(const ExecutedMove &executed_move) const
Definition: gameboard.cpp:116
GamePiece GetOccupantAt(const BoardSpace &space) const
Definition: gameboard.cpp:128
BoardMap_t board_map_
2-D array of GamePiece objects.
Definition: game_board.hpp:45
PieceColor ImplementGetColor(const BoardSpace &space) const
Definition: gameboard.cpp:56
void SetOccupantAt(const BoardSpace &space, GamePiece piece)
Definition: gameboard.cpp:153
const BoardMap_t & map() const
Definition: gameboard.cpp:132
void ImplementUndoMove(const ExecutedMove &executed_move)
Definition: gameboard.cpp:120
Calculates legal gameboard::Move objects for of a gameboard::GameBoard with a particular state.
uint16_t MoveCountType
Definition of gameboard::MoveCalculator.
Definitions of concrete classes that implement the MoveEvaluator interface.
Tracking piece positions and determining legal moves.
const BoardMapInt_t kStandardInitialBoard
Starting board represented as 2-D array of integers.
array< array< int, kNumFiles >, kNumRanks > BoardMapInt_t
2-D array of integers; can be converted to gameboard::BoardMap_t using gameboard::int_board_to_game_p...
array< array< GamePiece, kNumFiles >, kNumRanks > BoardMap_t
2-D array of gameboard::GamePiece objects.
const int kRepeatPeriodsToCheck[3]
Max allowed repetitions of prohibited move sequence lengths.
const int kMaxMovesWithoutCapture
const int kRepeatPeriodsMaxAllowed
Repeated move sequence lengths forbidden under move repetition rules.
A pair of coordinate (rank, and file) with properties determined by comparison with values of gameboa...
A change in the state of a gameboard::GameBoard represented by a gameboard::Move, and each of the gam...
A Xiangqi game piece described by its gameboard::PieceType and its gameboard::PieceColor.
Definition: game_piece.hpp:42
A container for multiple gameboard::Move objects.
A gameboard::BoardSpace pair (start and end).