Assets/Scripts/Pieces/PawnPiece.cs
/// <summary>
/// pawns can move 1unit in front or 2 if never moved
/// can also eat 1 unit in diagonal to the front and apply the en passant
/// the main restrictions are:
/// The positions of the pieces (must be inside the board)
/// can not go into a own piece
/// </summary>
/// <returns>bidemensional boolean array with the possible moves</returns>
pawns can move 1unit in front or 2 if never moved
can also eat 1 unit in diagonal to the front and apply the en passant
the main restrictions are:
The positions of the pieces (must be inside the board)
can not go into a own piece
pawns can move 1unit in front or 2 if never moved can also eat 1 unit in diagonal to the front and apply the en passant the main restrictions are : The positions of the pieces ( must be inside the board ) can not go into a own piece
public override bool[,] PossibleMove(BoardManager instance) {
        bool[,] possibleMovesMap = new bool[8, 8];
        ChessPiece enemyPiece, enemyPiece2;
        int[] e = instance.EnPassantMove;
        if (isWhite)
        {
            if (CurrentX != 0 && CurrentZ != 7)
            {
                if (e[0] == CurrentX - 1 && e[1] == CurrentZ + 1) 
                {
                    possibleMovesMap[CurrentX - 1, CurrentZ + 1] = true;
                }
                enemyPiece = instance.chessPieces[CurrentX - 1, CurrentZ + 1];
                if (enemyPiece != null && !enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX - 1, CurrentZ + 1] = true;
                }
            }
            if (CurrentX != 7 && CurrentZ != 7)
            {
                if (e[0] == CurrentX + 1 && e[1] == CurrentZ + 1)
                {
                    possibleMovesMap[CurrentX + 1, CurrentZ + 1] = true;
                }
                enemyPiece = instance.chessPieces[CurrentX + 1, CurrentZ + 1];
                if (enemyPiece != null && !enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX + 1, CurrentZ + 1] = true;
                }
            }
            if(CurrentZ != 7)
            {
                enemyPiece = instance.chessPieces[CurrentX, CurrentZ + 1];
                if (enemyPiece == null)
                {
                    possibleMovesMap[CurrentX, CurrentZ + 1] = true;
                }
                if (CurrentZ == 1)
                {
                    enemyPiece = instance.chessPieces[CurrentX, CurrentZ + 1];
                    enemyPiece2 = instance.chessPieces[CurrentX, CurrentZ + 2];
                    if (enemyPiece == null && enemyPiece2 == null)
                    {
                        possibleMovesMap[CurrentX, CurrentZ + 2] = true;
                    }
                }
            }
        }
        else
        {
            if (CurrentX != 7 && CurrentZ != 0)
            {
                if (e[0] == CurrentX + 1 && e[1] == CurrentZ - 1)
                {
                    possibleMovesMap[CurrentX + 1, CurrentZ - 1] = true;
                }
                enemyPiece = instance.chessPieces[CurrentX + 1, CurrentZ - 1];
                if (enemyPiece != null && enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX + 1, CurrentZ - 1] = true;
                }
            }
            if (CurrentX != 0 && CurrentZ != 7)
            {
                if (e[0] == CurrentX - 1 && e[1] == CurrentZ - 1)
                {
                    possibleMovesMap[CurrentX -  1, CurrentZ - 1] = true;
                }
                enemyPiece = instance.chessPieces[CurrentX - 1, CurrentZ - 1];
                if (enemyPiece != null && enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX - 1, CurrentZ - 1] = true;
                }
            }
            if (CurrentZ != 0)
            {
                enemyPiece = instance.chessPieces[CurrentX, CurrentZ - 1];
                if (enemyPiece == null)
                {
                    possibleMovesMap[CurrentX, CurrentZ - 1] = true;
                } 
                if (CurrentZ == 6)
                {
                    enemyPiece = instance.chessPieces[CurrentX, CurrentZ - 1];
                    enemyPiece2 = instance.chessPieces[CurrentX, CurrentZ - 2];
                    if (enemyPiece == null && enemyPiece2 == null)
                    {
                        possibleMovesMap[CurrentX, CurrentZ - 2] = true;
                    }
                }
            }
        }
        return possibleMovesMap;
    }
public override bool [ , ] PossibleMove ( BoardManager instance ) { bool [ , ] possibleMovesMap = new bool [ 8 , 8 ] ; ChessPiece enemyPiece , enemyPiece2 ; int [ ] e = instance . EnPassantMove ; if ( isWhite ) { if ( CurrentX != 0 && CurrentZ != 7 ) { if ( e [ 0 ] == CurrentX - 1 && e [ 1 ] == CurrentZ + 1 ) { possibleMovesMap [ CurrentX - 1 , CurrentZ + 1 ] = true ; } enemyPiece = instance . chessPieces [ CurrentX - 1 , CurrentZ + 1 ] ; if ( enemyPiece != null && ! enemyPiece . isWhite ) { possibleMovesMap [ CurrentX - 1 , CurrentZ + 1 ] = true ; } } if ( CurrentX != 7 && CurrentZ != 7 ) { if ( e [ 0 ] == CurrentX + 1 && e [ 1 ] == CurrentZ + 1 ) { possibleMovesMap [ CurrentX + 1 , CurrentZ + 1 ] = true ; } enemyPiece = instance . chessPieces [ CurrentX + 1 , CurrentZ + 1 ] ; if ( enemyPiece != null && ! enemyPiece . isWhite ) { possibleMovesMap [ CurrentX + 1 , CurrentZ + 1 ] = true ; } } if ( CurrentZ != 7 ) { enemyPiece = instance . chessPieces [ CurrentX , CurrentZ + 1 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX , CurrentZ + 1 ] = true ; } if ( CurrentZ == 1 ) { enemyPiece = instance . chessPieces [ CurrentX , CurrentZ + 1 ] ; enemyPiece2 = instance . chessPieces [ CurrentX , CurrentZ + 2 ] ; if ( enemyPiece == null && enemyPiece2 == null ) { possibleMovesMap [ CurrentX , CurrentZ + 2 ] = true ; } } } } else { if ( CurrentX != 7 && CurrentZ != 0 ) { if ( e [ 0 ] == CurrentX + 1 && e [ 1 ] == CurrentZ - 1 ) { possibleMovesMap [ CurrentX + 1 , CurrentZ - 1 ] = true ; } enemyPiece = instance . chessPieces [ CurrentX + 1 , CurrentZ - 1 ] ; if ( enemyPiece != null && enemyPiece . isWhite ) { possibleMovesMap [ CurrentX + 1 , CurrentZ - 1 ] = true ; } } if ( CurrentX != 0 && CurrentZ != 7 ) { if ( e [ 0 ] == CurrentX - 1 && e [ 1 ] == CurrentZ - 1 ) { possibleMovesMap [ CurrentX - 1 , CurrentZ - 1 ] = true ; } enemyPiece = instance . chessPieces [ CurrentX - 1 , CurrentZ - 1 ] ; if ( enemyPiece != null && enemyPiece . isWhite ) { possibleMovesMap [ CurrentX - 1 , CurrentZ - 1 ] = true ; } } if ( CurrentZ != 0 ) { enemyPiece = instance . chessPieces [ CurrentX , CurrentZ - 1 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX , CurrentZ - 1 ] = true ; } if ( CurrentZ == 6 ) { enemyPiece = instance . chessPieces [ CurrentX , CurrentZ - 1 ] ; enemyPiece2 = instance . chessPieces [ CurrentX , CurrentZ - 2 ] ; if ( enemyPiece == null && enemyPiece2 == null ) { possibleMovesMap [ CurrentX , CurrentZ - 2 ] = true ; } } } } return possibleMovesMap ; }
pawns can move 1unit in front or 2 if never moved
can also eat 1 unit in diagonal to the front and apply the en passant
the main restrictions are:
The positions of the pieces (must be inside the board)
can not go into a own piece
pawns can move 1unit in front or 2 if never moved can also eat 1 unit in diagonal to the front and apply the en passant the main restrictions are : The positions of the pieces ( must be inside the board ) can not go into a own piece
//check en passant moves //White Turn //Diagonals //Diagonal left //CHeck if En Passant Move is allowed //Diagonal right //CHeck if En Passant Move is allowed //1 forward //2 forward //in the begining //Black Turn //Diagonals //Diagonal right //CHeck if En Passant Move is allowed //Diagonal left //Check if En Passant Move is allowed //1 forward //2 forward //in the begining
bidemensional boolean array with the possible moves
bidemensional boolean array with the possible moves
instance
BoardManager