This class represents a Chinese Checkers game The ChineseCheckers class is responsible for representing the game of Chinese Checkers and for providing functionalities such as checking if a move is legal, executing moves, printing the game state, returning the current state of the game, and creating a new game. It also stores information about the grid, the number of times a position has been seen, the winning positions, and the illegal positions.
More...
#include <ChineseCheckers.hpp>
|
const uint_fast64_t | un_64_ = static_cast<uint_fast64_t>(1) |
|
Player | who_is_to_play_ = 0 |
|
bitBoards_t | bit_boards_ |
|
uint_fast64_t | zobrist_hash_ |
|
std::array< boost::unordered_map< uint_fast64_t, uint_fast64_t >, 2 > | zobrist_keys_ |
|
std::array< boost::unordered_map< uint_fast64_t, uint_fast64_t >, 2 > | zobrist_keys_moves_ |
|
boost::unordered_map< uint64_t, int > | number_of_times_seen_ |
|
std::vector< uint64_t > | positions_seen_ |
|
const uint_fast64_t | winning_positions_white_ = 0xF0E0C08000000000 |
|
const uint_fast64_t | winning_positions_black_ = 0x000000000103070F |
|
const boost::unordered_map< uint32_t, bool > | illegal_positions_ |
|
const std::array< std::array< uint32_t, 8 >, 8 > | cantor_pairing_ |
|
const std::vector< std::vector< int > > | valid_lines |
|
const std::vector< std::vector< int > > | valid_lines_illegal |
|
const std::array< std::pair< int, int >, 64 > | uint64_to_pair_ |
|
const std::array< std::array< uint_fast64_t, 8 >, 8 > | int_to_uint64_ |
|
const std::array< std::vector< uint_fast64_t >, 64 > | direct_neighbours_ |
|
const std::array< std::vector< std::vector< std::pair< std::pair< uint_fast64_t, uint_fast64_t >, uint_fast64_t > > >, 64 > | k_neighbours_ |
|
This class represents a Chinese Checkers game The ChineseCheckers class is responsible for representing the game of Chinese Checkers and for providing functionalities such as checking if a move is legal, executing moves, printing the game state, returning the current state of the game, and creating a new game. It also stores information about the grid, the number of times a position has been seen, the winning positions, and the illegal positions.
◆ ChineseCheckers()
ChineseCheckers::ChineseCheckers |
( |
| ) |
|
Construct the object
- See also
- newGame
◆ cantorPairingFunction()
int ChineseCheckers::cantorPairingFunction |
( |
const int & |
x, |
|
|
const int & |
y |
|
) |
| const |
|
protected |
◆ computeAndSetZobristHash()
void ChineseCheckers::computeAndSetZobristHash |
( |
| ) |
|
|
protected |
The function calculates the Zobrist hash value for the current game state based on the position of each piece on the board, using precomputed random keys for each square and each color. The hash value is stored in the zobrist_hash_ member variable.
- See also
- generateZobristKeys
◆ elementaryMove()
A member returning the type of an elementary move (not a succession of jumps).
- Parameters
-
original_position | The position. |
arrival_position | The arrival position. |
- Return values
-
Illegal | if the elementary move realized was of illegal. |
Jump | if the elementary move realized was a jump. |
notJump | if the elementary move realized was not a jump. |
- See also
- move
◆ generateZobristKeys()
void ChineseCheckers::generateZobristKeys |
( |
| ) |
|
|
protected |
◆ getBitBoardBlack()
uint_fast64_t ChineseCheckers::getBitBoardBlack |
( |
| ) |
const |
Returns bit_boards_.Black
- Returns
- bit_boards_.Black
◆ getBitBoardWhite()
uint_fast64_t ChineseCheckers::getBitBoardWhite |
( |
| ) |
const |
Returns bit_boards_.White
- Returns
- bit_boards_.White
◆ getWhoIsToPlay()
Player ChineseCheckers::getWhoIsToPlay |
( |
| ) |
const |
◆ isPositionIllegal()
bool ChineseCheckers::isPositionIllegal |
( |
| ) |
const |
|
protected |
◆ loadIllegalPositions()
boost::unordered_map< uint32_t, bool > ChineseCheckers::loadIllegalPositions |
( |
| ) |
const |
|
protected |
◆ move()
This member checks if a move is legal and executes it if it is legal.
- Parameters
-
player | indicates which player made the move. |
list_moves | contains the list of intermediate positions. of a move (including the starting point and the arrival point). |
- Return values
-
true | if the move was legal. |
false | if the move was not legal. |
- See also
- MoveType elementaryMove
◆ moveWithoutVerification()
void ChineseCheckers::moveWithoutVerification |
( |
const uint_fast64_t & |
move | ) |
|
This function is used to move a piece without verifying if the move is valid or not. It is not made to be used by the end user. It has been engineered to be used by solvers. It bypasses usual verifications and hence allows illegal moves to be played. This function should be used with great care.
- Parameters
-
move | indicates the move do execute. This is a 64 bit type. Only two bits must be set : the original position and the arrival position. |
- See also
- elementaryMove
-
move
◆ newGame()
void ChineseCheckers::newGame |
( |
| ) |
|
◆ printGrid()
void ChineseCheckers::printGrid |
( |
| ) |
const |
◆ printWhoIsToPlay()
void ChineseCheckers::printWhoIsToPlay |
( |
| ) |
const |
◆ stateOfGame()
Result ChineseCheckers::stateOfGame |
( |
| ) |
|
This function returns the current state of the game, which can be one of the following four values: WhiteWon, BlackWon, Draw, or NotFinished.
- Return values
-
notFinished | if the game is not finished. |
whiteWon | if white won the game. |
blackWon | if black won the game. |
draw | if a draw happened. |
- See also
- newGame
◆ bit_boards_
bitBoards_t ChineseCheckers::bit_boards_ |
|
protected |
A data structure containing the grid.
◆ cantor_pairing_
const std::array<std::array<uint32_t, 8>, 8> ChineseCheckers::cantor_pairing_ |
|
protected |
Stores results of cantor pairing to make the check for illegal positions faster.
◆ direct_neighbours_
const std::array<std::vector<uint_fast64_t>, 64> ChineseCheckers::direct_neighbours_ |
|
protected |
Stores the neighbours' position of all pawns.
◆ illegal_positions_
const boost::unordered_map<uint32_t, bool> ChineseCheckers::illegal_positions_ |
|
protected |
Stores the illegal positions.
◆ int_to_uint64_
const std::array<std::array<uint_fast64_t, 8>, 8> ChineseCheckers::int_to_uint64_ |
|
protected |
Stores the conversion of a pair of index to a bit-wise position.
◆ k_neighbours_
const std::array<std::vector< std::vector<std::pair<std::pair<uint_fast64_t, uint_fast64_t>, uint_fast64_t> > >, 64> ChineseCheckers::k_neighbours_ |
|
protected |
@detailsStores all required bitMasks to find all jumps from a given pawn.
◆ number_of_times_seen_
boost::unordered_map<uint64_t , int> ChineseCheckers::number_of_times_seen_ |
|
protected |
Indicates the number of times a position has been seen. It is used to check for draws.
◆ positions_seen_
std::vector<uint64_t> ChineseCheckers::positions_seen_ |
|
protected |
Indicate the positions we have already seen.
◆ uint64_to_pair_
const std::array<std::pair<int, int>, 64> ChineseCheckers::uint64_to_pair_ |
|
protected |
Stores the conversion of a bit-wise position to a pair of index.
◆ un_64_
const uint_fast64_t ChineseCheckers::un_64_ = static_cast<uint_fast64_t>(1) |
|
protected |
Basic object used to create bitmasks efficiently.
◆ valid_lines
const std::vector<std::vector<int> > ChineseCheckers::valid_lines |
|
protected |
Initial value:= {{-1, 0}, {-1, 1}, {0 , -1},
{0 , 1}, {1 , -1}, {1 , 0}}
Stores the valid directions to find if a move is valid faster.
◆ valid_lines_illegal
const std::vector<std::vector<int> > ChineseCheckers::valid_lines_illegal |
|
protected |
Initial value:= {{-1, 0}, {-1, 1}, {0 , -1},
{0 , 1}, {1 , -1}, {1 , 0},
{-2, 0}, {-2, 2}, {0 , -2},
{0 , 2}, {2 , -2}, {2 , 0}}
Stores the valid directions to find if a position is legal faster.
◆ who_is_to_play_
Player ChineseCheckers::who_is_to_play_ = 0 |
|
protected |
Indicate which is the next player to play.
◆ winning_positions_black_
const uint_fast64_t ChineseCheckers::winning_positions_black_ = 0x000000000103070F |
|
protected |
Keeps the positions of the black winning zone.
◆ winning_positions_white_
const uint_fast64_t ChineseCheckers::winning_positions_white_ = 0xF0E0C08000000000 |
|
protected |
Keeps the positions of the white winning zone.
◆ zobrist_hash_
uint_fast64_t ChineseCheckers::zobrist_hash_ |
|
protected |
The hash of the current grid.
◆ zobrist_keys_
std::array<boost::unordered_map<uint_fast64_t, uint_fast64_t>, 2> ChineseCheckers::zobrist_keys_ |
|
protected |
Zobrist keys associated with each positions.
◆ zobrist_keys_moves_
std::array<boost::unordered_map<uint_fast64_t, uint_fast64_t>, 2> ChineseCheckers::zobrist_keys_moves_ |
|
protected |
Zobrist keys associated to a move.
The documentation for this class was generated from the following files: