exploration.tests.core_demo
Authors: Peter Mawhorter Consulted: Date: 2022-8-31 Purpose: Demos of core functionality.
1""" 2Authors: Peter Mawhorter 3Consulted: 4Date: 2022-8-31 5Purpose: Demos of core functionality. 6""" 7 8from .. import core 9 10 11def graph_example(): 12 """ 13 Builds and returns a tiny `exploration.core.DecisionGraph`. 14 """ 15 m = core.DecisionGraph() 16 m.addDecision('a') 17 m.addDecision('b') 18 m.addDecision('c') 19 20 m.addTransition('a', 'East', 'b', 'West') 21 m.addTransition('a', 'Northeast', 'c') 22 m.addTransition('c', 'Southeast', 'b') 23 24 m.addUnexploredEdge('a', 'South') 25 26 return m 27 28 29def sm_demo(): 30 """ 31 Builds and returns a tiny `exploration.core.DiscreteExploration` 32 representing just parts of the first two rooms of Super Metroid 33 post-Ceres. 34 """ 35 # Create first two decisions 36 e = core.DiscreteExploration() 37 e.start('1. on ship', ['left', 'right']) 38 e.explore('right', '2. cliff', ['up cliff', 'through tunnel'], 'to ship') 39 40 # Add requirements to cliff options we can't take yet 41 g = e.currentGraph() 42 g.setTransitionRequirement('2. cliff', 'up cliff', 'high_jump') 43 g.setTransitionRequirement('2. cliff', 'through tunnel', 'block_breaker') 44 45 # Add decision point before door 46 e.retrace('to ship') 47 e.explore('left', '3. cave entrance', ['through door'], 'to ship') 48 49 # Add decision point for top room 50 e.explore('through door', '4. cave', 51 ['down blocked', 'down short', 'left', 'down pit'], 52 'door to outside') 53 54 # Set some requirements 55 g = e.currentGraph() 56 g.setTransitionRequirement('4. cave', 'down blocked', 57 'crawl&block_breaker') 58 g.setTransitionRequirement('4. cave', 'down short', 'crawl') 59 g.setTransitionRequirement('4. cave', 'left', 'block_breaker') 60 61 # Explore down to the first ledge where a door is visible 62 e.explore('down pit', '5. cave ledge', ['down', 'recessed door'], 'up') 63 64 # Set some requirement for the door 65 g = e.currentGraph() 66 g.setTransitionRequirement('5. cave ledge', 'recessed door', 'crawl') 67 68 # Only option remaining is to continue down, but we'll leave things 69 # at this point for now. 70 return e 71 72 73if __name__ == "__main__": 74 e = sm_demo() 75 76 import networkx as nx # type: ignore [import] 77 78 # You'll need to install the 'matplotlib' package for this to work 79 try: 80 import matplotlib.pyplot as plt # type: ignore [import] 81 82 # This draws the graph in a new window that pops up. You have to close 83 # the window to end the program. 84 nx.draw(e.currentGraph()) 85 plt.show() 86 except Exception: 87 print( 88 "Because matplotlib is not installed, we cannot demo drawing" 89 " a graph." 90 ) 91 92 # You'll need to install the 'pydot' package for this to work 93 # This saves the graph in dot format to the file 'graph.dot' 94 try: 95 nx.nx_pydot.write_dot(e.currentGraph(), "sm_start.dot") 96 except Exception: 97 print("Skipped writing a DOT file; is 'pydot' installed?")
def
graph_example():
12def graph_example(): 13 """ 14 Builds and returns a tiny `exploration.core.DecisionGraph`. 15 """ 16 m = core.DecisionGraph() 17 m.addDecision('a') 18 m.addDecision('b') 19 m.addDecision('c') 20 21 m.addTransition('a', 'East', 'b', 'West') 22 m.addTransition('a', 'Northeast', 'c') 23 m.addTransition('c', 'Southeast', 'b') 24 25 m.addUnexploredEdge('a', 'South') 26 27 return m
Builds and returns a tiny exploration.core.DecisionGraph
.
def
sm_demo():
30def sm_demo(): 31 """ 32 Builds and returns a tiny `exploration.core.DiscreteExploration` 33 representing just parts of the first two rooms of Super Metroid 34 post-Ceres. 35 """ 36 # Create first two decisions 37 e = core.DiscreteExploration() 38 e.start('1. on ship', ['left', 'right']) 39 e.explore('right', '2. cliff', ['up cliff', 'through tunnel'], 'to ship') 40 41 # Add requirements to cliff options we can't take yet 42 g = e.currentGraph() 43 g.setTransitionRequirement('2. cliff', 'up cliff', 'high_jump') 44 g.setTransitionRequirement('2. cliff', 'through tunnel', 'block_breaker') 45 46 # Add decision point before door 47 e.retrace('to ship') 48 e.explore('left', '3. cave entrance', ['through door'], 'to ship') 49 50 # Add decision point for top room 51 e.explore('through door', '4. cave', 52 ['down blocked', 'down short', 'left', 'down pit'], 53 'door to outside') 54 55 # Set some requirements 56 g = e.currentGraph() 57 g.setTransitionRequirement('4. cave', 'down blocked', 58 'crawl&block_breaker') 59 g.setTransitionRequirement('4. cave', 'down short', 'crawl') 60 g.setTransitionRequirement('4. cave', 'left', 'block_breaker') 61 62 # Explore down to the first ledge where a door is visible 63 e.explore('down pit', '5. cave ledge', ['down', 'recessed door'], 'up') 64 65 # Set some requirement for the door 66 g = e.currentGraph() 67 g.setTransitionRequirement('5. cave ledge', 'recessed door', 'crawl') 68 69 # Only option remaining is to continue down, but we'll leave things 70 # at this point for now. 71 return e
Builds and returns a tiny exploration.core.DiscreteExploration
representing just parts of the first two rooms of Super Metroid
post-Ceres.