Пример #1
0
        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;
        }
Пример #2
0
 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);
 }
Пример #3
0
 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;
 }
Пример #4
0
        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;
        }
Пример #5
0
 public override float Evaluate(Disc playerToMove, Board board)
 {
     int movesAvailable = board.Moves(playerToMove).Length;
     return (float) Math.Min(Math.Pow(movesAvailable - 4, 3), 20);
 }
Пример #6
0
 public abstract string GetMove(Board game);
Пример #7
0
 public override string GetMove(Board game)
 {
     return "a1";
 }
Пример #8
0
 public override float Evaluate(Disc playerToMove, Board board)
 {
     return Evaluator.Evaluate(playerToMove, board) * Weight;
 }
Пример #9
0
 public abstract float Evaluate(Disc playerToMove, Board board);