Exemple #1
0
 // make move
 public void makeMove(Move Move)
 {
     board[Move.getNewX(), Move.getNewY()]   = board[Move.getPrevX(), Move.getPrevY()];
     board[Move.getPrevX(), Move.getPrevY()] = null;
     if (Move.getIsBeating())
     {
         if (board[Move.getBeatingX(), Move.getBeatingY()].isFirstPlayer())
         {
             --firstPawns;
         }
         else if (!board[Move.getBeatingX(), Move.getBeatingY()].isFirstPlayer())
         {
             --secondPawns;
         }
         board[Move.getBeatingX(), Move.getBeatingY()] = null;
         if (Move.getNextBeating() != null)
         {
             makeMove(Move.getNextBeating());
         }
         else
         {
             grandForKing(Move.getNewX(), Move.getNewY());
         }
     }
     else
     {
         grandForKing(Move.getNewX(), Move.getNewY());
     }
 }
Exemple #2
0
 //deep copy
 public Move(Move move)
 {
     this.prevX       = move.getPrevX();
     this.prevY       = move.getPrevY();
     this.newX        = move.getNewX();
     this.newY        = move.getNewY();
     this.beatenX     = move.getBeatingX();
     this.beatenY     = move.getBeatingY();
     this.isBeating   = move.getIsBeating();
     this.prevBeating = move.getPrevBeating();
     this.nextBeating = move.getNextBeating();
 }
Exemple #3
0
        // checks all possibilities of multiple beatings
        private void multipleBeatings(bool isFirstPlayer, List <Move> possibleMovements, Move move, int startX, int startY)
        {
            int  x          = move.getNewX();
            int  y          = move.getNewY();
            int  beatenX    = move.getBeatingX();
            int  beatenY    = move.getBeatingY();
            Pawn beatenPawn = board[beatenX, beatenY];

            board[move.getBeatingX(), move.getBeatingY()] = null;
            if (!board[startX, startY].checkIfKing())
            {
                if (isFirstPlayer)
                {
                    if (isInBoard(x - 2, y - 2) && board[x - 2, y - 2] == null && board[x - 1, y - 1] != null && board[x - 1, y - 1].isFirstPlayer() != isFirstPlayer ||
                        isInBoard(x - 2, y + 2) && board[x - 2, y + 2] == null && board[x - 1, y + 1] != null && board[x - 1, y + 1].isFirstPlayer() != isFirstPlayer)
                    {
                        if (isInBoard(x - 2, y - 2) && board[x - 2, y - 2] == null && board[x - 1, y - 1] != null && board[x - 1, y - 1].isFirstPlayer() != isFirstPlayer)
                        {
                            Move newMovement = new Move(x, y, x - 2, y - 2, x - 1, y - 1, move);
                            move.setNextBeating(newMovement);
                            multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                        }
                        if (isInBoard(x - 2, y + 2) && board[x - 2, y + 2] == null && board[x - 1, y + 1] != null && board[x - 1, y + 1].isFirstPlayer() != isFirstPlayer)
                        {
                            Move newMovement = new Move(x, y, x - 2, y + 2, x - 1, y + 1, move);
                            move.setNextBeating(newMovement);
                            multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                        }
                    }
                    else
                    {
                        while (move.getPrevBeating() != null)
                        {
                            move = new Move(move.getPrevBeating());
                        }
                        possibleMovements.Add(move);
                    }
                }
                else
                {
                    if (isInBoard(x + 2, y - 2) && board[x + 2, y - 2] == null && board[x + 1, y - 1] != null && board[x + 1, y - 1].isFirstPlayer() != isFirstPlayer ||
                        isInBoard(x + 2, y + 2) && board[x + 2, y + 2] == null && board[x + 1, y + 1] != null && board[x + 1, y + 1].isFirstPlayer() != isFirstPlayer)
                    {
                        if (isInBoard(x + 2, y - 2) && board[x + 2, y - 2] == null && board[x + 1, y - 1] != null && board[x + 1, y - 1].isFirstPlayer() != isFirstPlayer)
                        {
                            Move newMovement = new Move(x, y, x + 2, y - 2, x + 1, y - 1, move);
                            move.setNextBeating(newMovement);
                            multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                        }
                        if (isInBoard(x + 2, y + 2) && board[x + 2, y + 2] == null && board[x + 1, y + 1] != null && board[x + 1, y + 1].isFirstPlayer() != isFirstPlayer)
                        {
                            Move newMovement = new Move(x, y, x + 2, y + 2, x + 1, y + 1, move);
                            move.setNextBeating(newMovement);
                            multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                        }
                    }
                    else
                    {
                        while (move.getPrevBeating() != null)
                        {
                            move = new Move(move.getPrevBeating());
                        }
                        possibleMovements.Add(move);
                    }
                }
            }
            else //kings
            {
                if (isInBoard(x - 2, y - 2) && board[x - 2, y - 2] == null && board[x - 1, y - 1] != null && board[x - 1, y - 1].isFirstPlayer() != isFirstPlayer ||
                    isInBoard(x - 2, y + 2) && board[x - 2, y + 2] == null && board[x - 1, y + 1] != null && board[x - 1, y + 1].isFirstPlayer() != isFirstPlayer ||
                    isInBoard(x + 2, y - 2) && board[x + 2, y - 2] == null && board[x + 1, y - 1] != null && board[x + 1, y - 1].isFirstPlayer() != isFirstPlayer ||
                    isInBoard(x + 2, y + 2) && board[x + 2, y + 2] == null && board[x + 1, y + 1] != null && board[x + 1, y + 1].isFirstPlayer() != isFirstPlayer)
                {
                    if (isInBoard(x - 2, y - 2) && board[x - 2, y - 2] == null && board[x - 1, y - 1] != null && board[x - 1, y - 1].isFirstPlayer() != isFirstPlayer)
                    {
                        Move newMovement = new Move(x, y, x - 2, y - 2, x - 1, y - 1, move);
                        move.setNextBeating(newMovement);
                        multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                    }
                    if (isInBoard(x - 2, y + 2) && board[x - 2, y + 2] == null && board[x - 1, y + 1] != null && board[x - 1, y + 1].isFirstPlayer() != isFirstPlayer)
                    {
                        Move newMovement = new Move(x, y, x - 2, y + 2, x - 1, y + 1, move);
                        move.setNextBeating(newMovement);
                        multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                    }
                    if (isInBoard(x + 2, y - 2) && board[x + 2, y - 2] == null && board[x + 1, y - 1] != null && board[x + 1, y - 1].isFirstPlayer() != isFirstPlayer)
                    {
                        Move newMovement = new Move(x, y, x + 2, y - 2, x + 1, y - 1, move);
                        move.setNextBeating(newMovement);
                        multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                    }
                    if (isInBoard(x + 2, y + 2) && board[x + 2, y + 2] == null && board[x + 1, y + 1] != null && board[x + 1, y + 1].isFirstPlayer() != isFirstPlayer)
                    {
                        Move newMovement = new Move(x, y, x + 2, y + 2, x + 1, y + 1, move);
                        move.setNextBeating(newMovement);
                        multipleBeatings(isFirstPlayer, possibleMovements, newMovement, startX, startY);
                    }
                }
                else
                {
                    while (move.getPrevBeating() != null)
                    {
                        move = new Move(move.getPrevBeating());
                    }
                    possibleMovements.Add(move);
                }
            }
            board[beatenX, beatenY] = beatenPawn;
            beatenPawn = null;
        }