def run(self): i = 0 while True: if i % 5 == 0: self.sendMessage(ServerMessageTypes.MOVEFORWARDDISTANCE, {'Amount': 5}) message = self.readMessage() field.update(message) if abs(self.last_X - self.X) > 1 and abs( self.last_Y - self.Y) > 1 and self.last_X != 0. and self.last_Y != 0.: print("{} {} {}".format(self.name, self.last_X, self.X)) break if i % 20 == 0: self.last_X = self.X self.last_Y = self.Y i += 1 print("Game has started") self.sendMessage(ServerMessageTypes.STOPALL) while self.is_running: message = self.readMessage() field.update(message) turret = 0 self.sendMessage(ServerMessageTypes.TOGGLETURRETRIGHT, {'Amount': turret}) turret = (turret + 60) % 360 self.last_turret_update = time.time() if self.start_rotating: new_degree = rotate_head(self.X, self.Y, 0., 0.) logging.info( "{} Getting close to the circle to degree {} ".format( self.name, new_degree)) self.sendMessage(ServerMessageTypes.TURNTOHEADING, {'Amount': (-new_degree + 360) % 360}) self.sendMessage(ServerMessageTypes.TOGGLEFORWARD) self.start_rotating = False self.is_rotating = True if self.is_rotating: if self.X**2 + self.Y**2 <= 25**2.: self.sendMessage(ServerMessageTypes.STOPMOVE) self.rotateByDeg(90) time.sleep(1.3) self.is_rotating = False self.is_rotating_2 = True self.toggleForward() if self.is_rotating_2: self.rotateByDeg(-10)
def rotateToShoot(self): if self.hooked_objective: new_x = self.X + math.cos(deg2rad(self.heading)) * 2 new_y = self.Y + math.sin(deg2rad(self.heading)) * 2 x_enemy, y_enemy, _, heading_enemy = field.enemies[ self.hooked_objective][:4] logging.info("{} Objective: {} {}".format(self.name, x_enemy, y_enemy)) x_enemy2 = x_enemy + math.cos(deg2rad(heading_enemy)) * 2 y_enemy2 = y_enemy + math.sin(deg2rad(heading_enemy)) * 2 degree = rotate_head(new_x, new_y, x_enemy2, y_enemy2) degree = (-degree) % 360 logging.info("{} OOOOOOOOOOOOOOOOOOO {} {}".format( self.name, x_enemy, x_enemy2)) self.sendMessage(ServerMessageTypes.TURNTURRETTOHEADING, {'Amount': degree})
def run(self): i = 0 while True: if i % 5 == 0: self.sendMessage(ServerMessageTypes.MOVEFORWARDDISTANCE, {'Amount': 5}) message = self.readMessage() logging.debug(message) field.update(message) if abs(self.last_X - self.X) > 1 and abs( self.last_Y - self.Y) > 1 and self.last_X != 0. and self.last_Y != 0.: print("{} {} {}".format(self.name, self.last_X, self.X)) break if i % 20 == 0: self.last_X = self.X self.last_Y = self.Y i += 1 self.sendMessage(ServerMessageTypes.STOPALL) while self.is_running: message = self.readMessage() field.update(message) logging.info(message) turret = 0 self.sendMessage(ServerMessageTypes.TOGGLETURRETRIGHT, {'Amount': turret}) turret = (turret + 60) % 360 self.last_turret_update = time.time() if self.start_rotating: new_degree = rotate_head(self.X, self.Y, 0., 0.) logging.info( "{} Getting close to the circle to degree {} ".format( self.name, new_degree)) self.rotateByDeg((-new_degree + 360 % 360), absolute=False) self.sendMessage(ServerMessageTypes.TURNTOHEADING, {'Amount': (-new_degree + 360) % 360}) self.sendMessage(ServerMessageTypes.TOGGLEFORWARD) self.start_rotating = False self.is_rotating = True if self.is_rotating: if self.X**2 + self.Y**2 <= 25**2.: self.sendMessage(ServerMessageTypes.STOPMOVE) self.rotateByDeg(90) time.sleep(1.3) self.is_rotating = False self.keep_rotating = True self.toggleForward() if self.keep_rotating: self.rotateByDeg(-10) if len(field.enemies) and self.ammo: self.hooked = random.choice(list(field.enemies.keys())) if self.hooked in field.enemies: self.stopRotationStrategy() x_enemy, y_enemy = field.enemies[self.hooked] new_degree = rotate_head(self.X, self.Y, x_enemy, y_enemy) self.sendMessage(ServerMessageTypes.TURNTURRETTOHEADING, {'Amount': (-new_degree + 360) % 360}) self.stopMoving() self.keep_rotating = False dist = distance(self.X, self.Y, x_enemy, y_enemy) dist = min(dist - 10, 0) self.moveForward(dist) if self.ammo > 0: self.shoot() # # self.toggleForward() #else: # self.hooked == False # self.start_rotating = True logging.info("My ammo {}".format(self.ammo)) if self.ammo == 0: if not self.hooked or self.hooked not in field.pickup: self.hooked = False ammo_pickups = list( filter(lambda x: x[0] == 'Ammo', field.pickup)) if len(ammo_pickups) > 0: self.stopRotationStrategy() self.hooked = min(ammo_pickups, key=lambda x: (x[1] - self.X)**2 + (x[2] - self.Y)**2) logging.info("Found available ammo: {} {}".format( self.hooked[1], self.hooked[2])) #self.rotateByDeg(hooked_deg) self.stopMoving() self.toggleForward() else: hooked_deg = rotate_head(self.X, self.Y, self.hooked[1], self.hooked[2]) self.rotateByDeg((-hooked_deg + 360) % 360, absolute=True)
def updateHook(self): if self.hooked: x_coord, y_coord = field.enemies[self.hooked] self.rotateTurretByDeg(-rotate_head(self.X, self.Y, x_coord, y_coord), absolute=True)
def moveTo(self, new_x, new_y): degree = rotate_head(self.X, self.Y, new_x, new_y) dist = distance(self.X, self.Y, new_x, new_y) self.rotateByDeg(-degree, absolute=True) self.moveForward(dist)
def goCircle(self, index, radius = 40, speed = 1): targetX, targetY = self.getOffsetInAngle(0, 0, radius, (time.time() * 10*speed + index*90) % 360) new_degree = rotate_head(self.X, self.Y, targetX, targetY) self.rotateByDeg(-new_degree, absolute=True)
def run(self): i = 0 while self.respawn: if i % 5 == 0: self.sendMessage(ServerMessageTypes.MOVEFORWARDDISTANCE, {'Amount': 5}) message = self.readMessage() logging.debug(message) field.update(message, self.index) if abs(self.last_X - self.X) > 1 and abs(self.last_Y - self.Y) > 1 and self.last_X != 0. and self.last_Y != 0.: print("{} {} {}".format(self.name, self.last_X, self.X)) self.respawn = False self.start_rotating = True break if i % 20 == 0: self.last_X = self.X self.last_Y = self.Y i += 1 self.sendMessage(ServerMessageTypes.STOPALL) while self.is_running: message = self.readMessage() field.update(message, self.index) self.updateHook() #logging.info(message) if self.kill_ctr > 0: # TODO: change threshold if abs(self.Y) > 98 and abs(self.X) < 20: self.is_banking = False logging.info("Banked") self.kill_ctr = 0 self.start_rotating = True self.stopAll() else: if not self.is_banking: logging.info("{} Banking...".format(self.name)) self.stopAll() self.is_banking = True self.stopRotationStrategy() destination = min([(0, -100), (0, 100)], key=lambda x: distance(self.X, self.Y, x[0], x[1])) degree = rotate_head(self.X, self.Y, destination[0], destination[1]) logging.info("{} {}".format(self.name, destination)) self.rotateByDeg(-degree, absolute=True) self.toggleForward() self.is_banking = True if self.start_rotating: new_degree = rotate_head(self.X, self.Y, 0, 0) logging.info("{} going to the center".format(self.name)) self.rotateByDeg(-new_degree, absolute=True) self.sendMessage(ServerMessageTypes.TOGGLEFORWARD) self.start_rotating = False self.is_rotating = True if self.is_rotating: if self.X**2 + self.Y**2 <= 25**2.: self.sendMessage(ServerMessageTypes.STOPMOVE) self.rotateByDeg(90) time.sleep(1.3) self.is_rotating = False self.keep_rotating = True self.toggleForward() if self.keep_rotating: logging.info("{} Rotating".format(self.name)) #self.rotateByDeg(-10) self.goCircle(self.index) if not self.hooked: self.radarTurret() if len(field.enemies) and self.ammo: closest_enemy = min(field.enemies.keys(), key=lambda x: distance(self.X, self.Y, field.enemies[x][0], field.enemies[x][1])) # hook if distance < 60 if distance(self.X, self.Y, field.enemies[closest_enemy][0], field.enemies[closest_enemy][1]) < 80: self.hookTo(closest_enemy) logging.info("{} hooked!".format(self.name)) if self.hooked in field.enemies: x_enemy, y_enemy = field.enemies[self.hooked] # Unhook for big distances if distance(self.X, self.Y, x_enemy, y_enemy) > 60: self.unhook() else: self.shoot() if self.ammo == 0: if not self.pickup_object or self.pickup_object not in field.ammo_pickups: self.pickup_object = None if len(field.ammo_pickups) > 0: self.stopRotationStrategy() closest_ammo_pickup = min(field.ammo_pickups, key=lambda x: distance(self.X, self.Y, x[0], x[1])) logging.info("Found available ammo: {}".format(closest_ammo_pickup)) self.pickup(closest_ammo_pickup)
def rotateTurretTo(self, new_x, new_y): new_degree = rotate_head(self.X, self.Y, new_x, new_y) new_degree = (-new_degree) % 360 self.sendMessage(ServerMessageTypes.TURNTURRETTOHEADING, {'Amount': new_degree})
def rotateTo(self, new_x, new_y): new_degree = rotate_head(self.X, self.Y, new_x, new_y) self.rotateByDeg(-new_degree, absolute=True)