Exemplo n.º 1
0
    def function(x, y):
        '''User-defined field function.'''

        pos=array([x,y])

        v1=PF.attractiveField(pos,goal,False)								# seems to work fine
        v2=PF.randomField()												# seems to work fine
        v3=PF.getTotalRepulsive(pos,obstacles,bullets,otherTanks,myTanks)# returning [0,0] even though its finding the objects
        v4=PF.getTotalTangential(pos,obstacles,bullets,otherTanks,myTanks)#UnboundLocalError: local variable 'distObstacle' referenced before assignment

        x2=array([v1[0]+v2[0]+v3[0]+v4[0],v1[1]+v2[1]+v3[1]+v4[1]])
        #x2=v1+v2+v3
        x2=array([v1[0],v1[1]])
#        x2 = array(v1)
#        x2 = array(v2)
#        x2 = array(v3)
#        x2 = array(v4)
        
        return x2
Exemplo n.º 2
0
    def update(self, deltaTime):

		if not self.hasFlag and self.client.getMyTanks()[self.tank].flag:
			newG =[0,0]
			for i in self.client.getBases()[self.team].verts:
				newG+=i
			self.goal = newG/4
			self.hasFlag=1

		elif not self.client.getMyTanks()[self.tank].flag:
			self.hasFlag=0
			self.goal=self.client.getFlags()[self.enemy].position

		self.client.shoot(self.tank)
		
		aF=PF.attractiveField(self.getPos(),self.goal,self.hasFlag)
		tF=PF.getTotalTangential(self.position, self.client.getObstacles(), self.client.getShots(), self.client.getOtherTanks(), self.client.getMyTanks())
		rF=PF.getTotalRepulsive(self.position, self.client.getObstacles(), self.client.getShots(), self.client.getOtherTanks(), self.client.getMyTanks())
		randF=PF.randomField()

		a=.1
		ALL_FIELDS=array([aF[0]+a*tF[0]+a*rF[0]+randF[0],aF[1]+a*tF[1]+a*rF[1]+randF[1]])




		theta=self.PDController(ALL_FIELDS, deltaTime)
		

		theta= theta*float(self.client.getConstants()['tankangvel'])

		if theta<-1:
			theta=-1
		elif theta>1:
			theta=1	


		print theta

		self.client.setAngvel(self.tank,theta)
		self.client.setSpeed(self.tank,1)