Assets/Scripts/BoardManager.cs
/// <summary>
/// Actually moves a certain piece chessPieces[column, line] in a particular position (column;line)
/// to (to_Column, toLine)
/// Also checks for special moves
/// </summary>
Actually moves a certain piece chessPieces[column, line] in a particular position (column;line)
to (to_Column, toLine)
Also checks for special moves
Actually moves a certain piece chessPieces [ column line ] in a particular position ( column ; line ) to ( to_Column toLine ) Also checks for special moves
public void MovePiece(int column, int line, int to_Column, int toLine)
    {
        if (allowedMoves[to_Column, toLine]) {
            ChessPiece enemyPiece = chessPieces[to_Column, toLine];
            if (enemyPiece != null)
            {
                if (enemyPiece.GetType() == typeof(KingPiece))
                {
                    FinishGame(false);
                    return;
                }
                activeChessPieceModel.Remove(enemyPiece.gameObject);
                Destroy(enemyPiece.gameObject);
            }
            if (to_Column == EnPassantMove[0] && toLine == EnPassantMove[1])
            {
                if (isWhiteTurn)
                {
                    enemyPiece = chessPieces[to_Column, toLine - 1];
                }
                else
                {
                    enemyPiece = chessPieces[to_Column, toLine + 1];
                }
                activeChessPieceModel.Remove(enemyPiece.gameObject);
                Destroy(enemyPiece.gameObject); 
            }
            EnPassantMove[0] = -1;
            EnPassantMove[1] = -1;
            if (activeChessPiece.GetType() == typeof(PawnPiece))
            {
                if (toLine == 7)
                {
                    activeChessPieceModel.Remove(activeChessPiece.gameObject);
                    Destroy(activeChessPiece.gameObject);
                    SpawnPiece(to_Column, toLine, "Q");
                    activeChessPiece = chessPieces[to_Column, toLine];
                }
                if (toLine == 0)
                {
                    activeChessPieceModel.Remove(activeChessPiece.gameObject);
                    Destroy(activeChessPiece.gameObject);
                    SpawnPiece(to_Column, toLine, "q");
                    activeChessPiece = chessPieces[to_Column, toLine];
                }
                if (activeChessPiece.CurrentZ == 1 && toLine == 3)
                {
                    EnPassantMove[0] = to_Column;
                    EnPassantMove[1] = toLine - 1;
                }
                else if (activeChessPiece.CurrentZ == 6 && toLine == 4)
                {
                    EnPassantMove[0] = to_Column;
                    EnPassantMove[1] = toLine + 1;
                }
            }
            if(activeChessPiece.GetType() == typeof(KingPiece))
            {
                if(to_Column == column - 3)
                {
                    ChessPiece rook = chessPieces[column - 4, line];
                    chessPieces[column - 4, line] = null;
                    rook.setPosition(column - 4 + 2, line);
                    rook.transform.position = GetTileCenter(column - 4 + 2, line);
                    chessPieces[column - 4 + 2, toLine] = rook;
                }
                else if(to_Column == column + 2)
                {
                    ChessPiece rook = chessPieces[column + 3, line];
                    chessPieces[column + 3, line] = null;
                    rook.setPosition(column + 3 - 2, line);
                    rook.transform.position = GetTileCenter(column + 3 - 2, line);
                    chessPieces[column +3-2, line] = rook;
                }
            }
            chessPieces[activeChessPiece.CurrentX, activeChessPiece.CurrentZ] = null;
            activeChessPiece.setPosition(to_Column, toLine);
            activeChessPiece.transform.position = GetTileCenter(to_Column, toLine);
            chessPieces[to_Column, toLine] = activeChessPiece;
            isWhiteTurn = !isWhiteTurn;
        }
        UnselectPiece();
    }
public void MovePiece ( int column , int line , int to_Column , int toLine ) { if ( allowedMoves [ to_Column , toLine ] ) { ChessPiece enemyPiece = chessPieces [ to_Column , toLine ] ; if ( enemyPiece != null ) { if ( enemyPiece . GetType ( ) == typeof ( KingPiece ) ) { FinishGame ( false ) ; return ; } activeChessPieceModel . Remove ( enemyPiece . gameObject ) ; Destroy ( enemyPiece . gameObject ) ; } if ( to_Column == EnPassantMove [ 0 ] && toLine == EnPassantMove [ 1 ] ) { if ( isWhiteTurn ) { enemyPiece = chessPieces [ to_Column , toLine - 1 ] ; } else { enemyPiece = chessPieces [ to_Column , toLine + 1 ] ; } activeChessPieceModel . Remove ( enemyPiece . gameObject ) ; Destroy ( enemyPiece . gameObject ) ; } EnPassantMove [ 0 ] = - 1 ; EnPassantMove [ 1 ] = - 1 ; if ( activeChessPiece . GetType ( ) == typeof ( PawnPiece ) ) { if ( toLine == 7 ) { activeChessPieceModel . Remove ( activeChessPiece . gameObject ) ; Destroy ( activeChessPiece . gameObject ) ; SpawnPiece ( to_Column , toLine , " " ) ; activeChessPiece = chessPieces [ to_Column , toLine ] ; } if ( toLine == 0 ) { activeChessPieceModel . Remove ( activeChessPiece . gameObject ) ; Destroy ( activeChessPiece . gameObject ) ; SpawnPiece ( to_Column , toLine , " " ) ; activeChessPiece = chessPieces [ to_Column , toLine ] ; } if ( activeChessPiece . CurrentZ == 1 && toLine == 3 ) { EnPassantMove [ 0 ] = to_Column ; EnPassantMove [ 1 ] = toLine - 1 ; } else if ( activeChessPiece . CurrentZ == 6 && toLine == 4 ) { EnPassantMove [ 0 ] = to_Column ; EnPassantMove [ 1 ] = toLine + 1 ; } } if ( activeChessPiece . GetType ( ) == typeof ( KingPiece ) ) { if ( to_Column == column - 3 ) { ChessPiece rook = chessPieces [ column - 4 , line ] ; chessPieces [ column - 4 , line ] = null ; rook . setPosition ( column - 4 + 2 , line ) ; rook . transform . position = GetTileCenter ( column - 4 + 2 , line ) ; chessPieces [ column - 4 + 2 , toLine ] = rook ; } else if ( to_Column == column + 2 ) { ChessPiece rook = chessPieces [ column + 3 , line ] ; chessPieces [ column + 3 , line ] = null ; rook . setPosition ( column + 3 - 2 , line ) ; rook . transform . position = GetTileCenter ( column + 3 - 2 , line ) ; chessPieces [ column + 3 - 2 , line ] = rook ; } } chessPieces [ activeChessPiece . CurrentX , activeChessPiece . CurrentZ ] = null ; activeChessPiece . setPosition ( to_Column , toLine ) ; activeChessPiece . transform . position = GetTileCenter ( to_Column , toLine ) ; chessPieces [ to_Column , toLine ] = activeChessPiece ; isWhiteTurn = ! isWhiteTurn ; } UnselectPiece ( ) ; }
Actually moves a certain piece chessPieces[column, line] in a particular position (column;line)
to (to_Column, toLine)
Also checks for special moves
Actually moves a certain piece chessPieces [ column line ] in a particular position ( column ; line ) to ( to_Column toLine ) Also checks for special moves
//capture a piece //check if its the king? i dont think ill need it //gg //actually did the 2 tiles movement //remove black pawn->is white Turn //remove white pawn->is black Turn //record possible en passant moves //trnaform pawn into other piece //white team //black team //if movement is 2 tiles //if movement is 2 tiles //castling //only need to change rooks positioning here //king's will change after this if either way //change Turn
column
int
line
int
to_Column
int
toLine
int