Assets/Scripts/Pieces/QueenPiece.cs
/// <summary>
/// queens can move in diagonal or straigth as much as she can (bishop + tower behavior)
/// the main restrictions are:
/// The positions of the pieces (must be inside the board)
/// can not go into a own piece
/// can not jumo over pieces
/// </summary>
/// <returns>bidemensional boolean array with the possible moves</returns>
queens can move in diagonal or straigth as much as she can (bishop + tower behavior)
the main restrictions are:
The positions of the pieces (must be inside the board)
can not go into a own piece
can not jumo over pieces
queens can move in diagonal or straigth as much as she can ( bishop + tower behavior ) the main restrictions are : The positions of the pieces ( must be inside the board ) can not go into a own piece can not jumo over pieces
public override bool[,] PossibleMove(BoardManager instance)
    {
        bool[,] possibleMovesMap = new bool[8, 8];
        ChessPiece enemyPiece;
        int amountOfMovesInXDirection;
        amountOfMovesInXDirection = CurrentZ;
        while (true)
        {
            amountOfMovesInXDirection++;
            if (amountOfMovesInXDirection >= 8)
            {
                break;
            }
            enemyPiece = instance.chessPieces[CurrentX, amountOfMovesInXDirection];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX, amountOfMovesInXDirection] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[CurrentX, amountOfMovesInXDirection] = true;
                }
                break;
            }
        }
        amountOfMovesInXDirection = CurrentZ;
        while (true)
        {
            amountOfMovesInXDirection--;
            if (amountOfMovesInXDirection < 0)
            {
                break;
            }
            enemyPiece = instance.chessPieces[CurrentX, amountOfMovesInXDirection];
            if (enemyPiece == null)
            {
                possibleMovesMap[CurrentX, amountOfMovesInXDirection] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[CurrentX, amountOfMovesInXDirection] = true;
                }
                break;
            }
        }
        amountOfMovesInXDirection = CurrentX;
        while (true)
        {
            amountOfMovesInXDirection++;
            if (amountOfMovesInXDirection >= 8)
            {
                break;
            }
            enemyPiece = instance.chessPieces[amountOfMovesInXDirection, CurrentZ];
            if (enemyPiece == null)
            {
                possibleMovesMap[amountOfMovesInXDirection, CurrentZ] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[amountOfMovesInXDirection, CurrentZ] = true;
                }
                break;
            }
        }
        amountOfMovesInXDirection = CurrentX;
        while (true)
        {
            amountOfMovesInXDirection--;
            if (amountOfMovesInXDirection < 0)
            {
                break;
            }
            enemyPiece = instance.chessPieces[amountOfMovesInXDirection, CurrentZ];
            if (enemyPiece == null)
            {
                possibleMovesMap[amountOfMovesInXDirection, CurrentZ] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[amountOfMovesInXDirection, CurrentZ] = true;
                }
                break;
            }
        }
        int posX;
        int posZ;
        posX = CurrentX;
        posZ = CurrentZ;
        per right diagonal
        while (posX < 7 && posZ < 7)
        {
            posX++;
            posZ++;
            enemyPiece = instance.chessPieces[posX, posZ];
            if (enemyPiece == null)
            {
                possibleMovesMap[posX, posZ] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[posX, posZ] = true;
                }
                break;
            }
        }
        posX = CurrentX;
        posZ = CurrentZ;
        per left diagonal
        while (posX > 0 && posZ < 7)
        {
            posX--;
            posZ++;
            enemyPiece = instance.chessPieces[posX, posZ];
            if (enemyPiece == null)
            {
                possibleMovesMap[posX, posZ] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[posX, posZ] = true;
                }
                break;
            }
        }
        posX = CurrentX;
        posZ = CurrentZ;
        while (posX > 0 && posZ > 0)
        {
            posX--;
            posZ--;
            enemyPiece = instance.chessPieces[posX, posZ];
            if (enemyPiece == null)
            {
                possibleMovesMap[posX, posZ] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[posX, posZ] = true;
                }
                break;
            }
        }
        posX = CurrentX;
        posZ = CurrentZ;
        while (posX < 7 && posZ > 0)
        {
            posX++;
            posZ--;
            enemyPiece = instance.chessPieces[posX, posZ];
            if (enemyPiece == null)
            {
                possibleMovesMap[posX, posZ] = true;
            }
            else
            {
                if (enemyPiece.isWhite != isWhite)
                {
                    possibleMovesMap[posX, posZ] = true;
                }
                break;
            }
        }
        return possibleMovesMap;
    }
public override bool [ , ] PossibleMove ( BoardManager instance ) { bool [ , ] possibleMovesMap = new bool [ 8 , 8 ] ; ChessPiece enemyPiece ; int amountOfMovesInXDirection ; amountOfMovesInXDirection = CurrentZ ; while ( true ) { amountOfMovesInXDirection ++ ; if ( amountOfMovesInXDirection >= 8 ) { break ; } enemyPiece = instance . chessPieces [ CurrentX , amountOfMovesInXDirection ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX , amountOfMovesInXDirection ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ CurrentX , amountOfMovesInXDirection ] = true ; } break ; } } amountOfMovesInXDirection = CurrentZ ; while ( true ) { amountOfMovesInXDirection -- ; if ( amountOfMovesInXDirection < 0 ) { break ; } enemyPiece = instance . chessPieces [ CurrentX , amountOfMovesInXDirection ] ; if ( enemyPiece == null ) { possibleMovesMap [ CurrentX , amountOfMovesInXDirection ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ CurrentX , amountOfMovesInXDirection ] = true ; } break ; } } amountOfMovesInXDirection = CurrentX ; while ( true ) { amountOfMovesInXDirection ++ ; if ( amountOfMovesInXDirection >= 8 ) { break ; } enemyPiece = instance . chessPieces [ amountOfMovesInXDirection , CurrentZ ] ; if ( enemyPiece == null ) { possibleMovesMap [ amountOfMovesInXDirection , CurrentZ ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ amountOfMovesInXDirection , CurrentZ ] = true ; } break ; } } amountOfMovesInXDirection = CurrentX ; while ( true ) { amountOfMovesInXDirection -- ; if ( amountOfMovesInXDirection < 0 ) { break ; } enemyPiece = instance . chessPieces [ amountOfMovesInXDirection , CurrentZ ] ; if ( enemyPiece == null ) { possibleMovesMap [ amountOfMovesInXDirection , CurrentZ ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ amountOfMovesInXDirection , CurrentZ ] = true ; } break ; } } int posX ; int posZ ; posX = CurrentX ; posZ = CurrentZ ; while ( posX < 7 && posZ < 7 ) { posX ++ ; posZ ++ ; enemyPiece = instance . chessPieces [ posX , posZ ] ; if ( enemyPiece == null ) { possibleMovesMap [ posX , posZ ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ posX , posZ ] = true ; } break ; } } posX = CurrentX ; posZ = CurrentZ ; while ( posX > 0 && posZ < 7 ) { posX -- ; posZ ++ ; enemyPiece = instance . chessPieces [ posX , posZ ] ; if ( enemyPiece == null ) { possibleMovesMap [ posX , posZ ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ posX , posZ ] = true ; } break ; } } posX = CurrentX ; posZ = CurrentZ ; while ( posX > 0 && posZ > 0 ) { posX -- ; posZ -- ; enemyPiece = instance . chessPieces [ posX , posZ ] ; if ( enemyPiece == null ) { possibleMovesMap [ posX , posZ ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ posX , posZ ] = true ; } break ; } } posX = CurrentX ; posZ = CurrentZ ; while ( posX < 7 && posZ > 0 ) { posX ++ ; posZ -- ; enemyPiece = instance . chessPieces [ posX , posZ ] ; if ( enemyPiece == null ) { possibleMovesMap [ posX , posZ ] = true ; } else { if ( enemyPiece . isWhite != isWhite ) { possibleMovesMap [ posX , posZ ] = true ; } break ; } } return possibleMovesMap ; }
queens can move in diagonal or straigth as much as she can (bishop + tower behavior)
the main restrictions are:
The positions of the pieces (must be inside the board)
can not go into a own piece
can not jumo over pieces
queens can move in diagonal or straigth as much as she can ( bishop + tower behavior ) the main restrictions are : The positions of the pieces ( must be inside the board ) can not go into a own piece can not jumo over pieces
//up //if it is an enemy piece //down //if it is an enemy piece //right //if it is an enemy piece //left //if it is an enemy piece //bishop part //diagonals //upper right diagonal //upper left diagonal //lower left diagonal //lower right diagonal
bidemensional boolean array with the possible moves
bidemensional boolean array with the possible moves
instance
BoardManager