private float Alphabeta(Board board, Disc playerToMove, int distanceToLeafNodes, float alpha, float beta) { if (distanceToLeafNodes == 0) { NodesEvaluated++; return _nodeEvaluator.Evaluate(playerToMove, board); } float best = float.MinValue; foreach (Square move in board.Moves(playerToMove)) { if (best >= beta) { BetaCutoffs++; break; } var childBoard = new Board(board); childBoard.MakeMove(playerToMove, move); if (best > alpha) alpha = best; float score = -Alphabeta(childBoard, playerToMove.Opponent(), distanceToLeafNodes - 1, -beta, -alpha); if (score > best) { best = score; if (distanceToLeafNodes == _currentSearchDepth) { BestScore = score; BestMove = move; } } } return best; }
public Board(Board board) { //Copy members for (int row = 0; row < 8; row++) for (int col = 0; col < 8; col++) _squares[row, col] = board._squares[row, col]; _squaresRemaining = CountDiscs(Disc.None); }
public override float Evaluate(Disc playerToMove, Board board) { int divisor = 0; float total = 0; foreach (var evaluator in Evaluators) { total += evaluator.Evaluate(playerToMove, board); divisor += evaluator.Weight; } if (divisor == 0) return 0; return total / divisor; }
public override float Evaluate(Disc playerToMove, Board board) { NodesEvaluated = 0; BetaCutoffs = 0; if (IterativeDeepening) _currentSearchDepth = 1; else _currentSearchDepth = MaxSearchDepth; while (_currentSearchDepth <= MaxSearchDepth) { _currentSearchDepth++; Alphabeta(board, playerToMove, _currentSearchDepth, float.MinValue, float.MaxValue); } return BestScore; }
public override float Evaluate(Disc playerToMove, Board board) { int movesAvailable = board.Moves(playerToMove).Length; return (float) Math.Min(Math.Pow(movesAvailable - 4, 3), 20); }
public abstract string GetMove(Board game);
public override string GetMove(Board game) { return "a1"; }
public override float Evaluate(Disc playerToMove, Board board) { return Evaluator.Evaluate(playerToMove, board) * Weight; }
public abstract float Evaluate(Disc playerToMove, Board board);