def _next_line_todo(self, n_from: Node) -> Line: tmp = [] attractiveness: float = 0 for line in n_from.lines: if self._touched[line.get_next_id(n_from.position)] == 0: attractiveness += line.attractiveness tmp.append(line) if len(tmp) == 0: return n_from.find_by_id(self._map.start.ident) tmp.sort()
def _next_line(self, n_from: Node) -> Line: tmp = [] attractiveness: float = 0 for line in n_from.lines: if self._touched[line.get_next_id(n_from.position)] == 0: attractiveness += line.attractiveness tmp.append(line) if len(tmp) == 0: return n_from.find_by_id(self._map.start.ident) if attractiveness == 0: return tmp[random.randint(0, len(tmp) - 1)] if random.randint(0, 100) < self._random_factor: return tmp[random.randint(0, len(tmp) - 1)] chance = random.randint(0, 100) for line in tmp: if line.attractiveness == 0: continue chance -= int(line.attractiveness / attractiveness * 100) if chance <= 0: return line return tmp[-1]