def move(self, search_type): self.mouse_path = self.compute_mouse_path() self.search = Searches(self.mouse_path, self.game_map, self.cat) if search_type == "b": cat_path = self.search.breath_first_search() elif search_type == "d": cat_path = self.search.depth_first_search() else: cat_path = self.search.a_star_search() while len(cat_path) > 1: self.mouse.current_pos = self.mouse_path[1] if self.mouse_path[1] == self.cheese_pos[0]: self.visited_cheese_pos.append(self.cheese_pos.pop(0)) self.cheese_pos = sorted(self.cheese_pos[:], key=self.compare_by_distance) self.visited_mouse_pos.append(self.mouse_path.pop(1)) self.game_state = GameState.BasicGameState(self.mouse.current_pos, cat_path[1], self.cheese_pos) self.visited_cat_pos.append(cat_path.pop(1)) self.game_map.update(self.game_state) self.canvas.display(self.game_map) print("Mouse Initial Position ", self.mouse.init_pos) print("Mouse visited position ", self.visited_mouse_pos) print("Cat visited position", self.visited_cat_pos) print("Visited Cheese Position ", self.visited_cheese_pos) time.sleep(1)
def __init__(self, map_height=12, map_width=12, num_of_cheese=3): self.map_height = map_height self.map_width = map_width self.num_of_cheese = num_of_cheese self.visited_cheese_pos = [] self.visited_mouse_pos = [] self.visited_cat_pos = [] self.game_states = [] self.mouse_path = [] self.mouse_initial_pos = [] self.random_coordinates = [] self.generate_resources() self.cheese_pos.sort(key=self.compare_by_distance) self.game_state = GameState.BasicGameState(self.mouse.current_pos, self.cat.current_pos, self.cheese_pos) self.game_states.append(self.game_state) self.game_map = GameMap(self.game_state, map_height, map_width) self.canvas = Canvas(self.game_map)