コード例 #1
0
        /// <summary>
        /// Attack all squares through a certain direction, based on their distance from
        /// <paramref name="originSquare"/>.
        /// </summary>
        /// <param name="originSquare">Attacker square, based on
        /// <paramref name="position"/>.</param>
        /// <param name="orientation">Attack orientation.</param>
        /// <param name="sense">True if the attack sense follows the orientation.
        /// False otherwise.</param>
        /// <param name="position">A given <see cref="Board.Position"/>.</param>
        /// <returns></returns>
        private static IEnumerable <Move> Attack(
            this Square originSquare,
            Through orientation,
            bool sense,
            IReadOnlyDictionary <Square, IPiece> position)
        {
            var moves = new List <Move>();

            int numberOfSquares = 1;

            var move = originSquare.AttackSquare(
                originSquare.Maneuver(
                    orientation, sense ? numberOfSquares : -numberOfSquares),
                position);

            while (move is not null)
            {
                yield return(move);

                if (move.Type is MoveType.Capture)
                {
                    yield break;
                }

                move = originSquare.AttackSquare(
                    originSquare.Maneuver(
                        orientation, sense ? (numberOfSquares += 1) : -(numberOfSquares += 1)),
                    position);
            }
        }
コード例 #2
0
        /// <summary>
        /// Attack all squares through a certain direction.
        /// </summary>
        /// <param name="piece">Attacking <see cref="Piece"/>.</param>
        /// <param name="orientation">Attack orientation.</param>
        /// <param name="position">A given <see cref="Board.Position"/>.</param>
        /// <param name="sense">True if the attack sense follows the orientation.
        /// False otherwise.</param>
        /// <param name="range">The range of the attack. Indicates how deep the attack is
        /// relative to <see cref="Piece.GetSquareFrom(IReadOnlyDictionary{Square, IPiece})"/>.</param>
        /// <returns>A read-only <see cref="Move"/> collection.</returns>
        public static IReadOnlyCollection <Move> Attack(
            this Piece piece,
            Through orientation,
            bool sense,
            IReadOnlyDictionary <Square, IPiece> position,
            uint range = 7)
        {
            var square = piece.GetSquareFrom(position);

            return((square is null) ?
                   new List <Move>() :
                   square
                   .Attack(orientation, sense, position)
                   .Take((int)range)
                   .ToList());
        }
コード例 #3
0
 /// <summary>
 /// Returns the destination <see cref="Square"/> by moving a certain <paramref name="numberOfSquares"/>
 /// through an <paramref name="orientation"/> from origin <paramref name="square"/>.
 /// </summary>
 /// <param name="square">Origin square.</param>
 /// <param name="orientation">The move orientation.</param>
 /// <param name="numberOfSquares">Number of squares. A negative number indicates a change in sense.</param>
 /// <returns></returns>
 public static Square Maneuver(
     this Square square,
     Through orientation,
     int numberOfSquares)
 => orientation switch
 {