예제 #1
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;
        }