def _move_ghost(self, g, ghost_range): if Grid.manhattan_distance(self.state.agent_pos, self.state.ghosts[g].pos) < ghost_range: if self.state.power_step > 0: self._move_defensive(g) else: self._move_aggressive(g) else: self._move_random(g)
def _select_target(rock_state, x_size): best_dist = x_size * 2 best_rock = -1 # Coord(-1, -1) for idx, rock in enumerate(rock_state.rocks): if rock.status != 0 and rock.count >= 0: d = Grid.manhattan_distance(rock_state.agent_pos, rock.pos) if d < best_dist: best_dist = d best_rock = idx # rock.pos return best_rock
def _hear_ghost(poc_state, hear_range=2): for ghost in poc_state.ghosts: if Grid.manhattan_distance(ghost.pos, poc_state.agent_pos) <= hear_range: return True return False