def perform_test(self, status_dict): """Test that the heuristic on leafs is consistent with the utility""" # Build models map_obj = Map(status_dict["game"]["board"]["tiles"]) status = Status(status_dict["game"], map_obj) # Simulate a final status status.turn = status.max_turns heuristic_tuple = self.heuristic.heuristic(status) utility_tuple = utility(status) # Check that heuristic and utility are consistent for i in range(4): for j in range(4): if utility_tuple[i] > utility_tuple[j]: self.assertGreater(heuristic_tuple[i], heuristic_tuple[j]) elif utility_tuple[i] == utility_tuple[j]: self.assertAlmostEqual( heuristic_tuple[i], heuristic_tuple[j] ) else: self.assertLess(heuristic_tuple[i], heuristic_tuple[j])
def perform_test(self, status_dict): """Test that simulate returns a new object""" # Build models map_obj = Map(status_dict["game"]["board"]["tiles"]) status = Status(status_dict["game"], map_obj) original_status = status.clone() next_status = simulate(status, Action.north) if original_status != next_status: self.assertNotEqual(id(status), id(next_status))
def perform_test(self, status_dict): """Test that simulate returns a new object""" # Build models map_obj = Map(status_dict["game"]["board"]["tiles"]) status = Status(status_dict["game"], map_obj) # Simulate the last turn status.turn = status.max_turns next_status = simulate(status, Action.north) self.assertEqual(status, next_status)
def perform_test(self, status_pair): """Test simulate by comparing simulated status""" dict_before, dict_after = status_pair # Build models map_obj = Map(dict_before["game"]["board"]["tiles"]) status_before = Status(dict_before["game"], map_obj) status_after = Status(dict_after["game"], map_obj) # Get actions actions_by_hero = [status_after.heroes[i].last_dir for i in range(4)] first_hero = status_before.current_hero() # Shift actions such that first_hero is the first to move actions = actions_by_hero[first_hero:] + actions_by_hero[:first_hero] # Run simulations simulated = simulate_actions(status_before, actions) # Compare self.assertEqual( status_after, simulated, msg=( "Before:\n{before}\n" + "Actions: {actions}\n" + "After:\n{after}\n" + "Simulated:\n{sim}\n" + "Round: {b_id} {b_turn} --> {a_id} {a_turn}" ).format( before=status_before, actions=actions, after=status_after, sim=simulated, b_id=status_before.id, b_turn=status_before.turn, a_id=status_after.id, a_turn=status_after.turn, ), )