Exemple #1
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
Exemple #2
0
    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)
Exemple #3
0
        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
Exemple #4
0
        def animate(i):
            mytanks = r.Mytanks()
            for num in range(len(mytanks.list)):
                occgrid = r.Occgrid(num)
                world.update(occgrid.corner(), occgrid.grid())

                #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(3)

                self.steer(mytanks, num, goal)
                #r.Shoot(num)

            return plt.imshow(world.world,
                              aspect=None,
                              cmap=cm.YlGnBu,
                              interpolation="none")
Exemple #5
0
    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)