Exemplo n.º 1
0
        private static Script CreateScript(int switchType, int switchColor, VariableLookup lookup)
        {
            switch (switchColor)
            {
            case ZeldaStates.SwitchRed: return(ZeldaScripts.CreateRedPiston(switchType, lookup));

            case ZeldaStates.SwitchBlue: return(ZeldaScripts.CreateBluePiston(switchType, lookup));
            }

            Debug.Fail();
            return(IdentityScript.Default);
        }
Exemplo n.º 2
0
        public void CrawlGenome()
        {
            // 3--2, 0--7, Switch: 4, Key: 3, Door: 9--8, Key: 9, Door: 4--6, 9--0, Key: 8, Door: 8--5, Piston: 7--1, Key: 7, Door: 5--6, Piston: 2--6
            // 0--7, 0--9, 2--3, Key: 3, Key: 7, Key: 8, Key: 9, Door: 4--6, Door: 5--6, Door: 5--8, Door: 8--9, Switch: 4, Piston: 1--7, Piston: 2--6

            var builder = new ZeldaDungeonBuilder();
            var lookup  = builder.Lookup;

            // 0--7, 0--9, 2--3
            builder.AddUndirectedTransition(0, 7, IdentityScript.Default);
            builder.AddUndirectedTransition(0, 9, IdentityScript.Default);
            builder.AddUndirectedTransition(2, 3, IdentityScript.Default);

            // Key: 3, Key: 7, Key: 8, Key: 9
            builder.AddScript(3, ZeldaScripts.CreateKey(0, lookup));
            builder.AddScript(7, ZeldaScripts.CreateKey(0, lookup));
            builder.AddScript(8, ZeldaScripts.CreateKey(0, lookup));
            builder.AddScript(9, ZeldaScripts.CreateKey(0, lookup));

            // Door: 4--6, Door: 5--6, Door: 5--8, Door: 8--9
            builder.AddUndirectedTransition(4, 6, ZeldaScripts.CreateDoor(0, lookup));
            builder.AddUndirectedTransition(5, 6, ZeldaScripts.CreateDoor(0, lookup));
            builder.AddUndirectedTransition(5, 8, ZeldaScripts.CreateDoor(0, lookup));
            builder.AddUndirectedTransition(8, 9, ZeldaScripts.CreateDoor(0, lookup));

            // Switch: 4, Piston: 1--7, Piston: 2--6
            builder.AddScript(4, ZeldaScripts.CreateColorSwitch(0, lookup));

            // Piston: 1--7, Piston: 2--6
            builder.AddUndirectedTransition(1, 7, ZeldaScripts.CreateBluePiston(0, lookup));
            builder.AddUndirectedTransition(2, 6, ZeldaScripts.CreateRedPiston(0, lookup));

            var crawler = builder.Build();
            var dot     = new DotBuilder();

            crawler.Express(dot);

            var initialState = emptyVariables.ToState(builder.Lookup);

            crawler.Crawl(new[] { initialState }, 10000);

            // test for exit reached
            Assert.True(crawler.DebugGetStep(0, initialState).HasDistanceFromExit);
        }