Ejemplo n.º 1
0
 public XNAGameScreenView(Game game, GameBoard gameBoard, XNAGameBoard xnaGameBoard)
     : base(game)
 {
     contentManager = game.Content;
     this.gameBoard = gameBoard;
     darkSquare = contentManager.Load<Texture2D>(@"Textures\darksquare");
     lightSquare = contentManager.Load<Texture2D>(@"Textures\lightsquare");
     backGround = contentManager.Load<Texture2D>(@"Textures\background");
     crown = contentManager.Load<Texture2D>(@"Textures\crown");
     blackWins = contentManager.Load<Texture2D>(@"Textures\blackWins");
     whiteWins = contentManager.Load<Texture2D>(@"Textures\whiteWins");
     title = contentManager.Load<Texture2D>(@"Textures\Title");
     onePlayer = contentManager.Load<Texture2D>(@"Textures\1Player");
     twoPlayer = contentManager.Load<Texture2D>(@"Textures\2Player");
     yourTurn = contentManager.Load<Texture2D>(@"Textures\YourTurn");
     phoneTurn = contentManager.Load<Texture2D>(@"Textures\Thinking");
     playerOneTurn = contentManager.Load<Texture2D>(@"Textures\Player1Turn");
     playerTwoTurn = contentManager.Load<Texture2D>(@"Textures\Player2Turn");
     selectDifficulty = contentManager.Load<Texture2D>(@"Textures\SelectDifficulty");
     easy = contentManager.Load<Texture2D>(@"Textures\easy");
     normal = contentManager.Load<Texture2D>(@"Textures\normal");
     hard = contentManager.Load<Texture2D>(@"Textures\hard");
     whitePiece = contentManager.Load<Texture2D>(@"Textures\whitepiece");
     blackPiece = contentManager.Load<Texture2D>(@"Textures\blackPiece");
     whiteKingPiece = contentManager.Load<Texture2D>(@"Textures\whiteking");
     blackKingPiece = contentManager.Load<Texture2D>(@"Textures\blackking");
     possibleMove = contentManager.Load<Texture2D>(@"Textures\possibleMove");
     forceJumps = contentManager.Load<Texture2D>(@"Textures\ForceJumps");
     checkedBox = contentManager.Load<Texture2D>(@"Textures\checked");
     unCheckedBox = contentManager.Load<Texture2D>(@"Textures\unchecked");
     whiteTurn = contentManager.Load<Texture2D>(@"Textures\whiteTurn");
     blackTurn = contentManager.Load<Texture2D>(@"Textures\blackTurn");
     this.xnaGameBoard = xnaGameBoard;
 }
Ejemplo n.º 2
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.º 3
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.º 4
0
 public List<GamePieceMove> GetAIMoves(GameBoard board)
 {
     List<GamePieceMove> moves = new List<GamePieceMove>();
     MiniMax(board);
     moves.Add(bestMove);
     moves.AddRange(GetAddtionalMoves(board, bestMove));
     return moves;
 }
Ejemplo n.º 5
0
 public void MiniMaxWithoutAlphaBetaPruning(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 = MinWithoutAlphaBetaPruning(CreateCurrentBoard(board, move), FIRSTSTEP);
         board.UnDoMove(move);
         if (currentValue > bestValue)
         {
             bestMove = move;
             bestValue = currentValue;
         }
     }
     endTime = System.DateTime.Now;
 }
Ejemplo n.º 6
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 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;
        }
Ejemplo n.º 7
0
 protected override void Initialize()
 {
     gameBoard = new GameBoard();
     xnaGameBoard = new XNAGameBoard();
     xnaGameScreenView = new XNAGameScreenView(this, gameBoard, xnaGameBoard);
     //gameTurn = PlayerTurn.WhiteTurn;
     gameState = GameStates.TitleScreen;
     TouchPanel.EnabledGestures = GestureType.Tap;
     xnaGameScreenView.CreateHowManyPlayersButtons();
     xnaGameScreenView.CreateCheckBox();
     spriteBatch = new SpriteBatch(GraphicsDevice);
     base.Initialize();
 }
Ejemplo n.º 8
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.º 9
0
 private GameBoard CreateCurrentBoard(GameBoard board, GamePieceMove move)
 {
     GameBoard currentBoard = new GameBoard();
     currentBoard = board.CloneBoard();
     currentBoard.ApplyMove(move);
     currentBoard = MakeAddtionalMoves(currentBoard, move).CloneBoard();
     return currentBoard;
 }
Ejemplo n.º 10
0
 public void MinMaxTest()
 {
     AI_Accessor target = new AI_Accessor();
     GameBoard_Accessor board =  CreateTestBoard();
     GameBoard testBoard = new GameBoard();
     testBoard = board.CloneBoard();
     target.numberOfMovesAhead = 2;
     List<GamePieceMove> aiMoves = target.GetAIMoves(testBoard);
     foreach(GamePieceMove move in aiMoves)
         testBoard.ApplyMove(move);
     string expected = "\nB_B_B___\n___w____\n______B_\n_w______\n__b___b_\n________\n________\n___W_W__";
     string actual = testBoard.ToString();
     Assert.AreEqual(expected,actual);
 }
Ejemplo n.º 11
0
 public void EvaluateBoardForWhitePlayerUsingInitialBoard()
 {
     GameBoard target = new GameBoard();
     PlayerColours playerColour = PlayerColours.White;
     int expected = 12;
     int actual;
     actual = target.EvaluateBoard(playerColour);
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 12
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.º 13
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;
         }
     }
 }