示例#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
文件: Board.cs 项目: rofr/othello-net
 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);