Example #1
0
        public List <Point> GetSafeMovesFromCheck(ChessBoard chessBoard)
        {
            var safePossibles = new List <Point>();
            var possibleMoves = this.GetPossibleMoves(chessBoard);
            var kingToCheck   = chessBoard.GetFigureByPercolate(f => f.ToString() == "King" &&
                                                                f.Color == this.Color);

            foreach (var possible in possibleMoves)
            {
                var startPosition = this.Position;
                chessBoard.RemovedFigure = default;
                this.MoveGod(possible, chessBoard);
                if (!chessBoard.IsPointUnderCheck(kingToCheck.Position, kingToCheck.Color))
                {
                    safePossibles.Add(possible);
                }
                this.MoveGod(startPosition, chessBoard);
                chessBoard.AddFigure(chessBoard.RemovedFigure);
                chessBoard.RemovedFigure = default;
            }
            return(safePossibles);
        }