示例#1
0
文件: AI.cs 项目: kev148/WPDraughts
        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;
        }
示例#2
0
文件: AI.cs 项目: kev148/WPDraughts
        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 m in addtionalMoves)
            {
                GameBoard currentBoard = new GameBoard();
                currentBoard = board.CloneBoard();
                currentBoard.ApplyMove(m);
                currentBoard = MakeAddtionalMoves(currentBoard, m);
                if (currentBoard.EvaluateBoard(PlayerColours.Black) > bestBoardValue)
                    bestBoard = currentBoard;
                board.UnDoMove(m);
            }
            return bestBoard;
        }
示例#3
0
文件: AI.cs 项目: kev148/WPDraughts
 private GameBoard CreateCurrentBoard(GameBoard board, GamePieceMove move)
 {
     GameBoard currentBoard = new GameBoard();
     currentBoard = board.CloneBoard();
     currentBoard.ApplyMove(move);
     currentBoard = MakeAddtionalMoves(currentBoard, move).CloneBoard();
     return currentBoard;
 }
示例#4
0
文件: AI.cs 项目: kev148/WPDraughts
 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;
     }
 }
示例#5
0
文件: AI.cs 项目: kev148/WPDraughts
 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;
         }
     }
 }