def score_tank(self, tank): """Score tank.""" my_base = self.team.base.center if tank.flag: ebase = tank.flag.team.base dist_to = collisiontest.get_dist(my_base, tank.flag.team.base.center) dist_back = collisiontest.get_dist(tank.pos, my_base) more = 100.0 * (dist_to - dist_back)/dist_to if dist_back > dist_to: more = 0 self.setValue(500 + more) else: closest = None for color,team in self.team.map.teams.items(): if team is self.team: continue dst = collisiontest.get_dist(tank.pos, team.base.center) if closest is None or dst < closest[0]: closest = dst, team.base if not closest: logger.warning("no closest found... %s" % self.team.color) return False total_dist = collisiontest.get_dist(my_base, closest[1].center) dist_to = collisiontest.get_dist(tank.pos, closest[1].center) if dist_to > total_dist: return self.setValue(100.0 * (total_dist-dist_to)/total_dist)
def score_tank(self, tank): """Score tank.""" my_base = self.team.base.center if tank.flag: ebase = tank.flag.team.base dist_to = collisiontest.get_dist(my_base, tank.flag.team.base.center) dist_back = collisiontest.get_dist(tank.pos, my_base) more = 100.0 * (dist_to - dist_back) / dist_to if dist_back > dist_to: more = 0 self.setValue(500 + more) else: closest = None for color, team in self.team.map.teams.items(): if team is self.team: continue dst = collisiontest.get_dist(tank.pos, team.base.center) if closest is None or dst < closest[0]: closest = dst, team.base if not closest: logger.warning("no closest found... %s" % self.team.color) return False total_dist = collisiontest.get_dist(my_base, closest[1].center) dist_to = collisiontest.get_dist(tank.pos, closest[1].center) if dist_to > total_dist: return self.setValue(100.0 * (total_dist - dist_to) / total_dist)
def closest_base(self, pos): """Returns position of clossest base.""" items = tuple(sorted((collisiontest.get_dist(pos, base.center), base) for base in self.bases.values())) if abs(items[0][0] - items[1][0]) < 50: return None return items[0][1]
def closest_base(self, pos): """Returns position of clossest base.""" items = tuple( sorted((collisiontest.get_dist(pos, base.center), base) for base in self.bases.values())) if abs(items[0][0] - items[1][0]) < 50: return None return items[0][1]