示例#1
0
 def __getRotatedVectors(self, vector, cos_k):
     """
     FUNCTION NOT USED IN FINAL IMPLEMENTATION
     
     This function will calculate 2 other angles that the agent can kick the ball to. If 
     the agent has calculated a direct path from itself to another keeper, that should be
     the input vector. If the agent is interested in passing at a 5 degree angle, then
     the 2nd input should be the cosine of 5 degrees. This function will then calculate 
     and return the 2 unit vectors which are the vectors pointing at 5 degree angles 
     
     :param vector: the vector that points directly from the  ball's noisy 
         position to the noisy position of the keeper the agent wants to pass to
     :param cos_k: the cosine of the angle that the agent wants to pass at. The
         reason cosine is used instead of the angle is for computational efficiency
     
     :type vector: list or tuple of numbers
     :type cos_k: number
     
     :returns: a list of 2 unit vectors, each one representing the 2 directions that
         the ball can be kicked to achieve the desired angle.
         
     :rtype: list of tuples, each tuple being a tuple of floats.
     """
     discriminantIsZero = False
     terminalPosCosZero = kUtil.addVectorToPoint(self.noisyBallPos, vector) 
     vector = kUtil.unitVector(vector)
     ax = vector[1] #columns are x
     ay = vector[0] #rows are y
     k = cos_k
     term1 = 2*k*ax #term 1 = -b 
     discriminant = term1 * term1 - 4 * (ax*ax +ay*ay)*(-1.0*ay*ay + k * k)
     discriminant = math.sqrt(discriminant)
     if (abs(discriminant) < 0.00001):
         discriminantIsZero = True
         
     #denominator = 2 * (ax*ax + ay*ay) #should be 2 every time if A is a unit vector
     denominator = 2 #should be 2 every time if A is a unit vector
     bx1 = (term1 - discriminant) / denominator
     #print "term1: ", term1, " discriminant:", discriminant, " denominator: ", denominator
     by1 = math.sqrt(1.0 - (bx1 * bx1))
     returnUnitVectors = []
     #make it (row,col) format, so therefore it's (y,x)
     returnUnitVectors.append((by1, bx1))
     returnUnitVectors.append((-1.0 * by1, bx1))
     
     if discriminantIsZero == False:
         bx2 = (term1 + discriminant) / denominator
         by2 = math.sqrt(1.0 - (bx2 * bx2))
         returnUnitVectors.append((by2, bx2))
         returnUnitVectors.append((-1.0 * by2, bx2)) 
         #print "return vectors"
         #print returnVectors
         returnUnitVectors = sorted(returnUnitVectors, key=lambda x: kUtil.getSqrDist(terminalPosCosZero, x))
         
     return returnUnitVectors[:2]
示例#2
0
	def _decisionFunction(self):
		"""
		This is where Magic Happens
		"""
		#print("Entering decision function")
		self.NN.Flush()
		self.NN.Input(self.bevList) # can input numpy arrays, too
			                          # for some reason only np.float64 is supported
		#print("Printing input of NN")		
		#print(self.bevList)
		#for _ in range(10000):
		self.NN.Activate()
		o = self.NN.Output()
		
		'''
		print("Printing output of NN")
		for i in range(len(o)):
			print o[i],' ',
		print()
		'''
		#print("Printing Connections")
		#print(len(self.NN.m_connections))
		#print(len(o))
		holdDecision = self.ballHolderSubIndex
		passList = [0,0]
		for j in range(len(self.bevList)):
			if self.bevList[j] == 1 and j!=holdDecision:
				passList.append(j)
				

		keeperIndex = [0,0]
		try:
			if self.bevSubstrate[holdDecision]:
				#print("Value for holding is:   ",o[holdDecision])
				a=0
		except Exception as ex:
			print("Exception with hold ball. Value: ",holdDecision)
		try:
			if self.bevSubstrate[passList[0]]:
				#print("Value for passing 0 is: ",o[passList[0]])
				a=0
		except Exception as ex:
			print("Exception with pass 0. Value: ",passList[0])
		try:
			if self.bevSubstrate[passList[1]]:
				#print("Value for passing 1 is: ",o[passList[1]])
				a=0
		except Exception as ex:
			print("Exception with pass 1. Value: ",passList[1])

		if (kUtil.getSqrDist(self.bevSubstrate[holdDecision],self.bevSubstrate[passList[0]])) <= (kUtil.getSqrDist(self.bevSubstrate[holdDecision],self.bevSubstrate[passList[1]])):
			keeperIndex[0] = 1
			keeperIndex[1] = 2
		else:
			keeperIndex[0] = 2
			keeperIndex[1] = 1
			
		out,i = max([(x,y) for y,x in enumerate(o)])
		'''
		if (o[holdDecision] >= o[passList[0]]) and (o[holdDecision] >= o[passList[1]]):
			#print("Holding ball")
			self._holdBall()
		else:
			if o[passList[0]] >= o[passList[1]]:
				#print("Pass 0")
				self._passBall(keeperIndex[0])
			else:
				#print("Pass 1")
				self._passBall(keeperIndex[1])

		#print("The decision is: ",i)
		'''
		if i==holdDecision:
			self._holdBall()
		else:
			self._passBall(self.bevSubstrate[i])
		
		return