Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
gameboard Namespace Reference

Tracking piece positions and determining legal moves. More...

Classes

struct  BoardDirection
 Descirbes a direction on a gameboard::GameBoard.board_map_. More...
 
struct  BoardSpace
 A pair of coordinate (rank, and file) with properties determined by comparison with values of gameboard features: board size, river locations, and castle locations. More...
 
struct  CastleEdges
 Defines a castle feature in terms of its min / max rank and file. More...
 
struct  ExecutedMove
 A change in the state of a gameboard::GameBoard represented by a gameboard::Move, and each of the gameboard::GamePiece objects located at the start and end locations of the Move. More...
 
class  GameBoard
 Implements SpaceInfoProvider interface; stores piece positions, and exposes methods for calculating, executing, an un-doing moves. More...
 
class  GameBoardFactory
 
class  GameBoardForConcepts
 Must comply with SpaceInfoProviderConcept; stores piece positions, and exposes methods for calculating, executing, an un-doing moves. More...
 
struct  GamePiece
 A Xiangqi game piece described by its gameboard::PieceType and its gameboard::PieceColor. More...
 
struct  Move
 A gameboard::BoardSpace pair (start and end). More...
 
class  MoveCalculator
 Calculates legal gameboard::Move objects for of a gameboard::GameBoard with a particular state. More...
 
struct  MoveCollection
 A container for multiple gameboard::Move objects. More...
 
class  PieceMoves
 Implements piece type dependent move rules; used by gameboard::MoveCalculator. More...
 

Typedefs

typedef array< array< GamePiece, kNumFiles >, kNumRanksBoardMap_t
 2-D array of gameboard::GamePiece objects.
 
typedef array< array< int, kNumFiles >, kNumRanksBoardMapInt_t
 2-D array of integers; can be converted to gameboard::BoardMap_t using gameboard::int_board_to_game_pieces.
 
typedef array< BoardSpace, 9 > Castle_t
 
typedef void(PieceMoves::* MethodPtr_t) (const BoardMap_t &, PieceColor, const BoardSpace &, MoveCollection &)
 
typedef array< MethodPtr_t, kNumPieceTypeValsPieceDispatchArray_t
 

Enumerations

enum  PieceType : int {
  kNnn = 0 , kGen = 1 , kAdv = 2 , kEle = 3 ,
  kHor = 4 , kCha = 5 , kCan = 6 , kSol = 7
}
 
enum  PieceColor : int { kRed = -1 , kNul = 0 , kBlk = 1 }
 

Functions

PieceColor opponent_of (PieceColor color)
 
constexpr Castle_t calc_castle_spaces (const CastleEdges &edges)
 
constexpr Castle_t red_castle_spaces ()
 
constexpr Castle_t black_castle_spaces ()
 
BoardMap_t int_board_to_game_pieces (const BoardMapInt_t int_board)
 
bool is_occupied (const BoardMap_t &board_map, const BoardSpace &space)
 
PieceColor get_color (const BoardMap_t &board_map, const BoardSpace &space)
 
PieceType get_type (const BoardMap_t &board_map, const BoardSpace &space)
 
BoardSpace get_general_position (const BoardMap_t &board_map, const PieceColor color)
 
vector< BoardSpaceget_all_spaces_occupied_by (const BoardMap_t &board_map, const PieceColor color)
 
size_t GetZColorIndexOf (PieceColor color)
 
PieceColor GetPieceColorOf (size_t zcolor_index)
 
constexpr PieceDispatchArray_t build_piece_dispatch_array ()
 

Variables

const BoardIndexType kNumRanks = 10
 
const BoardIndexType kNumFiles = 9
 
const BoardIndexType kRedRiverEdge = 5
 
const BoardIndexType kBlackRiverEdge = 4
 
constexpr CastleEdges kRedCastleEdges = {7, 9, 3, 5}
 
constexpr CastleEdges kBlackCastleEdges = {0, 2, 3, 5}
 
const BoardMapInt_t kStandardInitialBoard
 Starting board represented as 2-D array of integers.
 
const int kRepeatPeriodsToCheck [3] = {2, 3, 4}
 Max allowed repetitions of prohibited move sequence lengths.
 
const int kRepeatPeriodsMaxAllowed = 2
 Repeated move sequence lengths forbidden under move repetition rules.
 
const int kMaxMovesWithoutCapture = 120
 
const int kNumPieceTypeVals = 8
 
const unordered_map< string, PieceTypekPieceTypeStringToEnum
 
const int kNumPieceColorVals = 3
 
const unordered_map< string, PieceColorkPieceColorStringToEnum
 
const array< BoardDirection, 2 > kSideDirections
 
const vector< pair< BoardDirection, vector< BoardDirection > > > kHorsePaths
 
const vector< BoardDirectionkAllOrthogonalDirections
 
const vector< BoardDirectionkAllDiagonalDirections
 

Detailed Description

Tracking piece positions and determining legal moves.

Typedef Documentation

◆ BoardMap_t

2-D array of gameboard::GamePiece objects.

This is the data type of gameboard::GameBoard.board_map_.

Definition at line 44 of file board_data_structs.hpp.

◆ BoardMapInt_t

typedef array<array<int, kNumFiles>, kNumRanks> gameboard::BoardMapInt_t

2-D array of integers; can be converted to gameboard::BoardMap_t using gameboard::int_board_to_game_pieces.

Definition at line 47 of file board_data_structs.hpp.

◆ Castle_t

typedef array<BoardSpace, 9> gameboard::Castle_t

Definition at line 89 of file board_data_structs.hpp.

◆ MethodPtr_t

typedef void(PieceMoves::* gameboard::MethodPtr_t) (const BoardMap_t &, PieceColor, const BoardSpace &, MoveCollection &)

Definition at line 16 of file move_calculator_details.hpp.

◆ PieceDispatchArray_t

Enumeration Type Documentation

◆ PieceColor

Enumerator
kRed 
kNul 
kBlk 

Definition at line 38 of file game_piece.hpp.

◆ PieceType

Enumerator
kNnn 
kGen 
kAdv 
kEle 
kHor 
kCha 
kCan 
kSol 

Definition at line 13 of file game_piece.hpp.

Function Documentation

◆ black_castle_spaces()

constexpr Castle_t gameboard::black_castle_spaces ( )
constexpr

Definition at line 106 of file board_data_structs.hpp.

◆ build_piece_dispatch_array()

constexpr PieceDispatchArray_t gameboard::build_piece_dispatch_array ( )
inlineconstexpr

Definition at line 21 of file move_calculator_details.hpp.

◆ calc_castle_spaces()

constexpr Castle_t gameboard::calc_castle_spaces ( const CastleEdges edges)
inlineconstexpr

Definition at line 92 of file board_data_structs.hpp.

◆ get_all_spaces_occupied_by()

vector< BoardSpace > gameboard::get_all_spaces_occupied_by ( const BoardMap_t board_map,
const PieceColor  color 
)
inline

Definition at line 150 of file board_data_structs.hpp.

◆ get_color()

PieceColor gameboard::get_color ( const BoardMap_t board_map,
const BoardSpace space 
)
inline

Definition at line 124 of file board_data_structs.hpp.

◆ get_general_position()

BoardSpace gameboard::get_general_position ( const BoardMap_t board_map,
const PieceColor  color 
)
inline

Definition at line 132 of file board_data_structs.hpp.

◆ get_type()

PieceType gameboard::get_type ( const BoardMap_t board_map,
const BoardSpace space 
)
inline

Definition at line 128 of file board_data_structs.hpp.

◆ GetPieceColorOf()

PieceColor gameboard::GetPieceColorOf ( size_t  zcolor_index)
inline

Definition at line 81 of file game_piece.hpp.

◆ GetZColorIndexOf()

size_t gameboard::GetZColorIndexOf ( PieceColor  color)
inline

Definition at line 77 of file game_piece.hpp.

◆ int_board_to_game_pieces()

BoardMap_t gameboard::int_board_to_game_pieces ( const BoardMapInt_t  int_board)
inline

Definition at line 110 of file board_data_structs.hpp.

◆ is_occupied()

bool gameboard::is_occupied ( const BoardMap_t board_map,
const BoardSpace space 
)
inline

Definition at line 120 of file board_data_structs.hpp.

◆ opponent_of()

PieceColor gameboard::opponent_of ( PieceColor  color)
inline

Definition at line 38 of file board_data_structs.hpp.

◆ red_castle_spaces()

constexpr Castle_t gameboard::red_castle_spaces ( )
constexpr

Definition at line 104 of file board_data_structs.hpp.

Variable Documentation

◆ kAllDiagonalDirections

const vector< BoardDirection > gameboard::kAllDiagonalDirections
Initial value:
= {
}
Descirbes a direction on a gameboard::GameBoard.board_map_.

Definition at line 27 of file piece_moves.cpp.

◆ kAllOrthogonalDirections

const vector< BoardDirection > gameboard::kAllOrthogonalDirections
Initial value:
= {
}

Definition at line 20 of file piece_moves.cpp.

◆ kBlackCastleEdges

constexpr CastleEdges gameboard::kBlackCastleEdges = {0, 2, 3, 5}
constexpr

Definition at line 31 of file board_data_structs.hpp.

◆ kBlackRiverEdge

const BoardIndexType gameboard::kBlackRiverEdge = 4

Definition at line 21 of file board_data_structs.hpp.

◆ kHorsePaths

const vector< pair< BoardDirection, vector< BoardDirection > > > gameboard::kHorsePaths
Initial value:
= {
{BoardDirection{1, 0}, {BoardDirection{1, 1}, BoardDirection{1, -1}}},
{BoardDirection{-1, 0}, {BoardDirection{-1, 1}, BoardDirection{-1, -1}}},
{BoardDirection{0, 1}, {BoardDirection{1, 1}, BoardDirection{-1, 1}}},
{BoardDirection{0, -1}, {BoardDirection{1, -1}, BoardDirection{-1, -1}}}
}

Definition at line 13 of file piece_moves.cpp.

◆ kMaxMovesWithoutCapture

const int gameboard::kMaxMovesWithoutCapture = 120

Definition at line 17 of file game_board_for_concepts.hpp.

◆ kNumFiles

const BoardIndexType gameboard::kNumFiles = 9

Definition at line 18 of file board_data_structs.hpp.

◆ kNumPieceColorVals

const int gameboard::kNumPieceColorVals = 3

Definition at line 39 of file game_piece.hpp.

◆ kNumPieceTypeVals

const int gameboard::kNumPieceTypeVals = 8

Definition at line 23 of file game_piece.hpp.

◆ kNumRanks

const BoardIndexType gameboard::kNumRanks = 10

Definition at line 17 of file board_data_structs.hpp.

◆ kPieceColorStringToEnum

const unordered_map<string, PieceColor> gameboard::kPieceColorStringToEnum
Initial value:
= [] {
unordered_map<string, PieceColor> temp;
temp.insert(make_pair("red", PieceColor::kRed));
temp.insert(make_pair("null", PieceColor::kNul));
temp.insert(make_pair("black", PieceColor::kBlk));
return temp;
}()

Definition at line 68 of file game_piece.hpp.

◆ kPieceTypeStringToEnum

const unordered_map<string, PieceType> gameboard::kPieceTypeStringToEnum
Initial value:
= [] {
unordered_map<string, PieceType> temp;
temp.insert(make_pair("null", PieceType::kNnn));
temp.insert(make_pair("general", PieceType::kGen));
temp.insert(make_pair("advisor", PieceType::kAdv));
temp.insert(make_pair("elephant", PieceType::kEle));
temp.insert(make_pair("chariot", PieceType::kCha));
temp.insert(make_pair("horse", PieceType::kHor));
temp.insert(make_pair("cannon", PieceType::kCan));
temp.insert(make_pair("soldier", PieceType::kSol));
return temp;
}()

Definition at line 25 of file game_piece.hpp.

◆ kRedCastleEdges

constexpr CastleEdges gameboard::kRedCastleEdges = {7, 9, 3, 5}
constexpr

Definition at line 30 of file board_data_structs.hpp.

◆ kRedRiverEdge

const BoardIndexType gameboard::kRedRiverEdge = 5

Definition at line 20 of file board_data_structs.hpp.

◆ kRepeatPeriodsMaxAllowed

const int gameboard::kRepeatPeriodsMaxAllowed = 2

Repeated move sequence lengths forbidden under move repetition rules.

If kRepeatPeriodsToCheck = {2, 3, 4} and kRepeatPeriodsMaxAllowed = 2, then the following sequences are probibited: ABABAB, ABCABCABC, ABCDABCDABCD, ABCDEABCDEABCDE, ABCDEFABCDEFABCDEF

Definition at line 16 of file game_board_for_concepts.hpp.

◆ kRepeatPeriodsToCheck

const int gameboard::kRepeatPeriodsToCheck = {2, 3, 4}

Max allowed repetitions of prohibited move sequence lengths.

Definition at line 15 of file game_board_for_concepts.hpp.

◆ kSideDirections

const array< BoardDirection, 2 > gameboard::kSideDirections
Initial value:
= {
}

Definition at line 8 of file piece_moves.cpp.

◆ kStandardInitialBoard

const BoardMapInt_t gameboard::kStandardInitialBoard
Initial value:
= {{
{5, 4, 3, 2, 1, 2, 3, 4, 5},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 6, 0, 0, 0, 0, 0, 6, 0},
{7, 0, 7, 0, 7, 0, 7, 0, 7},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{-7, 0, -7, 0, -7, 0, -7, 0, -7},
{0, -6, 0, 0, 0, 0, 0, -6, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{-5, -4, -3, -2, -1, -2, -3, -4, -5},
}}

Starting board represented as 2-D array of integers.

Can be converted to array of GamePiece objects by board_utilities::int_board_to_game_pieces.

Definition at line 14 of file game_board_for_concepts.hpp.