Exemple #1
0
    public List <int> AvailableMoves(List <GameObject> board, int currentPos)
    {
        int        x          = currentPos % 4;
        int        y          = currentPos / 4;
        List <int> validMoves = new List <int>();

        if (emptyOrOpponent(board, x + 1, y + 2))
        {
            validMoves.Add(Library.GetBoardIndex(x + 1, y + 2));
        }
        if (emptyOrOpponent(board, x - 1, y + 2))
        {
            validMoves.Add(Library.GetBoardIndex(x - 1, y + 2));
        }
        if (emptyOrOpponent(board, x + 1, y - 2))
        {
            validMoves.Add(Library.GetBoardIndex(x + 1, y - 2));
        }
        if (emptyOrOpponent(board, x - 1, y - 2))
        {
            validMoves.Add(Library.GetBoardIndex(x - 1, y - 2));
        }
        if (emptyOrOpponent(board, x + 2, y + 1))
        {
            validMoves.Add(Library.GetBoardIndex(x + 2, y + 1));
        }
        if (emptyOrOpponent(board, x + 2, y - 1))
        {
            validMoves.Add(Library.GetBoardIndex(x + 2, y - 1));
        }
        if (emptyOrOpponent(board, x - 2, y + 1))
        {
            validMoves.Add(Library.GetBoardIndex(x - 2, y + 1));
        }
        if (emptyOrOpponent(board, x - 2, y - 1))
        {
            validMoves.Add(Library.GetBoardIndex(x - 2, y - 1));
        }

        audioPlayer.SE_PickUp();
        return(validMoves);
    }
Exemple #2
0
    public List <int> AvailableMoves(List <GameObject> board, int currentPos)
    {
        int        x          = currentPos % 4;
        int        y          = currentPos / 4;
        List <int> validMoves = new List <int>();
        int        index      = -1;

        if (x != 0)
        {
            // Left
            index = Library.GetBoardIndex(x - 1, y);
            if (emptyOrOpponent(board, index))
            {
                validMoves.Add(index);
            }

            // Up and Left
            if (y != 0)
            {
                index = Library.GetBoardIndex(x - 1, y - 1);
                if (emptyOrOpponent(board, index))
                {
                    validMoves.Add(index);
                }
            }
            // Down and Left
            if (y != 7)
            {
                index = Library.GetBoardIndex(x - 1, y + 1);
                if (emptyOrOpponent(board, index))
                {
                    validMoves.Add(index);
                }
            }
        }
        if (x != 3)
        {
            index = Library.GetBoardIndex(x + 1, y);
            if (emptyOrOpponent(board, index))
            {
                validMoves.Add(index);
            }

            // Up and Right
            if (y != 0)
            {
                index = Library.GetBoardIndex(x + 1, y - 1);
                if (emptyOrOpponent(board, index))
                {
                    validMoves.Add(index);
                }
            }

            // Down and Right
            if (y != 7)
            {
                index = Library.GetBoardIndex(x + 1, y + 1);
                if (emptyOrOpponent(board, index))
                {
                    validMoves.Add(index);
                }
            }
        }
        if (y != 0)
        {
            // Up
            index = Library.GetBoardIndex(x, y - 1);
            if (emptyOrOpponent(board, index))
            {
                validMoves.Add(index);
            }
        }
        if (y != 7)
        {
            // Down
            index = Library.GetBoardIndex(x, y + 1);
            if (emptyOrOpponent(board, index))
            {
                validMoves.Add(index);
            }
        }

        audioPlayer.SE_PickUp();
        return(validMoves);
    }
Exemple #3
0
    /*
     * A pawn can move forward one square unless the pawn has not yet moved in which case
     * it can move forward 2 squares.  A pawn captures diagonaly.
     */
    public List <int> AvailableMoves(List <GameObject> board, int currentPos)
    {
        int        x          = currentPos % 4;
        int        y          = currentPos / 4;
        List <int> validMoves = new List <int>();

        audioPlayer.SE_PickUp();

        // Movement logic
        if (y + direction <= 7 && y + direction >= 0)
        {
            // One move forward
            int index = Library.GetBoardIndex(x, y + 1 * direction);
            if (board[index].GetComponent <Square>().Piece == null)
            {
                validMoves.Add(index);

                // Two moves forward possible if never moved
                if (startingPosition)
                {
                    index = Library.GetBoardIndex(x, y + 2 * direction);
                    if (board[index].GetComponent <Square>().Piece == null)
                    {
                        validMoves.Add(index);
                    }
                    if ((y != 1 && team == Affiliation.Black) || (y != 6 && team == Affiliation.White))
                    {
                        // An important warning as logic does not test boundaries for second move
                        Debug.LogWarning("Pawn is not starting on second rank.  Is this intentional?");
                    }
                }
            }
        }

        // Capture logic
        if (x != 0 && y != 7 && y != 0)
        {
            int index = Library.GetBoardIndex(x - 1, y + 1 * direction);

            // if(an enemy piece is found)
            if (board[index].GetComponent <Square>().Piece != null && board[index].GetComponent <Square>().Piece.Team != team)
            {
                validMoves.Add(index);
            }
        }
        if (x != 3 && y != 7 && y != 0)
        {
            int index = Library.GetBoardIndex(x + 1, y + 1 * direction);

            // if(an enemy piece is found)
            if (board[index].GetComponent <Square>().Piece != null && board[index].GetComponent <Square>().Piece.Team != team)
            {
                validMoves.Add(index);
            }
        }

        // En Passant Logic
        if (enPassant > 0)
        {
            validMoves.Add(passantBoardIndex);
        }

        return(validMoves);
    }