Ejemplo n.º 1
0
 def new_move(self,
              action=None,
              group=0,
              x_range=(0.0, WORLD_WIDTH),
              y_range=(0.0, WORLD_HEIGHT),
              vector=(0.0, 0.0),
              angle=0.0,
              factor=0.0,
              max_speed=0.0,
              max_angular_speed=0.0,
              vehicle_type=None,
              facility_id=-1,
              vehicle_id=-1):
     m = Move()
     m.action = action
     m.group = group
     m.left, m.right = x_range
     m.top, m.bottom = y_range
     m.x, m.y = vector
     m.angle = angle
     m.factor = factor
     m.max_speed = max_speed
     m.max_angular_speed = max_angular_speed
     m.vehicle_type = vehicle_type
     m.facility_id = facility_id
     m.vehicle_id = vehicle_id
     return m
Ejemplo n.º 2
0
    def move_forward(self, move: Move):
        enemy_vehicle = min(
            (vehicle for vehicle in self.enemy_vehicles.values()),
            key=(lambda vehicle: vehicle.get_distance_to(self.my_x, self.my_y)),
        )
        x, y = enemy_vehicle.x, enemy_vehicle.y

        # Nuclear strike logic.
        if (
            self.me.remaining_nuclear_strike_cooldown_ticks == 0 and
            enemy_vehicle.get_distance_to(self.my_x, self.my_y) > self.r
        ):
            vehicle, distance = min(
                self.get_vehicles_with_distance_to(self.my_vehicles.values(), enemy_vehicle),
                key=itemgetter(1),
            )
            if distance < self.get_vision_range(vehicle):
                print('[{}] TACTICAL NUCLEAR STRIKE!'.format(self.world.tick_index))
                move.action = ActionType.TACTICAL_NUCLEAR_STRIKE
                move.vehicle_id = vehicle.id
                move.x = enemy_vehicle.x
                move.y = enemy_vehicle.y
                return

        move.action = ActionType.MOVE
        move.max_speed = self.get_max_speed()
        if self.me.score > self.world.get_opponent_player().score:
            # We're winning. Why take a risk? Slowly go away.
            move.x = -(x - self.my_x)
            move.y = -(y - self.my_y)
            move.max_speed = 0.01
        elif (
            self.attack_ratio >= 1.0 or
            enemy_vehicle.get_distance_to(self.my_x, self.my_y) > self.r + 20.0 or
            self.world.tick_index > 19000
        ):
            # We have enough vehicles or opponent is too far away, let's attack!
            move.x = x - self.my_x
            move.y = y - self.my_y
        else:
            # We're losing the battle. Let's move left-right until something good happens.
            move.x = y - self.my_y
            move.y = -(x - self.my_x)
            if getrandbits(1):
                move.x = -move.x
                move.y = -move.y
Ejemplo n.º 3
0
 def do_move(s: MyStrategy, w: World, g: Game, m: Move):
     m.action = ActionType.MOVE
     m.x = destination.x
     m.y = destination.y
     #print("Moving to: " + str(destination.x) + ":" + str(destination.y))
     m.max_speed = max_speed