コード例 #1
0
ファイル: Rotor.cs プロジェクト: un-pogaz/ChromatikTool
        /// <summary>
        /// Initialize a rotor with a set of given wires and the specifieds rotates.
        /// </summary>
        public Rotor(string id, IEnumerable <char> wires, char?initialPosition, IEnumerable <char> rotateAt) : base(wires)
        {
            if (id.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("The " + nameof(id) + " can be null, Empty or WhiteSpace.", nameof(id));
            }
            Id = id;

            WiresLeft  = new WireMatrix(wires);
            WiresRight = WiresLeft.Invert();

            if (rotateAt == null)
            {
                RotateAt = new char[0];
            }
            else
            {
                rotateAt = rotateAt.Distinct();

                foreach (char item in rotateAt)
                {
                    if (!AlphabetContains(item))
                    {
                        throw ExceptionInvalidChar(item, nameof(rotateAt));
                    }
                }

                RotateAt = rotateAt.ToArray();
            }


            if (initialPosition == null)
            {
                InitialPosition = OperatingAlphabet[0];
            }
            else
            {
                InitialPosition = initialPosition.GetValueOrDefault();
            }
        }
コード例 #2
0
ファイル: Reflector.cs プロジェクト: un-pogaz/ChromatikTool
 /// <summary>
 /// Initialize a reflector with a set of given wires.
 /// </summary>
 public Reflector(string id, IEnumerable <char> wires) : base(wires)
 {
     Id    = id;
     Wires = new WireMatrix(wires);
 }