def shoot_em(self, tank): my_position = Point(tank.x, tank.y) for enemy in self.enemies: enemy_position = Point(enemy.x, enemy.y) if my_position.distance(enemy_position) <= 50: theta = self.fields.angle(tank,enemy) if theta < 1.5 and theta > -1.5: line_to_enemy = Line(my_position, enemy_position) safe = True for teamMate in self.mytanks: if teamMate.index == tank.index: continue teamMate_position = Point(teamMate.x, teamMate.y) cp2 = teamMate_position.closestPointOnLine(line_to_enemy) teamMate_enemy_line = Line(teamMate_position, cp2) if teamMate_position.distance(cp2) < 10: safe = False break if safe == True: return True return False
def shoot_em(self, tank): my_position = Point(tank.x, tank.y) for enemy in self.enemies: enemy_position = Point(enemy.x, enemy.y) if my_position.distance(enemy_position) <= 50: theta = self.fields.angle(tank, enemy) if theta < 1.5 and theta > -1.5: line_to_enemy = Line(my_position, enemy_position) safe = True for teamMate in self.mytanks: if teamMate.index == tank.index: continue teamMate_position = Point(teamMate.x, teamMate.y) cp2 = teamMate_position.closestPointOnLine( line_to_enemy) teamMate_enemy_line = Line(teamMate_position, cp2) if teamMate_position.distance(cp2) < 10: safe = False break if safe == True: return True return False
def tick(self): self.commands = [] curtime = time.time() self.mytanks = self.bzrc.get_mytanks() for tank in self.mytanks: curLocation = Point(tank.x, tank.y) target = self.locationList[tank.index] if curLocation.distance(target) < 10: target = self.getRandomCoordinate(tank.index) while self.grid.get(target.x, target.y) > .95: target = self.getRandomCoordinate(tank.index) self.locationList[tank.index] = target self.oldlocation[tank.index] = curLocation self.goToPoint(tank, target) if(curtime - self.time > 4.25 ): for tank in self.mytanks: command = Command(tank.index,0,0,False) self.commands = [] self.commands.append(command) self.bzrc.do_commands(self.commands) self.commands = [] self.getObservation(tank) self.time = time.time()
def tick(self): if(self.ticks < 10): pass if self.tank.status == "dead": return self.commands = [] curtime = time.time() curLocation = Point(self.tank.x, self.tank.y) target = self.locationList[self.tank.index] if curLocation.distance(target) < 10: target = self.getRandomCoordinate(self.tank.index) while self.grid.get(target.x, target.y) > .95: target = self.getRandomCoordinate(self.tank.index) self.locationList[self.tank.index] = target self.oldlocation[self.tank.index] = curLocation self.goToPoint(self.tank, target) if(curtime - self.time > 2.25 ): command = Command(self.tank.index,0,0,False) self.commands = [] self.commands.append(command) self.bzrc.do_commands(self.commands) self.commands = [] self.getObservation(self.tank) self.time = time.time()
def kalmanCommand(self, totalX, totalY, theta, shoot, tank): p = Point(tank.x, tank.y) for obstacle in self.obstacles: if (p.distance(obstacle) < 50): deltaX, deltaY = self.fields.getTangentialField2( self.tank, obstacle, 100, 40, "CW") totalX = deltaX totalY = deltaY theta = math.atan2(totalY, totalX) theta = self.normalize_angle(theta - tank.angle) speed = math.sqrt(totalY**2 + totalX**2) self.commands = [] command = Command(tank.index, .15 * speed, 1.15 * theta, True) self.commands.append(command) self.bzrc.do_commands(self.commands) self.commands = []
def kalmanCommand(self,totalX,totalY,theta,shoot,tank): p = Point(tank.x,tank.y) for obstacle in self.obstacles: if(p.distance(obstacle) < 50): deltaX,deltaY = self.fields.getTangentialField2(self.tank,obstacle, 100, 40,"CW") totalX = deltaX totalY = deltaY theta = math.atan2(totalY,totalX) theta = self.normalize_angle(theta-tank.angle) speed = math.sqrt(totalY**2+totalX**2) self.commands = [] command = Command(tank.index,.15*speed,1.15*theta,True) self.commands.append(command) self.bzrc.do_commands(self.commands) self.commands = []