def tick(self, time_diff): """Some time has passed; decide what to do next.""" mytanks, othertanks, flags, shots = self.bzrc.get_lots_o_stuff() self.mytanks = mytanks self.flags = flags # We only care about our enemy's flag enemy_flag = None for flag in self.flags: # print("flag color: %s x: %f y: %f" % (flag.color, flag.x, flag.y)) if flag.color == self.enemy: # print("enemy found, and it is %s" % flag.color) enemy_flag = flag # Flag is the goal, so it creates an attractive field obstacles = self.bzrc.get_obstacles() fields = self.repulsive_and_tangential_fields_from_obstacles(obstacles) # fields = [] attractive_field = Field(enemy_flag.x, enemy_flag.y, 5, 300) attractive_field.kind = 'attractive' for tank in self.mytanks: # print("tank angle is %f x is %f y is %f" % (tank.angle, tank.x, tank.y)) #if this tank has the flag, then its attractive field is the home base if tank.flag == self.enemy: attractive_field = Field((self.base.corner1_x + self.base.corner3_x) / 2.0, (self.base.corner1_y + self.base.corner3_y) / 2.0, 5, 300) attractive_field.kind = 'attractive' fields.append(attractive_field) self.bzrc.angvel(tank.index, self.calculate_angvel(tank, fields)) #speed depends on how far away we are? #just ignore that for now, see if it works. self.bzrc.speed(tank.index, self.calculate_speed(tank, fields)) self.bzrc.shoot(tank.index)
def repulsive_and_tangential_fields_from_obstacles(self, obstacles): fields = [] for obstacle in obstacles: centroid = self.calculate_centroid(obstacle) radius = self.calculate_radius_from_centroid(centroid, obstacle) field = Field(centroid['x'], centroid['y'], radius, 100) field.kind = 'repulsive' fields.append(field) tan_field = Field(centroid['x'], centroid['y'], radius, 100) tan_field.kind = 'tangential' fields.append(tan_field) return fields