public static bool IsInCheck([NotNull] this GamePosition gamePosition, GameSide side)
        {
            if (gamePosition is null)
            {
                throw new ArgumentNullException(nameof(gamePosition));
            }

            var king          = side.ToPiece(PieceType.King);
            var attackingSide = side.Invert();
            var kingSquares   = gamePosition.PiecePosition[king].GetSquares();

            return(gamePosition.IsAnyUnderAttack(kingSquares, attackingSide));
        }
예제 #2
0
        protected GamePosition([NotNull] GamePosition other)
        {
            if (other is null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            var otherType = other.GetType();

            if (otherType != GetType())
            {
                throw new ArgumentException($@"Invalid object type '{otherType.GetFullName()}'.", nameof(other));
            }

            PiecePosition = other.PiecePosition.Copy();
            ActiveSide    = other.ActiveSide;
            FullMoveIndex = other.FullMoveIndex;
        }
        public static bool IsAnyUnderAttack(
            [NotNull] this GamePosition gamePosition,
            [NotNull] ICollection <Square> targetSquares,
            GameSide attackingSide)
        {
            if (gamePosition is null)
            {
                throw new ArgumentNullException(nameof(gamePosition));
            }

            if (targetSquares is null)
            {
                throw new ArgumentNullException(nameof(targetSquares));
            }

            var result = targetSquares.Count != 0 &&
                         targetSquares.Any(targetSquare => gamePosition.IsUnderAttack(targetSquare, attackingSide));

            return(result);
        }
예제 #4
0
 public abstract bool IsSamePosition([NotNull] GamePosition other);
예제 #5
0
 public override bool IsSamePosition(GamePosition other) => IsSamePosition(other as StandardGamePosition);