Example #1
0
	def _passBall(self, pointToPassTo):
		'''
		If a keeper currently has the ball, then it has the option to hold the ball,
		or pass it. Call this function to pass the ball. pointToPassTo is the coordinate that
		the keeper can pass to. these are pixel values 

		:param pointToPassTo: the tile that the agent is passing to. It is an XY coordinate defined to be the top left 
			corner of the tile you're trying to pass to

		:type pointToPassTo: typle of int

		:returns: no return 
		'''
		if self.fieldBall == None:
			print("ERROR: trying to hold ball without actually having  ball")
			return
	
		#pass to team mate integerK. if integerK = 1, then it's the 2nd element in array
		selfToTargetDirection = kUtil.unitVector(kUtil.getVector(self.__getBallCenter(self.noisyBallPos), pointToPassTo))
		selfToTargetVector = (kUtil.scalarMultiply(self.fieldBall.maxBallSpeed, selfToTargetDirection))

			
		#at this point, you've determined the angle you wanna pass, and you pass.
		#set ball's possesion to false, and update to new point. ball class handles direction vector
		self.fieldBall.updatePosession(False)
		self.inPosession = False
		self.isKicking = True
		#kUtil.addVectorToPoint(self.fieldBall.trueBallPos, selfToTeammateVector)
		self.fieldBall.updateDirection(kUtil.getNoisyVals(selfToTargetVector, self.getSigma()))
Example #2
0
	def debugPassVectors(self, startPoint, vectors):
		"""
		This function is meant to display yellow dots to help the programmer figure
		out if the getRotatedVectors function works correctly. The getRotatedVectors
		function ended up being discarded, but code for it is still kept incase
		the developers decide they want to use it later on
		
		:param vectors: 2 vectors that were calculated by getRotatedVectors
		:param startPoint: the vertex/starting point of the vector that you're trying
		    to rotate. You rotate about the vertex. 
		    
		:type vectors: a list of 2 vectors, each vector being a tuple of floats
		:type startPoint: a tuple or list of floats
		
		:returns: no return
		"""
		self.worldRef.__drawWorld ()
		self.worldRef.__displayScore()
		print("Starting point: ", startPoint) 
		for vector in vectors:
			newVector = kUtil.addVectorToPoint(startPoint, kUtil.scalarMultiply(5, vector))
			print("printing vector: ", newVector)
			self.worldRef.gameDisplay.blit(self.worldRef.__debugYellowDotImage, (newVector[1], newVector[0]))
		self.worldRef.gameDisplay.blit(self.worldRef.__debugRedDotImage, (startPoint[1], startPoint[0]))
		pygame.display.update()
		print("debugging")
Example #3
0
    def Qtesting(self):
        self.resetGameForTraining()
        while self.isGameOver() == False:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gameExit = True
            self.sendStateVars()
            self.calc_receive()
            for keeper in self.keeperArray:
                keeper.isInTraining = False
                keeper.decisionFlowChart()
            for taker in self.takerArray:
                taker.decisionFlowChart()
            
            newBallPoint = kUtil.addVectorToPoint(self.fieldBall.trueBallPos, kUtil.scalarMultiply(self.maxBallSpeed, kUtil.unitVector(self.fieldBall.trueBallDirection)))
            self.fieldBall.updateCoordinate(newBallPoint)
            for i in range(len(self.takerArray)):
                self.takerArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.takerArray[i].sigma)
            for i in range(len(self.keeperArray)):
                self.keeperArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.keeperArray[i].sigma)                
            self.updateBallPosession()
            self.updateScore()
            self.drawWorld ()
            self.displayScore()
            pygame.display.update()
            #this specifies frames per second
            self.clock.tick(self.fps)
    
        if self.isGameOver() == True:
            gameExit = True
        print("final score: ", self.keeperScore)

        self.finish()
        #self.pause("Game Over: Final Score %d" % self.keeperScore)
        self.exitSim()
Example #4
0
 def moveAttempt(self, inputAgent, reversedPolarCoord ):
     
     noiseFreeDirectionVector = reversedPolarCoord[0]
     distance = reversedPolarCoord[1]
     
     #for the purposes of finding legal moves, just assume that they player is trying
     #to cover the most amount of distance. Also, right now, it's not important if
     #noiseFreeDirectionVector is a unit vector or not
     quad = self.getQuadAttemptingToMoveTo(inputAgent, noiseFreeDirectionVector)
     setOfLegalQuads = self.getLegalQuadrants(inputAgent)
     #print(setOfLegalQuads)
     #print("quad:", quad)
     if quad in setOfLegalQuads:
         #move is legal, do it
         self.moveAgent(inputAgent, kUtil.scalarMultiply ( distance, kUtil.unitVector(noiseFreeDirectionVector)))
     else:
         #move is illegal. Simply return without calling or updating anything
         #print("Illegal move: ", reversedPolarCoord)
         return
Example #5
0
 def calcOptimal(self, agentList, i, intersect):
     V = kUtil.getVector(self.fieldBall.trueBallPos, intersect)
     UV = kUtil.unitVector(V)
     stepVector = kUtil.scalarMultiply(self.maxBallSpeed, UV)
     #keep adding the step vector to the optimal point
     optimalPoint = self.fieldBall.trueBallPos
     maxNumSteps = int(kUtil.getDist(self.fieldBall.trueBallPos, intersect)/ self.maxBallSpeed)
     stepCount = 0
     for k in range(maxNumSteps):
         optimalPoint = kUtil.addVectorToPoint(optimalPoint, stepVector)
         stepCount += 1
         currPd = kUtil.getDist(optimalPoint,agentList[i].true_pos)
         currBd = kUtil.getDist(self.fieldBall.trueBallPos, optimalPoint)
         currPt = currPd / self.maxPlayerSpeed
         currBt = currBd / self.maxBallSpeed
         if currPt < currBt:
             #found the optimal, so return it
             return optimalPoint
     #if you get here, then no closer optimal was found, so just return the intersect
     return intersect
Example #6
0
	def moveAttempt(self, inputAgent, reversedPolarCoord ):
		"""
		This function is used by the agent in order to attempt movement on the 
		field. If the move is legal, the agent's position is updated. If the 
		move is illegal, then nothing happens. A move is illegal if the agent 
		tries to go outside the boundaries of the field. 
		
		:param inputAgent: a reference to the agent that is attempting to move
		:param reversedPolarCoord: the movement that the agent is trying to do. 
		    the movement is represented as a tuple where the first element is a
		    unit vector representing the direction the agent is trying to move, 
		    and the 2nd element is the distance the agent is trying to move.
		    
		:type inputAgent: agent
		:type reversedPolarCoord: tuple where first element is a tuple of floats, 
		    and the 2nd element is a float or integer
		
		:returns: true if move was successful, false if not
		:rtype: boolean
		"""
		noiseFreeDirectionVector = reversedPolarCoord[0]
		distance = reversedPolarCoord[1]
		
		#for the purposes of finding legal moves, just assume that they player is trying
		#to cover the most amount of distance. Also, right now, it's not important if
		#noiseFreeDirectionVector is a unit vector or not
		quad = self.__getQuadAttemptingToMoveTo(inputAgent, noiseFreeDirectionVector)
		setOfLegalQuads = self.__getLegalQuadrants(inputAgent)
		#print setOfLegalQuads 
		#print "quad:", quad
		if quad in setOfLegalQuads:
			#move is legal, do it
			self.__moveAgent(inputAgent, kUtil.scalarMultiply ( distance, kUtil.unitVector(noiseFreeDirectionVector)))
		else:
			#move is illegal. Simply return without calling or updating anything
			#print "Illegal move: ", reversedPolarCoord 
			return False
		if kUtil.magnitude(noiseFreeDirectionVector) == 0.0:
			return False
		else:
			return True
Example #7
0
 def QTraining(self,totalTraining):
     for training in range(totalTraining):
         print("Training number :",training)
         if training%100 == 0:
             self.displayGraphics = True
         else:
             self.displayGraphics = False
         self.resetGameForTraining()
         while self.isGameOver() == False:
             for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                     gameExit = True
             self.sendStateVars()
             reward = 100000
             for keeper in self.keeperArray:
                 keeper.updateReward(reward) 
             self.calc_receive()
             for keeper in self.keeperArray:
                 keeper.isInTraining = True
                 keeper.decisionFlowChart()
             for taker in self.takerArray:
                 taker.decisionFlowChart()
                 
             newBallPoint = kUtil.addVectorToPoint(self.fieldBall.trueBallPos, kUtil.scalarMultiply(self.maxBallSpeed, kUtil.unitVector(self.fieldBall.trueBallDirection)))
             self.fieldBall.updateCoordinate(newBallPoint)
             for i in range(len(self.takerArray)):
                 self.takerArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.takerArray[i].sigma)
             for i in range(len(self.keeperArray)):
                 self.keeperArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.keeperArray[i].sigma)                
             self.updateBallPosession()
             self.updateScore()
             if(self.displayGraphics == True):
                 self.drawWorld ()
                 self.displayScore()
                 pygame.display.update()
             if self.isGameOver():
                 reward = -100
                 self.sendStateVars()
                 for keeper in self.keeperArray:
                     keeper.updateFinalReward(reward)
             self.clock.tick(10000)
Example #8
0
	def commonFunctionality(self, mode, showDisplay = True, turnOnGrid = False, prettyGrid = False):
		#this is common code that will occur regardless of what agent you picked
		#if (self.fieldBall.inPosession == False):
		newBallPoint = kUtil.addVectorToPoint(self.fieldBall.trueBallPos, kUtil.scalarMultiply(self.maxBallSpeed, kUtil.unitVector(self.fieldBall.trueBallDirection)))
		self.fieldBall.updateCoordinate(newBallPoint)
		for i in range(len(self.takerArray)):
			self.takerArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.takerArray[i].getSigma())
		for i in range(len(self.keeperArray)):
			self.keeperArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.keeperArray[i].getSigma())                
		self.__updateBallPosession()
		self.__updateScore()
		#remove this line if you don't want the grid to be drawn
		if showDisplay:
			if (turnOnGrid):
				gridList = self.bev.getBirdsEyeViewAsList(self.keeperArray, self.takerArray)
				substrate = self.bev.getSubstrate(self.keeperArray, self.takerArray)
				self.__drawWorld (mode, gridList, substrate, prettyGrid)
			else:
				self.__drawWorld(mode)
			self.__displayScore()
			pygame.display.update()
Example #9
0
 def passBall(self, integerK):
     #if you're passing to integerK = 1, then that means pass to the keeper that's closer to you
     #if you're passing ot integerK = 2, then that means pass to the keeper that's farther to you
     #0 is an invalid input
     sortedKeepers = sorted(self.keeperArray)
     if integerK == 0:
         print("Invalid input for integerK! integerK not allowed to be", integerK)
         return
     if self.fieldBall == None:
         print("ERROR: trying to hold ball without actually having  ball")
         return
     
     #pass to team mate integerK. if integerK = 1, then it's the 2nd element in array
     selfToTeammateDirection = kUtil.unitVector(kUtil.getVector(self.noisyBallPos, sortedKeepers[integerK].noisy_pos))
     selfToTeammateVector = (kUtil.scalarMultiply(self.fieldBall.maxBallSpeed, selfToTeammateDirection))
     #set ball's possesion to false, and update to new point. ball class handles direction vector
     self.fieldBall.updatePosession(False)
     self.inPosession = False
     self.isKicking = True
     #kUtil.addVectorToPoint(self.fieldBall.trueBallPos, selfToTeammateVector)
     self.fieldBall.update(selfToTeammateVector)
     #self.fieldBall.updatepos( kUtil.addVectorToPoint(self.fieldBall.true_pos, selfToTeammateVector ) )
     return (selfToTeammateDirection, self.maxBallSpeed)
Example #10
0
 def _passBall(self, integerK):
     """
     If a keeper currently has the ball, then it has the option to hold the ball,
     or pass it. Call this function to pass the ball. integerK represents the 
     keeper that the ball holder is passing to. integerK = 1 means pass to the 
     keeper that is closest to the ball besides the ball holder. integerK = 2
     means pass to the 2nd closest, and so on. Only subclasses of agent should
     be calling this function.
     
     :param integerK: this represents the 
         keeper that the ball holder is passing to. integerK = 1 means pass to the 
         keeper that is closest to the ball besides the ball holder. integerK = 2
         means pass to the 2nd closest, and so on.
     
     :type integerK: integer
     
     :returns: no return 
     """
     #print("passing to keeper " +  str(integerK) + ", indexed by distance. ")
     #if you're passing to integerK = 1, then that means pass to the keeper that's closer to you
     #if you're passing ot integerK = 2, then that means pass to the keeper that's farther to you
     #0 is an invalid input
     sortedKeepers = sorted(self.keeperArray)
     if integerK == 0:
         print("Invalid input for integerK! integerK not allowed to be", integerK)
         return
     if self.fieldBall == None:
         print("ERROR: trying to hold ball without actually having  ball")
         return
     
     #pass to team mate integerK. if integerK = 1, then it's the 2nd element in array
     selfToTeammateDirection = kUtil.unitVector(kUtil.getVector(self.noisyBallPos, sortedKeepers[integerK].get_noisy_pos()))
     selfToTeammateVector = (kUtil.scalarMultiply(self.fieldBall.maxBallSpeed, selfToTeammateDirection))
     
     """
     #this code segment is for determining which angle you'd rather pass to. it's all deterministic
     ballPos = self.noisyBallPos
     passVectorsToConsider = []
     passVectorsToConsider.append(selfToTeammateDirection)
     for i in range(len(self.cosinesOfInterest)):
         passVectorsToConsider = passVectorsToConsider + self.__getRotatedVectors(selfToTeammateDirection, self.cosinesOfInterest[i])
     #now sort the vectors based on how open they are:
     self.worldRef.debugPassVectors(ballPos, passVectorsToConsider)
     passVectorsToConsider = sorted(passVectorsToConsider, 
                                    key = lambda vector: max ( kUtil.cosTheta(self.worldRef.takerArray[0].getNoisyMidPoint(), ballPos, kUtil.addVectorToPoint(ballPos, vector)), 
                                                               kUtil.cosTheta(self.worldRef.takerArray[1].getNoisyMidPoint(), ballPos, kUtil.addVectorToPoint(ballPos, vector))),
                                     )
     #iterate over the sorted list until you find a pass that you can do
     for i in range(len(passVectorsToConsider)):
         if( calcReceive.calc_receive(self.worldRef, passVectorsToConsider[i]) != None): 
             selfToTeammateDirection = passVectorsToConsider[i]
             selfToTeammateVector = (kUtil.scalarMultiply(self.fieldBall.maxBallSpeed, selfToTeammateDirection))
             print "PASS USING ANGLE ACHEIVED AT i=", i
             break
     """    
             
     #at this point, you've determined the angle you wanna pass, and you pass.
     #set ball's possesion to false, and update to new point. ball class handles direction vector
     self.fieldBall.updatePosession(False)
     self.inPosession = False
     self.isKicking = True
     #kUtil.addVectorToPoint(self.fieldBall.trueBallPos, selfToTeammateVector)
     self.fieldBall.updateDirection(kUtil.getNoisyVals(selfToTeammateVector, self.__sigma))
Example #11
0
def __calcOptimal(worldRef, agentList, i, intersect):
    """
    This function is a private function meant to assist another private function called
    __calc_receive_ball_moving. 
    
    once __calc_receive_ball_moving has calculated the intersection point, there's 
    one last step: to make sure that the intersection point isn't too close to 
    the out of bounds area. If the intersection point too close to out of bounds, 
    then return an intersection point along the path that the ball is traveling, but
    is just still safely away from the out of bounds areas. 
    
    
    .. note::
        This is a private function that the user shouldn't worry about calling.
        Only the calc_receive function should be called.  
    
    :param worldRef: a reference to the simulator class which is calling this function
    :param agentList: a list provided by the simulator of all agents
    :param i: the index of the agent running to the ball for the list agentList
    :param intersect: the intersection point that has been calculated, and might be too
        close to out of bounds

        
    :type worldRef: keepAway class
    :type agentList: a list where each element is an agent class
    :type i: integer
    :type intersect: a tuple of floats
    
    :returns: the intersection coordinate which is safely within bounds, or the original
        intersection point if no such point is found
    :rtype: tuple of floats

    """
    #if the intersect is in bounds, just go to it. no calculations needed
    if __isPointOutOfPlayRegion(worldRef, intersect, agentList, i) == False:
        #print("point in bounds, return intersect") 
        return intersect
        
    #V = vector from agent's perpendicular intercept to the ball
    V = kUtil.getVector(intersect, worldRef.fieldBall.trueBallPos)
    #turn V into a unit vector and multipy it by the speed of the ball to get velocity vector
    UV = kUtil.unitVector(V)
    stepVector = kUtil.scalarMultiply(worldRef.maxBallSpeed, UV)
        
    #the optimal point is intialized to the intersect, and 
    #the intersect is currently out of bounds.
    #keep adding the step vector to the optimal point until
    #the intersect is no longer out of bounds
    optimalPoint = intersect
    maxNumSteps = int(kUtil.getDist(worldRef.fieldBall.trueBallPos, intersect)/ worldRef.maxBallSpeed)
    stepCount = 0
    #if you can't get to the ball in maxNumSteps, then it's hopeless. simply
    #return the intersection point. Your agent will fail and the ball will
    #go out of bounds, but there's nothing that can be done
    for k in range(maxNumSteps):
        optimalPoint = kUtil.addVectorToPoint(optimalPoint, stepVector)
        stepCount += 1
        if __isPointOutOfPlayRegion(worldRef, optimalPoint, agentList, i) == False:
            #print("Optimal found, returning optimal point:", optimalPoint) 
            return optimalPoint
    #if you get here, then no closer optimal was found
    #print("no optimal found, returning intersect", intersect) 
    return intersect
Example #12
0
    def gameLoop(self, mode):
        """
        This is the main game loop. Each iteration of this counts as a tick. 
        With each tick, an agent can move keepAway.maxPlayerSpeed units, and the
        ball can move keepAway.maxBallSpeed units. At the end of each tick, the
        pygame screen is updated to the next frame. 
        
        :returns: no return
        """
        self.__drawWorld()
        gameExit = False
        pygame.display.update()
        experimentAgent = self.keeperArray[0]
        # each occurance of this loop is treated as one simulation cycle
        while not gameExit:
            if mode == "manual":
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        gameExit = True
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_LEFT:
                            self.moveAttempt(experimentAgent, ((0, -1), self.maxPlayerSpeed))
                        elif event.key == pygame.K_RIGHT:
                            self.moveAttempt(experimentAgent, ((0, 1), self.maxPlayerSpeed))
                        elif event.key == pygame.K_UP:
                            self.moveAttempt(experimentAgent, ((-1, 0), self.maxPlayerSpeed))
                        elif event.key == pygame.K_DOWN:
                            self.moveAttempt(experimentAgent, ((1, 0), self.maxPlayerSpeed))
                        elif event.key == pygame.K_1:
                            self.moveAttempt(experimentAgent, ((-1, -1), self.maxPlayerSpeed))
                        elif event.key == pygame.K_2:
                            self.moveAttempt(experimentAgent, ((-1, 1), self.maxPlayerSpeed))
                        elif event.key == pygame.K_3:
                            self.moveAttempt(experimentAgent, ((1, -1), self.maxPlayerSpeed))
                        elif event.key == pygame.K_4:
                            self.moveAttempt(experimentAgent, ((1, 1), self.maxPlayerSpeed))
            elif mode == "hand_coded":
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        gameExit = True
                self.sendCalcReceiveDecision()
                self.sendSimpleStateVars()
                for keeper in self.keeperArray:
                    keeper.decisionFlowChart()
                for taker in self.takerArray:
                    taker.decisionFlowChart()
            elif mode == "sarsa":
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        gameExit = True
                self.sendCalcReceiveDecision()
                self.sendSimpleStateVars()

            # this is common code that will occur regardless of what agent you picked
            # if (self.fieldBall.inPosession == False):
            newBallPoint = kUtil.addVectorToPoint(
                self.fieldBall.trueBallPos,
                kUtil.scalarMultiply(self.maxBallSpeed, kUtil.unitVector(self.fieldBall.trueBallDirection)),
            )
            self.fieldBall.updateCoordinate(newBallPoint)
            for i in range(len(self.takerArray)):
                self.takerArray[i].noisyBallPos = kUtil.getNoisyVals(
                    self.fieldBall.trueBallPos, self.takerArray[i].getSigma()
                )
            for i in range(len(self.keeperArray)):
                self.keeperArray[i].noisyBallPos = kUtil.getNoisyVals(
                    self.fieldBall.trueBallPos, self.keeperArray[i].getSigma()
                )
            self.__updateBallPosession()
            self.__updateScore()
            self.__drawWorld()
            self.__displayScore()
            pygame.display.update()

            if self.isGameOver() == True:
                gameExit = True
                print("final score: ", self.keeperScore)
            # this specifies frames per second
            self.clock.tick(self.test_fps)
        self.__finish()
        # self.pause("Game Over: Final Score %d" % self.keeperScore)
        self.__exitSim()
Example #13
0
 def gameLoop(self, mode):
     self.drawWorld ()
     gameExit = False
     if(self.displayGraphics == True):
         pygame.display.update()
     experimentAgent = self.takerArray[0]
     #each occurance of this loop is treated as one simulation cycle
     while not gameExit:
         if(mode == "manual"):
             for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                     gameExit = True
                 if event.type == pygame.KEYDOWN:
                     if event.key == pygame.K_LEFT:
                         self.moveAttempt(experimentAgent, ((0,-1), self.maxPlayerSpeed))
                     elif event.key == pygame.K_RIGHT:
                         self.moveAttempt(experimentAgent, ((0,1), self.maxPlayerSpeed))
                     elif event.key == pygame.K_UP:
                         self.moveAttempt(experimentAgent, ((-1,0), self.maxPlayerSpeed))
                     elif event.key == pygame.K_DOWN:
                         self.moveAttempt(experimentAgent, ((1,0), self.maxPlayerSpeed))
                     elif event.key == pygame.K_1:
                         self.moveAttempt(experimentAgent, ((-1,-1), self.maxPlayerSpeed))
                     elif event.key == pygame.K_2:
                         self.moveAttempt(experimentAgent, ((-1,1), self.maxPlayerSpeed))
                     elif event.key == pygame.K_3:
                         self.moveAttempt(experimentAgent, ((1,-1), self.maxPlayerSpeed))
                     elif event.key == pygame.K_4:
                         self.moveAttempt(experimentAgent, ((1,1), self.maxPlayerSpeed))
         elif (mode == "hand_coded"):
             for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                     gameExit = True
             self.sendStateVars()
             self.calc_receive()
             for keeper in self.keeperArray:
                 keeper.decisionFlowChart()
             for taker in self.takerArray:
                 taker.decisionFlowChart()
         elif(mode == "q_learning"):
             totalTraining = 5
             flag = False
             for index in range(len(self.keeperArray)):
                 if self.keeperArray[index].load_obj("dict",index, mode) == None:
                     flag = True
             if flag:
                 print("no files exist")
                 self.QTraining(totalTraining)
             
                 for index in range(len(self.keeperArray)):
                     self.keeperArray[index].save_obj(self.keeperArray[index].q_values,"dict",index, mode)
                     #for key in list(self.keeperArray[index].q_values.keys())[:10]:
                         #print("QValues of ",index," agent is: key=",key," value=",self.keeperArray[index].q_values[key])
                 
                 self.Qtesting()
             
             else:
                 print("files exist, continue training")
                 totalTraining = 0
                 for index in range(len(self.keeperArray)):
                     self.keeperArray[index].q_values = self.keeperArray[index].load_obj("dict",index, mode)
                     #for key in list(self.keeperArray[index].q_values.keys())[:10]:
                         #print("QValues of ",index," agent is: key=",key," value=",self.keeperArray[index].q_values[key])
                 
                 
                 
                 self.QTraining(totalTraining)
                 
                 for index in range(len(self.keeperArray)):
                     self.keeperArray[index].save_obj(self.keeperArray[index].q_values,"dict",index, mode)
                     
                 self.Qtesting()
                 
                                     
         elif(mode == "sarsa"):
             totalTraining = 5
             flag = False
             for index in range(len(self.keeperArray)):
                 if self.keeperArray[index].load_obj("dict",index, mode) == None:
                     flag = True
             if flag:
                 print("no files exist")
                 self.QTraining(totalTraining)
             
                 for index in range(len(self.keeperArray)):
                     self.keeperArray[index].save_obj(self.keeperArray[index].q_values,"dict",index, mode)
                     #for key in list(self.keeperArray[index].q_values.keys())[:10]:
                         #print("QValues of ",index," agent is: key=",key," value=",self.keeperArray[index].q_values[key])
                 
                 self.Qtesting()
             
             else:
                 print("files exist, continue training")
                 totalTraining = 0
                 for index in range(len(self.keeperArray)):
                     self.keeperArray[index].q_values = self.keeperArray[index].load_obj("dict",index, mode)
                     #for key in list(self.keeperArray[index].q_values.keys())[:10]:
                         #print("QValues of ",index," agent is: key=",key," value=",self.keeperArray[index].q_values[key])
                 
                 
                 
                 self.QTraining(totalTraining)
                 
                 for index in range(len(self.keeperArray)):
                     self.keeperArray[index].save_obj(self.keeperArray[index].q_values,"dict",index, mode)
                     
                 self.Qtesting()
                 
                                     
             
         #this is common code that will occur regardless of what agent you picked
         #if (self.fieldBall.inPosession == False):
         newBallPoint = kUtil.addVectorToPoint(self.fieldBall.trueBallPos, kUtil.scalarMultiply(self.maxBallSpeed, kUtil.unitVector(self.fieldBall.trueBallDirection)))
         self.fieldBall.updateCoordinate(newBallPoint)
         for i in range(len(self.takerArray)):
             self.takerArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.takerArray[i].sigma)
         for i in range(len(self.keeperArray)):
             self.keeperArray[i].noisyBallPos = kUtil.getNoisyVals(self.fieldBall.trueBallPos, self.keeperArray[i].sigma)                
         self.updateBallPosession()
         self.updateScore()
         self.drawWorld ()
         self.displayScore()
         pygame.display.update()
         
         if self.isGameOver() == True:
             gameExit = True
             print("final score: ", self.keeperScore)
         #this specifies frames per second
         self.clock.tick(self.fps)
     self.finish()
     #self.pause("Game Over: Final Score %d" % self.keeperScore)
     self.exitSim()