def map_update_clues_test(): # Test Map.update_clues method # create map and characters a_map = map_.Map('story') player = char.Player() boar = char.Boar() a_map.characters['player'] = player a_map.characters['boar'] = boar # add two adjacent scenes s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' a_map.add_scene(s1) # scene2 is east of scene1 s2 = map_gen.new_scene(a_map, None, (6, 5)) s2.name = 'scene2' a_map.add_scene(s2) map_gen.create_link(s1, s2) # put some clues in the scenes s1.clues.append(map_.FootprintClue('e')) s2.clues.append(map_.BrokenTreeClue()) ok_(s1.clues[0].fresh == 2) ok_(s2.clues[0].fresh == 2) # update clues one clock tick a_map.update_clues() ok_(s1.clues[0].fresh == 1) ok_(s2.clues[0].fresh == 1) # update clues one more time a_map.update_clues() ok_(s1.clues[0].fresh == 0) ok_(s2.clues[0].fresh == 0)
def run_away_test(): # Test player running away! # create map and characters a_map = map_.Map('story') player = char.Player() boar = char.Boar() a_map.characters['player'] = player a_map.characters['boar'] = boar # add two adjacent scenes s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' a_map.add_scene(s1) s2 = map_gen.new_scene(a_map, None, (6, 5)) s2.name = 'scene2' a_map.add_scene(s2) map_gen.create_link(s1, s2) # spawn the boss in one of the scenes map_gen.add_lair(a_map) map_gen.spawn_boss(a_map) # run away from one of the scenes name = combat.run_away(s1) ok_(name == s2.name) name = combat.run_away(s2) ok_(name == s1.name)
def DFS_test(): # test for the helper function DFS a_map = map_.Map('story') s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' a_map.add_scene(s1) s2 = map_gen.new_scene(a_map, None, (6, 5)) s2.name = 'scene2' a_map.add_scene(s2) map_gen.create_link(s1, s2) ok_(set(DFS(s1, a_map)) == set([s1, s2])) ok_(set(DFS(s2, a_map)) == set([s1, s2]))
def create_link_test(): a_map = map_.Map('story') # east-west s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' s2 = map_gen.new_scene(a_map, None, (6, 5)) s2.name = 'scene2' map_gen.create_link(s1, s2) ok_(s1.exits['e'] == 'scene2') ok_(s2.exits['w'] == 'scene1') # north-south s3 = map_gen.new_scene(a_map, None, (5, 6)) s3.name = 'scene3' map_gen.create_link(s1, s3) ok_(s1.exits['s'] == 'scene3') ok_(s3.exits['n'] == 'scene1') # nw-se s4 = map_gen.new_scene(a_map, None, (4, 6)) s4.name = 'scene4' map_gen.create_link(s1, s4) ok_(s1.exits['sw'] == 'scene4') ok_(s4.exits['ne'] == 'scene1') # ne-sw s5 = map_gen.new_scene(a_map, None, (6, 6)) s5.name = 'scene5' map_gen.create_link(s1, s5) ok_(s1.exits['se'] == 'scene5') ok_(s5.exits['nw'] == 'scene1')
def move_boss_test(): # Tests boss' movement on the map # create map: 1-2-3 a_map = map_.Map('story') s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' a_map.add_scene(s1) s2 = map_gen.new_scene(a_map, None, (6, 5)) s2.name = 'scene2' a_map.add_scene(s2) s3 = map_gen.new_scene(a_map, None, (7, 5)) s3.name = 'scene3' a_map.add_scene(s3) map_gen.create_link(s1, s2) map_gen.create_link(s2, s3) # set lair and spawn boss a_map.boss_scene_name = s1.name a_map.lair_scene_name = s1.name s1.flags['encounter'] = True # test 1: daytime, in lair scene for t in range(7, 20): # 0700 to 1900 a_map.clock.time = t new_scene, direction = a_map.move_boss() ok_(not a_map.path) # no path chosen ok_(new_scene == s1.name and not direction) # should stay in same scene # test 2: daytime, not in lair scene for t in range(7, 20): # 0700 to 1900 a_map.clock.time = t a_map.path = [] # reset path a_map.boss_scene_name = s3.name # spawn boss away from lair new_scene, direction = a_map.move_boss() ok_(a_map.path) # path to lair constructed # test 3: nighttime moved = False a_map.clock.time = 20 for t in range(10): # 2000 to 0600 a_map.clock.tick() a_map.boss_scene_name = s3.name # spawn boss away from lair new_scene, direction = a_map.move_boss() if direction: # not None moved = True ok_(not a_map.path) # no path chosen ok_(moved) # should have moved at least once (randomly)
def construct_path_test(): # Test path construction # map 1: 1-2-3-4 a_map = map_.Map('story') s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' a_map.add_scene(s1) s2 = map_gen.new_scene(a_map, None, (6, 5)) s2.name = 'scene2' a_map.add_scene(s2) s3 = map_gen.new_scene(a_map, None, (7, 5)) s3.name = 'scene3' a_map.add_scene(s3) s4 = map_gen.new_scene(a_map, None, (8, 5)) s4.name = 'scene4' a_map.add_scene(s4) # create links map_gen.create_link(s1, s2) map_gen.create_link(s2, s3) map_gen.create_link(s3, s4) # test 1: 1 to 4 path = a_map.construct_path(s1.name, s4.name) print path ok_(path == ['scene4', 'scene3', 'scene2']) # test 2: 2 to 4 path = a_map.construct_path(s2.name, s4.name) print path ok_(path == ['scene4', 'scene3']) # test 3: 3 to 4 path = a_map.construct_path(s3.name, s4.name) print path ok_(path == ['scene4']) # map 2: # 1 # |\ # 2 3 # | | # 5-4 a_map = map_.Map('story') s1 = map_gen.new_scene(a_map, None, (5, 5)) s1.name = 'scene1' a_map.add_scene(s1) s2 = map_gen.new_scene(a_map, None, (5, 6)) s2.name = 'scene2' a_map.add_scene(s2) s3 = map_gen.new_scene(a_map, None, (6, 6)) s3.name = 'scene3' a_map.add_scene(s3) s4 = map_gen.new_scene(a_map, None, (6, 7)) s4.name = 'scene4' a_map.add_scene(s4) s5 = map_gen.new_scene(a_map, None, (5, 7)) s5.name = 'scene5' a_map.add_scene(s5) # create links map_gen.create_link(s1, s2) map_gen.create_link(s1, s3) map_gen.create_link(s2, s5) map_gen.create_link(s3, s4) map_gen.create_link(s4, s5) # test 1: 1 to 5 path = a_map.construct_path(s1.name, s5.name) print path ok_(path == ['scene5', 'scene2']) # test 2: 3 to 2 path = a_map.construct_path(s3.name, s2.name) print path ok_(path == ['scene2', 'scene1'])