Esempio n. 1
0
        internal static IEnumerable <NotationMoveType> EnumerateMoves()
        {
            var randomGenerator = new Random();
            var lastRotation    = NotationRotationNames.None;

            while (true)
            {
                var nextMove = new NotationMoveType(
                    GetRandomRotationName(randomGenerator, lastRotation),
                    GetRandomRotationType(randomGenerator));
                lastRotation = nextMove.Name;

                yield return(nextMove);
            }
        }
        public static IEnumerable <NotationMoveType> EnumerateMoves(string moves)
        {
            var move = NotationMoveType.None;

            foreach (var moveChar in moves)
            {
                if (char.IsWhiteSpace(moveChar))
                {
                    // Ignore whitespace.
                }
                else if (moveChar == '\'')
                {
                    if (move.Type != NotationRotationType.Clockwise)
                    {
                        throw new Exception("Invalid move notation.");
                    }

                    move = move.With(NotationRotationType.CounterClockwise);
                }
                else if (moveChar == '2')
                {
                    if (move.Type != NotationRotationType.Clockwise)
                    {
                        throw new Exception("Invalid move notation.");
                    }

                    move = move.With(NotationRotationType.Double);
                }
                else if (char.IsLetter(moveChar))
                {
                    if (!move.IsEmpty)
                    {
                        yield return(move);

                        move = NotationMoveType.None;
                    }

                    move = new NotationMoveType(ParseMoveName(moveChar));
                }
            }

            if (!move.IsEmpty)
            {
                yield return(move);
            }
        }
 public static string FormatMove(NotationMoveType move)
 => FormatMoveName(move.Name) + FormatRotationType(move.Type);