def steer(self, mytanks, num, goal): desired_angle = self.angle( mytanks.position(num), self.generate_field_function( 150, goal)) #, r.Obstacles().get_Obstacles())) angadj = self.angveladj(mytanks.angle(num), mytanks.angvel(num), desired_angle) r.Angvel(num, angadj)
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 dumbagent(self, num1, num2): mytanks = r.Mytanks() desired_angle = 1 for idx in range(len(mytanks.list)): r.Speed(idx, 0) r.Angvel(idx, 0) 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 while True: start = time.time() straight(desired_angle, start) desired_angle += 1 if desired_angle < math.pi: desired_angle = desired_angle % math.pi else: desired_angle = -1 * (desired_angle % math.pi) print "desired" print desired_angle turn(desired_angle, start)
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