Exemplo n.º 1
0
        private static void RunPuzzle2()
        {
            var scan      = LoadState("input.txt");
            var automaton = new RecursiveEris(scan);

            Console.WriteLine("PUZZLE 2");
            Console.WriteLine("========");
            automaton.Advance(200);
            Console.WriteLine("Total number of bugs: " + automaton.CountBugsRecursive());
        }
Exemplo n.º 2
0
 public RecursiveEris(IEnumerable <IEnumerable <char> > cells = null, RecursiveEris parentLevel = null, RecursiveEris childLevel = null)
 {
     Width  = 5;
     Height = 5;
     Cells  = new char[Height, Width];
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             Cells[y, x] = (cells != null ? cells.ElementAt(y).ElementAt(x) : '.');
         }
     }
     Cells[Center, Center] = '?';
     ParentLevel           = parentLevel;
     ChildLevel            = childLevel;
 }
Exemplo n.º 3
0
        public void Advance(int steps = 1, bool advanceParent = true, bool advanceChild = true)
        {
            for (int i = 0; i < steps; i++)
            {
                // save next and current layouts
                var    nextLayout = GetNextLayout();
                string tiles      = GetTileString();
                string nextTiles  = GetTileStringFor(nextLayout);

                // handle recursive levels
                if (advanceParent)
                {
                    // add parent level if layout will change
                    if (nextTiles != tiles && ParentLevel == null)
                    {
                        ParentLevel = new RecursiveEris(childLevel: this);
                    }

                    // advance parent level, if any
                    if (ParentLevel != null)
                    {
                        ParentLevel.Advance(advanceChild: false);
                    }
                }
                if (advanceChild)
                {
                    // add child level if layout will change
                    if (nextTiles != tiles && ChildLevel == null)
                    {
                        ChildLevel = new RecursiveEris(parentLevel: this);
                    }

                    // advance child level, if any
                    if (ChildLevel != null)
                    {
                        ChildLevel.Advance(advanceParent: false);
                    }
                }

                // update tiles
                Cells = nextLayout;
            }
        }
Exemplo n.º 4
0
        private static void RunExamples2()
        {
            var scan      = LoadState("example1.txt");
            var automaton = new RecursiveEris(scan);

            automaton.Advance(10);
            Console.WriteLine("EXAMPLE 2");
            Console.WriteLine("=========");
            Console.WriteLine("Depth 0:");
            PrintScan(automaton);
            Console.WriteLine();

            int counter = 0;
            var parent  = automaton.ParentLevel;

            while (parent != null)
            {
                counter--;
                Console.WriteLine("Depth " + counter + ":");
                PrintScan(parent);
                Console.WriteLine();
                parent = parent.ParentLevel;
            }
            counter = 0;
            var child = automaton.ChildLevel;

            while (child != null)
            {
                counter++;
                Console.WriteLine("Depth " + counter + ":");
                PrintScan(child);
                Console.WriteLine();
                child = child.ChildLevel;
            }
            Console.WriteLine("Total number of bugs: " + automaton.CountBugsRecursive());
        }