def straight(desired_angle, start): r.Speed(num1, 1) r.Speed(num2, 1) while True: mytanks = r.Mytanks() angadj = self.angveladj(mytanks.angle(num1), mytanks.angvel(num1), desired_angle) r.Angvel(num1, angadj) r.Angvel(num2, angadj) end = time.time() delta_time = end - start if -.1 < delta_time % 2 < .1: r.Shoot(num1) r.Shoot(num2) if delta_time > 5: print "got out of straight" return
def turn(desired_angle, start): r.Speed(num1, 0) r.Speed(num2, 0) while True: mytanks = r.Mytanks() angadj = self.angveladj(mytanks.angle(num1), mytanks.angvel(num1), desired_angle) r.Angvel(num1, angadj) r.Angvel(num2, angadj) end = time.time() delta_angle = desired_angle - mytanks.angle(num1) # print "angle" # print desired_angle # print mytanks.angle(num) delta_time = end - start if -.1 < delta_time % 2 < .1: r.Shoot(num1) r.Shoot(num2) if -.1 < delta_angle < .1: return
def __init__(self, host, port): self.timestamp = datetime.datetime.utcnow() self.TIMEMULTIPLIER = 1 r.Request.connect(host, port) self.CONSTANTS = r.Constants().dictionary() self.bases = r.Bases() print self.CONSTANTS goal = r.Flags().index(0) fields.make_potential_fields(r.Obstacles().get_Obstacles(), int(self.CONSTANTS['worldsize']), r.Flags().index(0), self.generate_field_function(150,goal,r.Obstacles().get_Obstacles())) # for item in r.Obstacles().list: # print map(float, item[1:]) # # # # print r.Obstacles().get_Obstacles() # pdb.set_trace() while True: mytanks = r.Mytanks() for num in range(len(mytanks.list)): # num = 0 r.Speed(num, 1) # pdb.set_trace() if mytanks.flag(num) == True: goal = self.bases.center(self.CONSTANTS["team"]) else: goal = r.Flags().index(0) self.steer(mytanks, num, goal) r.Shoot(num)