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
def move(self, me: Player, world: World, game: Game, move: Move): if world.tick_index == 0: move.action = ActionType.CLEAR_AND_SELECT move.right = world.width move.bottom = world.height if world.tick_index == 1: move.action = ActionType.MOVE move.x = world.width / 2.0 move.y = world.height / 2.0
def move(self, me: Player, world: World, game: Game, move: Move): self.map.update(world.new_vehicles, world.vehicle_updates) if world.tick_index == 0: move.action = ActionType.CLEAR_AND_SELECT move.right = world.width move.bottom = world.height if world.tick_index == 1: move.action = ActionType.MOVE move.x = world.width / 1.0 move.y = world.height / 2.0
def do_nuke(s: MyStrategy, w: World, g: Game, m: Move): m.action = ActionType.TACTICAL_NUCLEAR_STRIKE m.x = target.x m.y = target.y m.vehicle_id = navigator
def do_scale(s: MyStrategy, w: World, g: Game, m: Move): m.action = ActionType.SCALE m.factor = factor m.x = center.x m.y = center.y
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
def do_rotate(s: MyStrategy, w: World, g: Game, m: Move): m.action = ActionType.ROTATE m.angle = angle m.max_angular_speed = max_speed m.x = center.x m.y = center.y
def expand(self, move: Move, x: float, y: float): move.action = ActionType.SCALE move.x = x move.y = y move.factor = 1.5
def moveToPoint(self, targetX, targetY, me: Trooper, world: object, game: Game, move: Move): cells = world.cells offsetX = 0 if me.x > targetX: offsetX = -1 elif me.x < targetX: offsetX = 1 else: offsetX = 0 offsetY = 0 if me.y > targetY: offsetY = -1 elif me.y < targetY: offsetY = 1 else: offsetY = 0 x = -1 y = -1 canMoveToPoint = False if offsetX != 0: x = me.x + offsetX y = me.y elif offsetY != 0: x = me.x y = me.y + offsetY for bonus in world.bonuses: if bonus.x == x and bonus.y == y: canMoveToPoint = True canMoveX = offsetX != 0 and cells[me.x + offsetX][me.y] == CellType.FREE canMoveY = offsetY != 0 and cells[me.x][me.y + offsetY] == CellType.FREE canMoveX = canMoveX or canMoveToPoint canMoveY = canMoveY or canMoveToPoint if canMoveX or canMoveY: move.action = ActionType.MOVE if canMoveX and canMoveY: if randint(0, 9) % 2 == 0: move.x = me.x + offsetX move.y = me.y else: move.x = me.x move.y = me.y + offsetY elif canMoveX: move.x = me.x + offsetX move.y = me.y else: move.x = me.x move.y = me.y + offsetY else: print('Recalculate direction') quarter = 0 if me.x > targetX and me.y < targetY: quarter = 1 elif me.x > targetX and me.y > targetY: quarter = 2 elif me.x < targetX and me.y > targetY: quarter = 3 elif me.x < targetX and me.y < targetY: quarter = 4 if quarter == 1: offsetX = 1 offsetY = -1 elif quarter == 2: offsetX = 1 offsetY = 1 elif quarter == 3: offsetX = -1 offsetY = 1 elif quarter == 4: offsetX = -1 offsetY = -1 if offsetX != 0: x = me.x + offsetX y = me.y elif offsetY != 0: x = me.x y = me.y + offsetY canMoveX = offsetX != 0 and cells[me.x + offsetX][me.y] == CellType.FREE canMoveY = offsetY != 0 and cells[me.x][me.y + offsetY] == CellType.FREE #if not canMoveX and not canMoveY: #self.moveToPoint(targetX + randint(0, 9) % 2, targetY + randint(0, 9) % 2, me, world, game, move) #return if canMoveX or canMoveY: print('Can move new direction') move.action = ActionType.MOVE if canMoveX and canMoveY: if randint(0, 9) % 2 == 0: move.x = me.x + offsetX move.y = me.y else: move.x = me.x move.y = me.y + offsetY elif canMoveX: move.x = me.x + offsetX move.y = me.y else: move.x = me.x move.y = me.y + offsetY
def throwGrenade(self, trooper : Trooper, move : Move): move.action = ActionType.THROW_GRENADE move.x = trooper.x move.y = trooper.y
def heal(self, trooper : Trooper, move : Move): move.action = ActionType.HEAL move.x = trooper.x move.y = trooper.y print('Солдат полечил')
def shootTrooper(self, trooper : Trooper, move : Move, game : Game, me : Trooper): move.action = ActionType.SHOOT move.x = trooper.x move.y = trooper.y