示例#1
0
 def dynamic(current_angle):
     if abs(current_angle) > 0.6:
         return False
     my_speed = course.rotate(current_angle) * context.speed.norm()
     my_line = Line(context.position, context.position + my_speed)
     for unit in all_units:
         if unit.speed.norm() == 0:
             continue
         unit_line = Line(unit.position, unit.position + unit.speed)
         intersection = my_line.intersection(unit_line)
         if intersection is None:
             continue
         if not is_in_world(intersection, world_tiles, tile_size):
             continue
         if is_in_empty_tile(intersection, world_tiles, tile_size):
             continue
         unit_dir = intersection - unit.position
         if unit_dir.norm() == 0 or unit_dir.cos(unit.speed) < 0:
             continue
         if unit_dir.norm() > my_speed.norm() * 100:
             continue
         my_dir = intersection - context.position
         if my_dir.norm() == 0 or my_dir.cos(my_speed) < 0:
             continue
         unit_time = unit_dir.norm() / unit.speed.norm()
         my_time = my_dir.norm() / my_speed.norm()
         if abs(my_time - unit_time) <= MY_INTERVAL:
             return True
     return False
示例#2
0
 def generate():
     for car in context.opponents_cars:
         car_position = Point(car.x, car.y)
         car_speed = Point(car.speed_x, car.speed_y)
         car_barriers = list(make_units_barriers([car]))
         distance = (context.position - car_position).norm()
         if car_speed.norm() < 1:
             yield (not has_intersection_with_tiles(distance) and
                    make_has_intersection_with_lane(
                        position=context.position,
                        course=tire_speed * 50,
                        barriers=car_barriers,
                        width=context.game.tire_radius,
                    )(0))
         else:
             car_line = Line(car_position, car_position + car_speed)
             tire_line = Line(context.position,
                              context.position + tire_speed)
             intersection = tire_line.intersection(car_line)
             if intersection is None:
                 continue
             if not is_in_world(intersection, world_tiles, tile_size):
                 continue
             if is_in_empty_tile(intersection, world_tiles, tile_size):
                 continue
             car_dir = intersection - car_position
             if car_dir.norm() > 0 and car_dir.cos(car_speed) < 0:
                 continue
             if car_dir.norm() > context.game.tire_initial_speed * 50:
                 continue
             tire_dir = intersection - context.position
             if tire_dir.norm() > 0 and tire_dir.cos(tire_speed) < 0:
                 continue
             if has_intersection_with_tiles(tire_dir.norm()):
                 continue
             car_time = car_dir.norm() / car_speed.norm()
             tire_time = tire_dir.norm() / tire_speed.norm()
             if abs(car_time - tire_time) <= TIRE_INTERVAL:
                 yield True
示例#3
0
 def generate():
     for car in context.opponents_cars:
         car_position = Point(car.x, car.y)
         car_speed = Point(car.speed_x, car.speed_y)
         car_barriers = list(make_units_barriers([car]))
         if car_speed.norm() < 1:
             for washer in washers:
                 yield make_has_intersection_with_lane(
                     position=washer.position,
                     course=washer.speed * 150,
                     barriers=car_barriers,
                     width=context.game.washer_radius,
                 )(0)
         else:
             car_line = Line(car_position, car_position + car_speed)
             for washer in washers:
                 washer_line = Line(washer.position,
                                    washer.position + washer.speed)
                 intersection = washer_line.intersection(car_line)
                 if intersection is None:
                     continue
                 if not is_in_world(intersection, world_tiles, tile_size):
                     continue
                 if is_in_empty_tile(intersection, world_tiles, tile_size):
                     continue
                 car_dir = intersection - car_position
                 if car_dir.norm() > 0 and car_dir.cos(car_speed) < 0:
                     continue
                 if car_dir.norm() > washer_speed * 150:
                     continue
                 washer_dir = intersection - washer.position
                 if (washer_dir.norm() > 0 and
                         washer_dir.cos(washer.speed) < 0):
                     continue
                 car_time = car_dir.norm() / car_speed.norm()
                 washer_time = washer_dir.norm() / washer.speed.norm()
                 if abs(car_time - washer_time) <= WASHER_INTERVAL:
                     yield True