public void Express(ZeldaDungeonBuilder builder) { foreach (ZeldaGene gene in genes) { gene.Express(builder); } }
public void CrawlDeadCycle() { // 0 -> 2 - 3 // | \ / // 1 4 var builder = new ZeldaDungeonBuilder(); builder.AddUndirectedTransition(0, 1, IdentityScript.Default); builder.AddUndirectedTransition(2, 3, IdentityScript.Default); builder.AddUndirectedTransition(3, 4, IdentityScript.Default); builder.AddUndirectedTransition(4, 2, IdentityScript.Default); builder.AddDirectedTransition(0, 2, IdentityScript.Default); var puzzle = builder.Build(); var initialState = emptyVariables.ToState(builder.Lookup); puzzle.Crawl(new[] { initialState }, maxSteps); Assert.NotNull(puzzle.DebugGetStep(0, initialState)); Assert.NotNull(puzzle.DebugGetStep(1, initialState)); Assert.NotNull(puzzle.DebugGetStep(2, initialState)); Assert.NotNull(puzzle.DebugGetStep(3, initialState)); Assert.NotNull(puzzle.DebugGetStep(4, initialState)); Assert.True(puzzle.DebugGetStep(0, initialState).HasDistanceFromExit); Assert.False(puzzle.DebugGetStep(2, initialState).HasDistanceFromExit); Assert.False(puzzle.DebugGetStep(3, initialState).HasDistanceFromExit); Assert.False(puzzle.DebugGetStep(4, initialState).HasDistanceFromExit); }
public override void Express(ZeldaDungeonBuilder builder) { // spawn key builder.AddScript(keyLocation, ZeldaScripts.CreateKey(keyType, builder.Lookup)); // spawn door builder.AddUndirectedTransition(doorStart, doorEnd, ZeldaScripts.CreateDoor(keyType, builder.Lookup)); }
public void CrawlMinimal() { // 0 - 1 var builder = new ZeldaDungeonBuilder(); builder.AddUndirectedTransition(0, 1, IdentityScript.Default); var crawler = builder.Build(); var initialState = emptyVariables.ToState(builder.Lookup); var terminalSteps = crawler.Crawl(new[] { initialState }, maxSteps); Assert.IsNotEmpty(terminalSteps); Assert.NotNull(crawler.DebugGetStep(0, initialState)); Assert.NotNull(crawler.DebugGetStep(1, initialState)); Assert.True(crawler.DebugGetStep(0, initialState).HasDistanceFromExit); Assert.True(crawler.DebugGetStep(1, initialState).HasDistanceFromExit); }
public void CrawlLinear() { // 0 - 2 - 3 - 1 var builder = new ZeldaDungeonBuilder(); builder.AddUndirectedTransition(0, 2, IdentityScript.Default); builder.AddUndirectedTransition(2, 3, IdentityScript.Default); builder.AddUndirectedTransition(3, 1, IdentityScript.Default); var crawler = builder.Build(); var initialState = emptyVariables.ToState(builder.Lookup); var terminalSteps = crawler.Crawl(new[] { initialState }, maxSteps); Assert.NotNull(crawler.DebugGetStep(0, initialState)); Assert.NotNull(crawler.DebugGetStep(1, initialState)); Assert.NotNull(crawler.DebugGetStep(2, initialState)); Assert.NotNull(crawler.DebugGetStep(3, initialState)); }
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); }
public Individual Evaluate(Genome g) { ZeldaGenome genome = (ZeldaGenome)g; // build puzzle var builder = new ZeldaDungeonBuilder(); Profiler.BeginSample("Express"); genome.Express(builder); Profiler.EndSample(); var crawler = builder.Build(); // build initial states var initialStates = new List <State>(); foreach (var variableAssignment in initialVariables) { var state = variableAssignment.ToState(builder.Lookup); initialStates.Add(state); } // crawl puzzle Profiler.BeginSample("Crawl"); var terminalSteps = crawler.Crawl(initialStates, maxSteps); Profiler.EndSample(); // evaluate puzzle Profiler.BeginSample("Assess"); int numSteps = crawler.DebugGetSteps().Count(); int numDeadEnds = ErrorCounter.CountDeadEnds(crawler); int shortestPathLength = PathFinder.CalcShortestPathLength(terminalSteps); double revisitFactor = PathFinder.CalcRevisitFactor(crawler); double branchFactor = PathFinder.CalcBranchFactor(crawler); Profiler.EndSample(); // create individual return(new ZeldaIndividual(genome, crawler, numSteps, numDeadEnds, shortestPathLength, revisitFactor, branchFactor)); }
public void CrawlKeyDoorBatch() { // 0 -d- 2 -d- 3 -d- 1 // kkk var builder = new ZeldaDungeonBuilder(); var lookup = builder.Lookup; builder.AddUndirectedTransition(0, 2, ZeldaScripts.CreateDoor(0, lookup)); builder.AddUndirectedTransition(2, 3, ZeldaScripts.CreateDoor(0, lookup)); builder.AddUndirectedTransition(3, 1, ZeldaScripts.CreateDoor(0, lookup)); builder.AddScript(0, ZeldaScripts.CreateKey(0, lookup)); builder.AddScript(0, ZeldaScripts.CreateKey(0, lookup)); builder.AddScript(0, ZeldaScripts.CreateKey(0, lookup)); var crawler = builder.Build(); var initialState = emptyVariables.ToState(builder.Lookup); crawler.Crawl(new[] { initialState }, maxSteps); // test for exit reached Assert.True(crawler.DebugGetStep(0, initialState).HasDistanceFromExit); }
public void CrawlDeadEnd() { // 0 -> 3 // \ // 2 - 1 var builder = new ZeldaDungeonBuilder(); builder.AddUndirectedTransition(0, 2, IdentityScript.Default); builder.AddUndirectedTransition(2, 1, IdentityScript.Default); builder.AddDirectedTransition(0, 3, IdentityScript.Default); var crawler = builder.Build(); var initialState = emptyVariables.ToState(builder.Lookup); crawler.Crawl(new[] { initialState }, maxSteps); Assert.NotNull(crawler.DebugGetStep(0, initialState)); Assert.NotNull(crawler.DebugGetStep(1, initialState)); Assert.NotNull(crawler.DebugGetStep(2, initialState)); Assert.NotNull(crawler.DebugGetStep(3, initialState)); Assert.IsEmpty(crawler.DebugGetStep(3, initialState).Successors); Assert.False(crawler.DebugGetStep(3, initialState).HasDistanceFromExit); }
public override void Express(ZeldaDungeonBuilder builder) { builder.AddScript(toolLocation, ZeldaScripts.CreateTool(toolType, builder.Lookup)); }
public override void Express(ZeldaDungeonBuilder builder) { builder.AddDirectedTransition(wayStart, wayEnd, IdentityScript.Default); }
public override void Express(ZeldaDungeonBuilder builder) { builder.AddScript(switchLocation, ZeldaScripts.CreateColorSwitch(switchType, builder.Lookup)); }
public override void Express(ZeldaDungeonBuilder builder) { builder.AddUndirectedTransition(pistonStart, pistonEnd, CreateScript(switchType, switchColor, builder.Lookup)); }
public abstract void Express(ZeldaDungeonBuilder builder);