Assets/Scripts/Pieces/HorsePiece.cs
/// <summary>
/// horses can move in L shape moves
/// 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>
horses can move in L shape moves
the main restrictions are:
The positions of the pieces (must be inside the board)
can not go into a own piece
horses can move in L shape moves 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;
        if (CurrentX - 2 >= 0 && CurrentZ + 1 <= 7)
        {
            enemyPiece = instance.chessPieces[CurrentX - 2, CurrentZ + 1];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX - 2, CurrentZ + 1] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX - 2, CurrentZ + 1] = true;
                }
            }
        }
        if (CurrentX - 1 >= 0 && CurrentZ + 2 <= 7)
        {
            enemyPiece = instance.chessPieces[CurrentX - 1, CurrentZ + 2];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX - 1, CurrentZ + 2] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX - 1, CurrentZ + 2] = true;
                }
            }
        }
        if (CurrentX - 2 >= 0 && CurrentZ - 1 >= 0)
        {
            enemyPiece = instance.chessPieces[CurrentX - 2, CurrentZ - 1];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX - 2, CurrentZ - 1] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX - 2, CurrentZ - 1] = true;
                }
            }
        }
        if (CurrentX - 1 >= 0 && CurrentZ - 2 >= 0)
        {
            enemyPiece = instance.chessPieces[CurrentX - 1, CurrentZ - 2];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX - 1, CurrentZ - 2] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX - 1, CurrentZ - 2] = true;
                }
            }
        }
        if (CurrentX + 2 <= 7 && CurrentZ + 1 <= 7)
        {
            enemyPiece = instance.chessPieces[CurrentX + 2, CurrentZ + 1];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX + 2, CurrentZ + 1] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX + 2, CurrentZ + 1] = true;
                }
            }
        }
        if (CurrentX + 1 <= 7 && CurrentZ + 2 <= 7)
        {
            enemyPiece = instance.chessPieces[CurrentX + 1, CurrentZ + 2];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX + 1, CurrentZ + 2] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX + 1, CurrentZ + 2] = true;
                }
            }
        }
        if (CurrentX + 2 <= 7 && CurrentZ - 1 > 0)
        {
            enemyPiece = instance.chessPieces[CurrentX + 2, CurrentZ - 1];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX + 2, CurrentZ - 1] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX + 2, CurrentZ - 1] = true;
                }
            }
        }
        if (CurrentX + 1 <= 7 && CurrentZ - 2 > 0)
        {
            enemyPiece = instance.chessPieces[CurrentX + 1, CurrentZ - 2];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX + 1, CurrentZ - 2] = true;
            }
            else
            {
                if (isWhite != enemyPiece.isWhite)
                {
                    possibleMovesMap[CurrentX + 1, CurrentZ - 2] = true;
                }
            }
        }
        return possibleMovesMap;
    }
public override bool [ , ] PossibleMove ( BoardManager instance ) { bool [ , ] possibleMovesMap = new bool [ 8 , 8 ] ; ChessPiece enemyPiece ; if ( CurrentX - 2 >= 0 && CurrentZ + 1 <= 7 ) { enemyPiece = instance . chessPieces [ CurrentX - 2 , CurrentZ + 1 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX - 2 , CurrentZ + 1 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX - 2 , CurrentZ + 1 ] = true ; } } } if ( CurrentX - 1 >= 0 && CurrentZ + 2 <= 7 ) { enemyPiece = instance . chessPieces [ CurrentX - 1 , CurrentZ + 2 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX - 1 , CurrentZ + 2 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX - 1 , CurrentZ + 2 ] = true ; } } } if ( CurrentX - 2 >= 0 && CurrentZ - 1 >= 0 ) { enemyPiece = instance . chessPieces [ CurrentX - 2 , CurrentZ - 1 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX - 2 , CurrentZ - 1 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX - 2 , CurrentZ - 1 ] = true ; } } } if ( CurrentX - 1 >= 0 && CurrentZ - 2 >= 0 ) { enemyPiece = instance . chessPieces [ CurrentX - 1 , CurrentZ - 2 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX - 1 , CurrentZ - 2 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX - 1 , CurrentZ - 2 ] = true ; } } } if ( CurrentX + 2 <= 7 && CurrentZ + 1 <= 7 ) { enemyPiece = instance . chessPieces [ CurrentX + 2 , CurrentZ + 1 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX + 2 , CurrentZ + 1 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX + 2 , CurrentZ + 1 ] = true ; } } } if ( CurrentX + 1 <= 7 && CurrentZ + 2 <= 7 ) { enemyPiece = instance . chessPieces [ CurrentX + 1 , CurrentZ + 2 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX + 1 , CurrentZ + 2 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX + 1 , CurrentZ + 2 ] = true ; } } } if ( CurrentX + 2 <= 7 && CurrentZ - 1 > 0 ) { enemyPiece = instance . chessPieces [ CurrentX + 2 , CurrentZ - 1 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX + 2 , CurrentZ - 1 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX + 2 , CurrentZ - 1 ] = true ; } } } if ( CurrentX + 1 <= 7 && CurrentZ - 2 > 0 ) { enemyPiece = instance . chessPieces [ CurrentX + 1 , CurrentZ - 2 ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX + 1 , CurrentZ - 2 ] = true ; } else { if ( isWhite != enemyPiece . isWhite ) { possibleMovesMap [ CurrentX + 1 , CurrentZ - 2 ] = true ; } } } return possibleMovesMap ; }
horses can move in L shape moves
the main restrictions are:
The positions of the pieces (must be inside the board)
can not go into a own piece
horses can move in L shape moves the main restrictions are : The positions of the pieces ( must be inside the board ) can not go into a own piece
//diagonal leftup+left //diagonal leftup+up //diagonal leftdown+left //diagonal leftdown+down //diagonal rightup+right //diagonal rightup+up //diagonal rightdown+right //diagonal rightdown+down
bidemensional boolean array with the possible moves
bidemensional boolean array with the possible moves
instance
BoardManager