def test_equivalent_states(self): state1 = SimulatorState(2) state1.add_item_to_floor('HM', 0) state1.add_item_to_floor('HG', 1) state1.add_item_to_floor('LiG', 1) state1.add_item_to_floor('LiM', 2) state2 = SimulatorState(2) state2.add_item_to_floor('LiG', 1) state2.add_item_to_floor('LiM', 0) state2.add_item_to_floor('HG', 1) state2.add_item_to_floor('HM', 2) self.assertTrue(SimulatorState.equivalent_states(state1, state2))
def test_different_states(self): state1 = SimulatorState(3) state1.add_item_to_floor('CM', 2) state1.add_item_to_floor('AG', 3) state1.add_item_to_floor('BG', 3) state1.add_item_to_floor('CG', 3) state1.add_item_to_floor('AM', 3) state1.add_item_to_floor('BM', 3) state2 = SimulatorState(3) state2.add_item_to_floor('BM', 2) state2.add_item_to_floor('CM', 2) state2.add_item_to_floor('AG', 3) state2.add_item_to_floor('BG', 3) state2.add_item_to_floor('CG', 3) state2.add_item_to_floor('AM', 3) self.assertFalse(SimulatorState.equivalent_states(state1, state2))
def update_state_simple_states(self, step_count: int, state: SimulatorState): equiv_state = None found_equivalent = False for seen_state in self.seen_states: if SimulatorState.equivalent_states(seen_state, state): found_equivalent = True equiv_state = seen_state if found_equivalent: if self.seen_states[equiv_state] > step_count: self.seen_states[equiv_state] = step_count else: self.seen_states[state] = step_count self.new_states[state] = step_count heuristic = self.calculate_heuristic(state) if heuristic in self.heuristic_value_map: self.heuristic_value_map[heuristic].append(state) else: self.heuristic_value_map[heuristic] = [state]