public List <Piece> IsPieceWhoCanDisableEchec(List <Piece> pieceMakeEchec, Piece.Color color) { List <Piece> pieceToMustMove = new List <Piece>(); Roi king = GetKing(color); if (king.GetPossibleMovesWhenInEchec(GameBoard, king.Coord, king) != null) { pieceToMustMove.Add(king); } foreach (Piece pieceGame in GameBoard) { if (pieceGame != null && pieceGame.color == color && pieceGame.name != "Roi") { List <Coord> movePieceGame = pieceGame.GetPossibleMoves(GameBoard, pieceGame.Coord); if (movePieceGame != null) { movePieceGame.ForEach(delegate(Coord coordPieceGame) { pieceMakeEchec.ForEach(delegate(Piece pieceEchec) { if (coordPieceGame.x == pieceEchec.Coord.x && coordPieceGame.y == pieceEchec.Coord.y) { if (!pieceToMustMove.Contains(pieceGame)) { pieceToMustMove.Add(pieceGame); } } List <Coord> movePieceEchec = pieceEchec.GetPossibleMovesWhenMakeEchec(GameBoard, pieceEchec.Coord, king.Coord); if (movePieceEchec != null) { movePieceEchec.ForEach(delegate(Coord coordPieceEchec) { if (coordPieceGame.x == coordPieceEchec.x && coordPieceGame.y == coordPieceEchec.y) { if (!pieceToMustMove.Contains(pieceGame)) { pieceToMustMove.Add(pieceGame); } } }); } }); }); } } } if (pieceToMustMove.Count == 0) { return(null); } return(pieceToMustMove); }
public bool IsEchecMat(Roi king) { if (king.isEchec) { List <Coord> moveKing = king.GetPossibleMovesWhenInEchec(GameBoard, king.Coord, king); List <Piece> pieceToMustMove = IsPieceWhoCanDisableEchec(king.pieceMakeEchec, king.color); string winColor = ""; if (king.color == Piece.Color.white) { winColor = "noirs"; } if (king.color == Piece.Color.black) { winColor = "blancs"; } if (moveKing == null && pieceToMustMove == null) { PrintBoard(); Console.WriteLine(" Echec et Mat !"); Console.WriteLine(" Les " + winColor + " ont gagne !"); return(true); } } return(false); }