def test_solver_branch_trivial1(self): level = Level() level.upper_layer = np.array( [[s, kR, lR, e, e, f], [lB, kB, w, w, e, e]], dtype=object) # S--K--L--L--E # \ / # K----- start = Start() key1 = Key("key1") lock1 = Lock("lock1") key2 = Key("key2") lock2 = Lock("lock2") end = End() start.add_child_s([key1, key2]) key1.add_child_s(lock1) key1.add_lock_s(lock1) lock1.add_child_s(lock2) key2.add_lock_s(lock2) lock2.add_child_s(end) positions_map = { start: np.array([0, 0]), key1: np.array([0, 1]), lock1: np.array([0, 2]), key2: np.array([1, 1]), lock2: np.array([1, 0]), end: np.array([0, 5]), } level.mission = start level.positions_map = positions_map does_level_follow_mission, solution = Solver.does_level_follow_mission( level) self.assertEqual(does_level_follow_mission, False)
def test_works_with_branched_graphs(self): # return # S # |----------- # | | | # L1 K2 L2 # | | # E K1 start = Start() key1 = Key("1") key2 = Key("2") lock1 = Lock("1") lock2 = Lock("2") end = End() start.add_child_s([lock1, key2, lock2]) lock1.add_child_s(end) lock2.add_child_s(key1) key1.add_child_s(lock1) key2.add_child_s(lock2) key1.add_lock_s(lock1) key2.add_lock_s(lock2) np.random.seed(4) level = Level() w = Tiles.wall e = Tiles.empty layer = np.array([[w, w, w, w, w, w, w, w], [w, e, e, e, e, e, e, w], [w, e, e, e, e, e, e, w], [w, w, w, w, w, w, w, w], [w, e, e, w, e, e, e, w], [w, e, e, w, e, e, e, w], [w, e, e, w, e, e, e, w], [w, w, w, w, w, w, w, w]], dtype=object) solution_node_order = Node.find_all_nodes(start, method="topological-sort") aesthetic_settings = AestheticSettings() was_successful = Generator.generate( level=level, size=layer.shape, aesthetic_settings=aesthetic_settings, max_retry_count=10, pregenerated_level_layer=layer, pregenerated_solution_node_order=solution_node_order) self.assertTrue(was_successful) Log.print(level)
def test_solver_linear_solvable_multicolored_keys(self): level = Level() level.upper_layer = np.array([[kY, lG, kB, lR, s, kR, lB, kG, lY, f]], dtype=object) # S--K--L--K--L--K--L--K--L--E start = Start() key_red = Key("red") lock_red = Lock("red") key_blue = Key("blue") lock_blue = Lock("blue") key_green = Key("green") lock_green = Lock("green") key_yellow = Key("yellow") lock_yellow = Lock("yellow") end = End() start.add_child_s([lock_red, key_red, lock_blue]) lock_red.add_child_s([lock_green, key_blue]) lock_green.add_child_s(key_yellow) lock_blue.add_child_s([lock_yellow, key_green]) lock_yellow.add_child_s(end) key_red.add_child_s(lock_red) key_red.add_lock_s(lock_red) key_blue.add_child_s(lock_blue) key_blue.add_lock_s(lock_blue) key_green.add_child_s(lock_green) key_green.add_lock_s(lock_green) key_yellow.add_child_s(lock_yellow) key_yellow.add_lock_s(lock_yellow) positions_map = { start: np.array([0, 4]), key_red: np.array([0, 5]), lock_red: np.array([0, 3]), key_blue: np.array([0, 2]), lock_blue: np.array([0, 6]), key_green: np.array([0, 7]), lock_green: np.array([0, 1]), key_yellow: np.array([0, 0]), lock_yellow: np.array([0, 8]), end: np.array([0, 9]), } level.mission = start level.positions_map = positions_map does_level_follow_mission, solution = Solver.does_level_follow_mission( level) self.assertEqual(does_level_follow_mission, True) expected_steps = [(start, []), (key_red, rM), (lock_red, 2 * lM), (key_blue, lM), (lock_blue, 4 * rM), (key_green, rM), (lock_green, 6 * lM), (key_yellow, lM), (lock_yellow, 8 * rM), (end, rM)] self.assert_steps_equal(solution.steps, expected_steps)
def generate_mission_graph(): a = Start() b = GNode([], [], "b") c = Key(name="c") d = GNode([], [], "d") e = End() f = Lock(name="f") g = GNode([], [], "g") a.add_child_s(b) a.add_child_s(c) a.add_child_s(d) b.add_child_s(e) c.add_child_s(f) c.add_child_s(g) f.add_key_s(c) c.add_lock_s(f) return a, {a, b, c, d, e, f, g}
def test_mutable_default_argument_bug(self): gnode1 = GNode("") gnode2 = GNode("") bad_node0 = GNode("BadNode0") gnode1.add_child_s(bad_node0) self.assertEqual(len(gnode2.child_s), 0) start1 = Start() start2 = Start() bad_node1 = GNode("BadNode1") start1.add_child_s(bad_node1) self.assertEqual(len(start2.child_s), 0) end1 = End() end2 = End() bad_node2 = GNode("BadNode2") end1.add_parent_s(bad_node2) self.assertEqual(len(end2.parent_s), 0) key1 = Key() key2 = Key() bad_node3 = GNode("BadNode3") key1.add_child_s(bad_node3) bad_node4 = GNode("BadNode4") key1.add_parent_s(bad_node4) self.assertEqual(len(key2.child_s), 0) self.assertEqual(len(key2.parent_s), 0) lock1 = Lock() lock2 = Lock() bad_node5 = GNode("BadNode5") lock1.add_child_s(bad_node5) bad_node6 = GNode("BadNode6") lock1.add_parent_s(bad_node6) self.assertEqual(len(lock2.child_s), 0) self.assertEqual(len(lock2.parent_s), 0)