Ejemplo n.º 1
0
        private List<GamePieceMove> GetAddtionalMoves(GameBoard board, GamePieceMove bestMove)
        {
            List<GamePieceMove> moves = new List<GamePieceMove>();
            List<GamePieceMove> bestMoves = new List<GamePieceMove>();
            int bestBoardValue = board.EvaluateBoard(PlayerColours.Black);

            GameBoard nextBoard = new GameBoard();
            nextBoard = board.CloneBoard();
            nextBoard.ApplyMove(bestMove);

            if (bestMove.IsJump)
                moves.AddRange(board.GetAllPossibleJumpsForThisPiece(bestMove.MovingPiece));
            foreach (GamePieceMove m in moves)
            {
                GameBoard currentBoard = new GameBoard();
                currentBoard = nextBoard.CloneBoard();
                currentBoard.ApplyMove(m);
                //currentBoard = MakeAddtionalMoves(currentBoard, m);
                if (currentBoard.EvaluateBoard(PlayerColours.Black) > bestBoardValue)
                    bestMoves.Add(m);
                bestMoves.AddRange(GetAddtionalMoves(currentBoard, m));
                board.UnDoMove(m);
            }
            board.UnDoMove(bestMove);
            return bestMoves;
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
 public void MiniMax(GameBoard board)
 {
     startTime = System.DateTime.Now;
     maxCalls = 0;
     minCalls = 0;
     int bestValue = 0;
     List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.Black);
     foreach (GamePieceMove move in PossibleMoves)
     {
         int currentValue = Min(CreateCurrentBoard(board, move), FIRSTSTEP, ref alpha, ref beta);
         board.UnDoMove(move);
         if (currentValue > bestValue)
         {
             bestMove = move;
             bestValue = currentValue;
         }
     }
     endTime = System.DateTime.Now;
 }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
0
        private GameBoard MakeAddtionalMoves(GameBoard board, GamePieceMove move)
        {
            List<GamePieceMove> addtionalMoves = new List<GamePieceMove>();
            GameBoard bestBoard = board.CloneBoard();
            int bestBoardValue = bestBoard.EvaluateBoard(PlayerColours.Black);

            if (move.IsJump && board.IsThereASecondJump(move))
                addtionalMoves.AddRange(board.GetAllPossibleJumpsForThisPiece(move.MovingPiece));
            foreach (GamePieceMove moves in addtionalMoves)
            {
                GameBoard currentBoard = CreateCurrentBoard(board, moves);
                if (currentBoard.EvaluateBoard(PlayerColours.Black) > bestBoardValue)
                    bestBoard = currentBoard;
                board.UnDoMove(moves);
            }
            return bestBoard;
        }
Ejemplo n.º 6
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;
     }
 }
Ejemplo n.º 7
0
 private void MiniMax(GameBoard board)
 {
     int bestValue = 0;
     List<GamePieceMove> PossibleMoves = board.GetAllPossibleMoves(PlayerColours.Black);
     foreach (GamePieceMove move in PossibleMoves)
     {
         GameBoard currentBoard = board.CloneBoard();
         currentBoard.ApplyMove(move);
         currentBoard = MakeAddtionalMoves(currentBoard, move).CloneBoard();
         int currentValue = Min(currentBoard, FIRSTSTEP,ref alpha,ref beta);
         board.UnDoMove(move);
         if (currentValue > bestValue)
         {
             bestMove = move;
             bestValue = currentValue;
         }
     }
 }