示例#1
0
def generate_cars_barriers(context: Context):
    def use(car: Car):
        car_speed = Point(car.speed_x, car.speed_y)
        return (car.id != context.me.id and
                (context.speed.norm() > CAR_SPEED_FACTOR * car_speed.norm() or
                 context.speed.norm() > 0 and
                 (car_speed.norm() > 0 and
                  abs(context.speed.cos(car_speed)) < cos(1) or
                  car_speed.norm() == 0)))

    return make_units_barriers(filter(use, context.world.cars))
示例#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
示例#4
0
def generate_opponents_cars_barriers(context: Context):
    return make_units_barriers(context.opponents_cars)
示例#5
0
def generate_oil_slicks_barriers(context: Context):
    return make_units_barriers(context.world.oil_slicks)
示例#6
0
def generate_projectiles_barriers(context: Context):
    return make_units_barriers(context.world.projectiles)