public static List <Position> GetAvailableMoves(GameObject piece) { // List to store all available moves List <Position> availableMoves = new List <Position>(); // Get all the properties that we need PieceProperties pieceProp = piece.GetComponent <PieceProperties>(); int team = pieceProp.team; int row = pieceProp.row; int col = pieceProp.column; PieceProperties.Type type = pieceProp.type; if (PieceProperties.Type.Pawn == type) { int dir = 0; int dist = 1; if (team == 0) { dir = 1; if (row == 1) { dist = 2; } ; } else if (team == 1) { dir = -1; if (row == 6) { dist = 2; } } // Moving forwards GameObject otherPiece; for (int i = 1; i <= dist; i++) { // Stop right before any piece otherPiece = chessboardManager.FindPiece(row + i * dist, col); if (otherPiece != null) { break; } availableMoves.Add(new Position(row + dir * i, col)); } // Moving diagonal if there is an enemy piece otherPiece = chessboardManager.FindPiece(row + 1, col + 1); if (otherPiece != null && otherPiece.GetComponent <PieceProperties>().team != team) { availableMoves.Add(new Position(row + 1, col + 1)); } otherPiece = chessboardManager.FindPiece(row + 1, col - 1); if (otherPiece != null && otherPiece.GetComponent <PieceProperties>().team != team) { availableMoves.Add(new Position(row + 1, col - 1)); } } else if (PieceProperties.Type.Rook == type) { AddOrthogonal(availableMoves, row, col, team, 8); } else if (PieceProperties.Type.Bishop == type) { AddDiagonal(availableMoves, row, col, team, 8); } else if (PieceProperties.Type.Queen == type) { AddOrthogonal(availableMoves, row, col, team, 8); AddDiagonal(availableMoves, row, col, team, 8); } else if (PieceProperties.Type.King == type) { AddOrthogonal(availableMoves, row, col, team, 1); AddDiagonal(availableMoves, row, col, team, 1); } else if (PieceProperties.Type.Knight == type) { AddL(availableMoves, row, col, team); } // Glow all available moves FindAndGlowAll(availableMoves); return(availableMoves); }