public virtual List <Move> getPossibleMoves() { List <Move> moves = calculateMoves(); King king = Board.GetFigures(Color, FiguresEnum.King).FirstOrDefault() as King; List <Move> movesInCheck = new List <Move>(); foreach (var move in moves) { Position p = move.Destination; Position currentPosition = new Position(Position); Figure figureOnPosition = Board.GetFigure(p); if (figureOnPosition != null) { Board.RemoveFigure(figureOnPosition); } setPosition(p); if (!king.isInCheck()) { movesInCheck.Add(move); } setPosition(currentPosition); if (figureOnPosition != null) { Board.AddFigure(figureOnPosition); } } return(movesInCheck); }
public bool isCheck() { King whiteKing = GetFigures(Color.White, FiguresEnum.King).FirstOrDefault() as King; King blackKing = GetFigures(Color.Black, FiguresEnum.King).FirstOrDefault() as King; if (whiteKing != null && whiteKing.isInCheck()) { KingInCheck = whiteKing; isMate(); return(true); } if (blackKing != null && blackKing.isInCheck()) { KingInCheck = blackKing; isMate(); return(true); } KingInCheck = null; return(false); }