コード例 #1
0
        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;
        }
コード例 #3
0
        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);