22 #ifndef MEDIASTATION_MINIGAMES_CHECKERS_H 23 #define MEDIASTATION_MINIGAMES_CHECKERS_H 25 #include "common/array.h" 27 #include "mediastation/actor.h" 28 #include "mediastation/mediascript/collection.h" 32 namespace CheckersMinigame {
34 const int COLUMN_COUNT = 8;
35 const int ROW_COUNT = 8;
36 const int PLAYABLE_CELLS_PER_ROW = 4;
37 const int TOTAL_CELLS = COLUMN_COUNT * ROW_COUNT;
38 const int TOTAL_PLAYABLE_CELLS = ROW_COUNT * PLAYABLE_CELLS_PER_ROW;
41 kUnoccupiedBySide = 0,
58 static constexpr CellClass CELL_CLASSIFICATION[TOTAL_PLAYABLE_CELLS] = {
59 kCellCorner, kCellNearCorner, kCellNearCorner, kCellNormal,
60 kCellCorner, kCellNormal, kCellNormal, kCellNormal,
61 kCellNormal, kCellNormal, kCellNormal, kCellOuterCenter,
62 kCellOuterCenter, kCellCenter, kCellCenter, kCellNormal,
63 kCellNormal, kCellCenter, kCellCenter, kCellOuterCenter,
64 kCellOuterCenter, kCellNormal, kCellNormal, kCellNormal,
65 kCellNormal, kCellNormal, kCellNormal, kCellCorner,
66 kCellNormal, kCellNearCorner, kCellNearCorner, kCellCorner
72 Side side = kUnoccupiedBySide;
75 bool isOccupied()
const {
return side != kUnoccupiedBySide; }
76 bool isMan()
const {
return isOccupied() && !isKing; }
84 constexpr
Pair() =
default;
85 constexpr
Pair(
int x_,
int y_) : x(x_), y(y_) {}
87 Pair(
int linearCellIndex);
88 int toLinearCellIndex()
const;
90 bool isWithinBoard()
const;
91 Pair operator+(
const Pair &other)
const;
101 int totalBlackMen = 0;
102 int totalBlackKings = 0;
103 int totalWhiteMen = 0;
104 int totalWhiteKings = 0;
111 bool willCapture =
false;
112 bool willBecomeKing =
false;
119 enum CheckersCommand {
120 kCheckersCommandPiecesThatCanMove = 1,
121 kCheckersGetValidMoves = 2,
122 kCheckersNewGame = 3,
123 kCheckersFindBestMove = 4,
124 kCheckersTakeMove = 5,
125 kCheckersCommandDebugPrint = -2,
126 kCheckersCommandValidateBoard = -1
135 const Cell &cellAt(
const Pair &position)
const;
136 Cell &cellAt(uint linearIndex);
146 void getValidMovesForPiece(
148 bool calculateAndSortAllMovesForSide(Side side);
149 void prepareForBestMoveSearch(
int depth);
150 bool searchForBestMove(
int maxSearchTimeInMs);
151 Move &getCalculatedBestMove();
152 bool validateBoard()
const;
153 void printToDebug()
const;
158 int _maxSearchDepth = 1;
159 Side _sideToMove = kUnoccupiedBySide;
166 bool canMove(
const Board &board, Side side);
172 int alphaBetaEvaluate(
const Board &board,
Move &parentMove, Side maximizingSide, Side sideToMove,
int alpha,
int beta,
int ply, uint32 deadline);
175 int getTotalBoardScoreForSide(
const Board &board, Side side);
176 int getWeightedSquareScoreForSide(
const Board &board, Side side);
184 return left.score > right.score;
Out move(In first, In last, Out dst)
Definition: algorithm.h:109