示例#1
0
            public bool MoveNext()
            {
                if (!this.initialized)
                {
                    this.position     = this.grid.GetCenterPosition();
                    this.compassCycle = this.compassCycle.Reset();
                    this.initialized  = true;
                    return(true);
                }

                if (this.position == this.end)
                {
                    return(false);
                }

                var compassCycle = this.compassCycle.Next();
                var position     = this.position.MoveTo(compassCycle.Direction);

                if (this.grid.CanPositionBeTaken(position))
                {
                    this.compassCycle = compassCycle;
                    this.position     = position;
                }
                else
                {
                    this.position = this.position.MoveTo(this.compassCycle.Direction);
                }
                return(true);
            }
示例#2
0
 public SpiralOutwardGridPositionEnumerator(Grid grid)
 {
     this.grid         = grid ?? throw new ArgumentNullException(nameof(grid));
     this.compassCycle = new CompassCycle(Direction.Right, Direction.Up, Direction.Left, Direction.Down);
     this.end          = new Position(grid.Size - 1, grid.Size - 1);
     this.initialized  = false;
 }