def main(): test_state = GameState.BlindSearchGameState([1, 1], [2, 2], None, 5) test_state2 = GameState.BlindSearchGameState([1, 1], [2, 2], None, 5) print(test_state == test_state2) test_list = [test_state] test_list2 = [test_state] print(test_state2 in test_list) test_func(test_list) print(test_list[0].move_count) print(test_list2[0].move_count)
def depth_first_search(self): self.number_of_searches = 0 cat_pos = self.cat.init_pos count = 0 mouse_pos = self.mouse_path[count] dfs_stack = [ GameState.BlindSearchGameState(self.mouse_path[count], cat_pos, None, 0) ] cat_path = [cat_pos] visited_state = [] while len(dfs_stack) > 0: self.number_of_searches += 1 current_state = dfs_stack.pop(len(dfs_stack) - 1) count = current_state.move_count visited_state.append(current_state) possible_moves = self.cat_manager.get_all_possible_moves( current_state.cat) # print(self.number_of_searches) if len(possible_moves) > 0 and 0 <= count < len( self.mouse_path) - 1: game_state = None count += 1 mouse_pos = self.mouse_path[count] for cat_pos in possible_moves: game_state = GameState.BlindSearchGameState( mouse_pos, cat_pos, current_state, count) if game_state not in visited_state: dfs_stack.append(game_state) if current_state.cat == current_state.mouse_pos and not current_state.mouse_pos == self.mouse_path[ len(self.mouse_path) - 1]: self.game_map.game_over = True break elif self.number_of_searches >= MAX_BLIND_SEARCHES and MAX_BLIND_SEARCHES != -1 and not current_state.cat == current_state.mouse_pos and current_state.mouse_pos == self.mouse_path[ len(self.mouse_path) - 1]: break while not current_state.parent_state == None: cat_path.insert(1, current_state.cat) current_state = current_state.parent_state return cat_path