public bool WouldBeInCheckAfter(Move move, Player player) { ChessUtilities.ThrowIfNull(move, nameof(move)); var gcd = new GameCreationData(); gcd.Board = Board; gcd.CanWhiteCastleKingSide = !_whiteRookHMoved && !_whiteKingMoved; gcd.CanWhiteCastleQueenSide = !_whiteRookAMoved && !_whiteKingMoved; gcd.CanBlackCastleKingSide = !_blackRookHMoved && !_blackKingMoved; gcd.CanBlackCastleQueenSide = !_blackRookAMoved && !_blackKingMoved; gcd.EnPassant = null; if (_moves.Count > 0) { var last = _moves.Last(); if (last.Piece is Pawn && new SquareDistance(last.OriginalPosition, last.NewPosition).DistanceY == 2) { gcd.EnPassant = new Square(last.NewPosition.File, last.Player == Player.White ? 3 : 6); } } gcd.HalfMoveClock = _halfMoveClock; gcd.FullMoveNumber = _fullMoveNumber; var copy = new ChessGame(gcd); copy.ApplyMove(move, true); var status = copy.CalculateStatus(player, false); return(status.Event == GameEvent.Check && status.PlayerWhoCausedEvent != player); }
protected virtual bool WouldBeInCheckAfter(Move move, Player player) { Utilities.ThrowIfNull(move, "move"); ChessGame copy = new ChessGame(Board, player, false); copy.ApplyMove(move, true, false); GameStatus status = copy.CalculateStatus(player, false); return(status.Event == GameEvent.Check && status.PlayerWhoCausedEvent != player); }
protected virtual bool WouldBeInCheckAfter(Move move, Player player) { Utilities.ThrowIfNull(move, "move"); ChessGame copy = new ChessGame(Board, player, false); copy.ApplyMove(move, true, false); GameStatus status = copy.CalculateStatus(player, false); return status.Event == GameEvent.Check && status.PlayerWhoCausedEvent != player; }