int EvaluateMove(Board& board, int alpha, int beta, int depth, bool maximizing) { if (board.kingDead) { return maximizing ? -999111 : 999111; } if (depth == 0) { return EvaluateBoard(board); } vector<Move> possibleMoves; possibleMoves.reserve(100); GenerateAll(board, possibleMoves); int returnVal; if (maximizing) { for (Move move : possibleMoves) { board.MakeMove(move); alpha = max(alpha, EvaluateMove(board, alpha, beta, depth - 1, false)); if (beta <= alpha) { board.UndoMove(); break; } board.UndoMove(); } returnVal = alpha; } else { for (Move move : possibleMoves) { board.MakeMove(move); beta = min(beta, EvaluateMove(board, alpha, beta, depth - 1, true)); if (beta <= alpha) { board.UndoMove(); break; } board.UndoMove(); } returnVal = beta; } return returnVal; }
void HexMC2Player::Move(HexBoard &board, HexColor turn, unsigned int &row, unsigned int &col) { unsigned int idPlay, bestPlay, trow, tcol; int score, bestScore = -1; MoveGenerator mg(board); while (mg.Next(idPlay, trow, tcol)) { score = EvaluateMove(board, turn, trow, tcol); if (score > bestScore) { bestScore = score; bestPlay = idPlay; } } mg.Get(bestPlay, row, col); }