private void HighlightCheckers(int x, int y, Chessman king) { Chessman[,] Chessmans = BoardManager.Instance.Chessmans; Chessman piece = null; if (!(x >= 0 && x <= 7 && y >= 0 && y <= 7)) { return; } int X = x; int Y = y; // Down if (y - 1 >= 0) { piece = BoardManager.Instance.Chessmans[x, y - 1]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x, y - 1); return; } } while (y-- > 0) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Rook) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Rook/Queen Down"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Right if (x + 1 <= 7) { piece = BoardManager.Instance.Chessmans[x + 1, y]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x + 1, y); return; } } while (x++ < 7) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Rook) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Rook/Queen Right"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Left if (x - 1 >= 0) { piece = BoardManager.Instance.Chessmans[x - 1, y]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x - 1, y); return; } } while (x-- > 0) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Rook) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Rook/Queen Left"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Up if (y + 1 <= 7) { piece = BoardManager.Instance.Chessmans[x, y + 1]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x, y + 1); return; } } while (y++ < 7) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Rook) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Rook/Queen Up"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Left to right Down Diagonal if (x + 1 <= 7 && y - 1 >= 0 && king.isWhite) { piece = BoardManager.Instance.Chessmans[x + 1, y - 1]; // If the cell is not empty and and the piece is from opponent and is Pawn if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(Pawn)) { SetTileRed(x + 1, y - 1); return; } } if (x + 1 <= 7 && y - 1 >= 0) { piece = BoardManager.Instance.Chessmans[x + 1, y - 1]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x + 1, y - 1); return; } } while (x++ < 7 && y-- > 0) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Bishup) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Bishup/Queen LR Down"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Left to right Up Diagonal if (x + 1 <= 7 && y + 1 <= 7 && !king.isWhite) { piece = BoardManager.Instance.Chessmans[x + 1, y + 1]; // If the cell is not empty and and the piece is from opponent and is Pawn if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(Pawn)) { SetTileRed(x + 1, y + 1); return; } } if (x + 1 <= 7 && y + 1 <= 7) { piece = BoardManager.Instance.Chessmans[x + 1, y + 1]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x + 1, y + 1); return; } } while (x++ < 7 && y++ < 7) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Bishup) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Bishup/Queen LR Up"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Right to left Down Diagonal if (x - 1 >= 0 && y - 1 >= 0 && king.isWhite) { piece = BoardManager.Instance.Chessmans[x - 1, y - 1]; // If the cell is not empty and and the piece is from opponent and is Pawn if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(Pawn)) { SetTileRed(x - 1, y - 1); return; } } if (x - 1 >= 0 && y - 1 >= 0) { piece = BoardManager.Instance.Chessmans[x - 1, y - 1]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x - 1, y - 1); return; } } while (x-- > 0 && y-- > 0) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Bishup) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Bishup/Queen RL Down"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Right to left Up Diagonal if (x - 1 >= 0 && y + 1 <= 7 && !king.isWhite) { piece = BoardManager.Instance.Chessmans[x - 1, y + 1]; // If the cell is not empty and and the piece is from opponent and is Pawn if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(Pawn)) { SetTileRed(x - 1, y + 1); return; } } if (x - 1 >= 0 && y + 1 <= 7) { piece = BoardManager.Instance.Chessmans[x - 1, y + 1]; // If the cell is not empty and and the piece is from opponent and is King if (piece != null && piece.isWhite != king.isWhite && piece.GetType() == typeof(King)) { SetTileRed(x - 1, y + 1); return; } } while (x-- > 0 && y++ < 7) { piece = BoardManager.Instance.Chessmans[x, y]; // If the cell is empty if (piece == null) { continue; } // If the piece is from same team else if (piece.isWhite == king.isWhite) { break; } // Else if the piece is from opponent team if (piece.GetType() == typeof(Bishup) || piece.GetType() == typeof(Queen)) { Debug.Log("Threat from Bishup/Queen RL Up"); SetTileRed(x, y); return; } break; } x = X; y = Y; // Knight Threats // DownLeft if (king.KnightThreat(x - 1, y - 2)) { SetTileRed(x - 1, y - 2); return; } // DownRight if (king.KnightThreat(x + 1, y - 2)) { SetTileRed(x + 1, y - 2); return; } // RightDown if (king.KnightThreat(x + 2, y - 1)) { SetTileRed(x + 2, y - 1); return; } // RightUp if (king.KnightThreat(x + 2, y + 1)) { SetTileRed(x + 2, y + 1); return; } // LeftDown if (king.KnightThreat(x - 2, y - 1)) { SetTileRed(x - 2, y - 1); return; } // LeftUp if (king.KnightThreat(x - 2, y + 1)) { SetTileRed(x - 2, y + 1); return; } // UpLeft if (king.KnightThreat(x - 1, y + 2)) { SetTileRed(x - 1, y + 2); return; } // UpRight if (king.KnightThreat(x + 1, y + 2)) { SetTileRed(x + 1, y + 2); return; } }