public static Dictionary <int, Dictionary <int, ChessPiece> > GetScenario(Move testMove) { var scenario = HelperMaths.DeepClone(Layout); scenario[testMove.Destination.Item1][testMove.Destination.Item2] = scenario[testMove.Origin.Item1][testMove.Origin.Item2]; scenario[testMove.Origin.Item1][testMove.Origin.Item2] = null; return(scenario); }
public static bool HorizontalThreatCheck(int kingX, int kingY, Dictionary <int, Dictionary <int, ChessPiece> > scenario, PieceColor enemy) { for (int i = 1; i <= 8; i++) { if (HelperMaths.IsInRange(kingY + i, 0, 7)) { if (scenario[kingX][kingY + i] != null) { if (scenario[kingX][kingY + i].ToString() == enemy.ToString() + PieceType.Rook.ToString() || scenario[kingX][kingY + i].ToString() == enemy.ToString() + PieceType.Queen.ToString()) { return(true); } else { break; } } } else { break; } } for (int i = 1; i <= 8; i++) { if (HelperMaths.IsInRange(kingY - i, 0, 7)) { if (scenario[kingX][kingY - i] != null) { if (scenario[kingX][kingY - i].ToString() == enemy.ToString() + PieceType.Rook.ToString() || scenario[kingX][kingY - i].ToString() == enemy.ToString() + PieceType.Queen.ToString()) { return(true); } else { break; } } } else { break; } } return(false); }
//----------------------------------------------------------------- // King check functions //----------------------------------------------------------------- public static bool EnemyPawnCheck(int kingX, int kingY, Dictionary <int, Dictionary <int, ChessPiece> > scenario, PieceColor enemy) { if (enemy == PieceColor.Black) { if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7)) { if (scenario[kingX - 1][kingY - 1]?.ToString() == enemy.ToString() + "Pawn") { return(true); } } if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7)) { if (scenario[kingX - 1][kingY + 1]?.ToString() == enemy.ToString() + "Pawn") { return(true); } } } if (enemy == PieceColor.White) { if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7)) { if (scenario[kingX + 1][kingY - 1]?.ToString() == enemy.ToString() + "Pawn") { return(true); } } if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7)) { if (scenario[kingX + 1][kingY + 1]?.ToString() == enemy.ToString() + "Pawn") { return(true); } } } return(false); }
private static bool TestKingChecks(Dictionary <int, Dictionary <int, ChessPiece> > scenario) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (scenario[i][j]?.ToString() == GameState.PlayerTurn.ToString() + "King") { PieceColor enemy = GameState.PlayerTurn == PieceColor.Black ? enemy = PieceColor.White : enemy = PieceColor.Black; if (HelperMaths.EnemyPawnCheck(i, j, scenario, enemy) || HelperMaths.HorizontalThreatCheck(i, j, scenario, enemy) || HelperMaths.DiagonalThreatCheck(i, j, scenario, enemy) || HelperMaths.VerticalThreatCheck(i, j, scenario, enemy) || HelperMaths.HorseThreatCheck(i, j, scenario, enemy)) { return(true); } return(false); } } } return(false); }
public static bool HorseThreatCheck(int kingX, int kingY, Dictionary <int, Dictionary <int, ChessPiece> > scenario, PieceColor enemy) { if (HelperMaths.IsInRange(kingX - 2, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7)) { if (scenario[kingX - 2][kingY - 1]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } if (HelperMaths.IsInRange(kingX - 2, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7)) { if (scenario[kingX - 2][kingY + 1]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } if (HelperMaths.IsInRange(kingX + 2, 0, 7) && HelperMaths.IsInRange(kingY - 1, 0, 7)) { if (scenario[kingX + 2][kingY - 1]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } if (HelperMaths.IsInRange(kingX + 2, 0, 7) && HelperMaths.IsInRange(kingY + 1, 0, 7)) { if (scenario[kingX + 2][kingY + 1]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } // if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY + 2, 0, 7)) { if (scenario[kingX + 1][kingY + 2]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY + 2, 0, 7)) { if (scenario[kingX - 1][kingY + 2]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } if (HelperMaths.IsInRange(kingX + 1, 0, 7) && HelperMaths.IsInRange(kingY - 2, 0, 7)) { if (scenario[kingX + 1][kingY - 2]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } if (HelperMaths.IsInRange(kingX - 1, 0, 7) && HelperMaths.IsInRange(kingY - 2, 0, 7)) { if (scenario[kingX - 1][kingY - 2]?.ToString() == enemy.ToString() + "Horseman") { return(true); } } return(false); }
public static Dictionary <int, Dictionary <int, ChessPiece> > GetGameState() { var clone = HelperMaths.DeepClone(Layout); return(clone); }