Exemple #1
0
        public int Min(GameBoard board, int step,ref int alpha,ref int beta)
        {
            minCalls++;
            if (board.IsGameOver() || IsDepthReached(step))
                return board.EvaluateBoard(PlayerColours.Black);
            else
            {
                int bestValue = int.MaxValue;
                List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.White);
                foreach (GamePieceMove move in PossibleMoves)
                {
                    int currentValue = Max(CreateCurrentBoard(board, move), step + 1, ref alpha, ref beta);
                    board.UnDoMove(move);
                    if (currentValue < bestValue)
                    {
                        bestValue = currentValue;
                        beta = currentValue;
                    }
                    if (beta <= alpha)
                        return bestValue;

                }
                return bestValue;
            }
        }
Exemple #2
0
 public int MinWithoutAlphaBetaPruning(GameBoard board, int step)
 {
     minCalls++;
     if (board.IsGameOver() || IsDepthReached(step))
         return board.EvaluateBoard(PlayerColours.Black);
     else
     {
         int bestValue = int.MaxValue;
         List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.White);
         foreach (GamePieceMove move in PossibleMoves)
         {
             int currentValue = MaxWithoutAlphaBetaPruning(CreateCurrentBoard(board, move), step + 1);
             board.UnDoMove(move);
             if (currentValue < bestValue)
                 bestValue = currentValue;
         }
         return bestValue;
     }
 }
Exemple #3
0
 private int Max(GameBoard board, int step, ref int alpha, ref int beta)
 {
     if (board.IsGameOver() || IsDepthReached(step))
         return board.EvaluateBoard(PlayerColours.Black);
     else
     {
         int bestValue = 0;
         List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.Black);
         foreach (GamePieceMove move in PossibleMoves)
         {
             GameBoard currentBoard = new GameBoard();
             currentBoard = board.CloneBoard();
             currentBoard.ApplyMove(move);
             currentBoard = MakeAddtionalMoves(currentBoard, move).CloneBoard();
             int currentValue = Min(currentBoard, step + 1, ref alpha, ref beta);
             board.UnDoMove(move);
             if (currentValue > bestValue)
             {
                 bestValue = currentValue;
                 alpha = bestValue;
             }
             if (beta >= alpha)
                 return bestValue;
         }
         return bestValue;
     }
 }