def move(self): ''' if (r.position[1], self.position[1]) in {(0, 1), (24, 23)} and abs(self.position[0] - r.position[0]) == 1: self.position = r.position if (r.position[0], self.position[0]) in {(0, 1), (24, 23)} and abs(self.position[1] - r.position[1]) == 1: self.position = r.position ''' if algorithms.see_each_other(self.position, r.position, position_matrix): path = algorithms.minimal_distance(self.position, r.position, position_matrix) self.position = path[-1] self.rabbit_last_seen = r.position elif self.rabbit_last_seen != None and self.rabbit_last_seen != self.position: path = algorithms.minimal_distance(self.position, r.position, position_matrix) self.position = path[-1] else: options = [] for (dx, dy) in [(0, 1), (1, 0), (-1, 0), (0, -1)]: curr_position = (self.position[0] + dx, self.position[1] + dy) if outOffBoundaries(curr_position) or isCollision( curr_position): continue options.append(curr_position) self.position = random.choice(options)
def move(self): self.prev_steps.append(self.position) p = random.randrange(0, 1000) if number_of_steps > 10 and self.position == self.prev_steps[-9]: p = 0 if p > 10 and algorithms.see_each_other(self.position, r.position, position_matrix): path = algorithms.minimal_distance(self.position, r.position, position_matrix) self.position = path[-1] self.rabbit_last_seen = r.position elif p > 10 and self.rabbit_last_seen != None and self.rabbit_last_seen != self.position: path = algorithms.minimal_distance(self.position, r.position, position_matrix) self.position = path[-1] else: options = [] for (dx, dy) in [(0, 1), (1, 0), (-1, 0), (0, -1)]: curr_position = (self.position[0] + dx, self.position[1] + dy) if outOffBoundaries(curr_position) or isCollision( curr_position): continue if len(self.prev_steps ) > 1 and curr_position == self.prev_steps[-2]: continue options.append(curr_position) self.position = random.choice(options)