def getTrajs(self, gameState): # set up dicts for the current and previous game states. gameStateDict = self.gameStateToDict(gameState) oldGameStateDict = self.gameStateToDict(self.lastGameStates) # check if you're using midpoint or edges. if ("X" in gameStateDict["Paddle"].keys()): dim = self.lastChosenDim elif ("X1" in gameStateDict["Paddle"].keys()): dim = self.lastChosenDim + "1" # compute trajectory for ball. Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict['Ball'][dim], oldGameStateDict['Ball'][dim]) if same: ball_traj = "Same" elif Largest == gameStateDict['Ball'][dim]: ball_traj = "More" else: ball_traj = "Less" # compute trajectory for paddle. Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict['Paddle'][dim], oldGameStateDict['Paddle'][dim]) if same: paddle_traj = "Same" elif Largest == gameStateDict['Paddle'][dim]: paddle_traj = "More" else: paddle_traj = "Less" # compute ball and paddle trajectory relation. if ball_traj == paddle_traj: traj_relation = 'Same' else: traj_relation = 'Diff' return ball_traj, paddle_traj, traj_relation
def getPredicate(self,gameState,dimention): gameStateDict = self.gameStateToDict(gameState) if(gameState.shape[0] == 8): Largest,Smallest,same,iterations = entropy.ent_magnitudeMoreLessSame(gameStateDict["Paddle"][dimention],gameStateDict["Ball"][dimention]) if(same): return "Same" elif (gameStateDict["Paddle"][dimention]-4 < gameStateDict["Ball"][dimention]) and (gameStateDict["Paddle"][dimention]+4 > gameStateDict["Ball"][dimention]): return "Same" elif(Largest == gameStateDict["Paddle"][dimention]): return "More" else: return "Less" elif(gameState.shape[0] == 12): #check the first cordinate on the dimention Largest,Smallest,same,iterations = entropy.ent_magnitudeMoreLessSame(gameStateDict["Paddle"][dimention + "1"],gameStateDict["Ball"][dimention + "1"]) if(same): part1 = "Same" elif(Largest == gameStateDict["Paddle"][dimention + "1"]): part1 = "More" else: part1 = "Less" #check the first cordinate on the dimention Largest,Smallest,same,iterations = entropy.ent_magnitudeMoreLessSame(gameStateDict["Paddle"][dimention + "2"],gameStateDict["Ball"][dimention + "2"]) if(same): part2 = "Same" elif(Largest == gameStateDict["Paddle"][dimention + "2"]): part2 = "More" else: part2 = "Less" return part1 + part2 return "Error Something whent wrong"
def getPredicate(self, gameState, dimension): gameStateDict = self.gameStateToDict(gameState) #pdb.set_trace() #for i in gameStateDict: # for j in gameStateDict[i]: # gameStateDict['Paddle'][j] = int(round(gameStateDict[i][j]/5.0)*5) #pdb.set_trace() #gameStateDict['Paddle']['X1'] -= 5 #gameStateDict['Paddle']['X2'] += 5 if (gameState.shape[0] == 8): Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict["Paddle"][dimension], gameStateDict["Ball"][dimension]) if (same): return "Same" elif (gameStateDict["Paddle"][dimension] - 3 < gameStateDict["Ball"][dimension]) and ( gameStateDict["Paddle"][dimension] + 3 > gameStateDict["Ball"][dimension]): return "Same" elif (Largest == gameStateDict["Paddle"][dimension]): return "More" else: return "Less" elif (gameState.shape[0] == 12): #check the first cordinate on the dimension Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict["Paddle"][dimension + "1"], gameStateDict["Ball"][dimension + "1"]) if (same): part1 = "Same" elif (Largest == gameStateDict["Paddle"][dimension + "1"]): part1 = "More" else: part1 = "Less" #check the first cordinate on the dimension Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict["Paddle"][dimension + "2"], gameStateDict["Ball"][dimension + "2"]) if (same): part2 = "Same" elif (Largest == gameStateDict["Paddle"][dimension + "2"]): part2 = "More" else: part2 = "Less" return part1 + part2 return "Error Something whent wrong"
def getSpacePredicate(self, gameStateDict, dimention): if ("X" in gameStateDict["Paddle"].keys()): Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict["Paddle"][dimention], gameStateDict["Ball"][dimention]) if (same): return "Same" elif (Largest == gameStateDict["Paddle"][dimention]): return "More" else: return "Less" elif ("X1" in gameStateDict["Paddle"].keys()): #check the first cordinate on the dimension Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict["Paddle"][dimention + "1"], gameStateDict["Ball"][dimention + "1"]) if (same): part1 = "Same" elif (Largest == gameStateDict["Paddle"][dimention + "1"]): part1 = "More" else: part1 = "Less" #check the first cordinate on the dimension Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict["Paddle"][dimention + "2"], gameStateDict["Ball"][dimention + "2"]) if (same): part2 = "Same" elif (Largest == gameStateDict["Paddle"][dimention + "2"]): part2 = "More" else: part2 = "Less" return part1 + part2 return "Error Something whent wrong"
def getTrajectory(self, gameState): # set up dicts for the current and previous game states. gameStateDict = self.gameStateToDict(gameState) oldGameStateDict = self.gameStateToDict(self.lastGameStates) # check if you're computing trajectory for ball or paddle. item = np.random.choice(['Ball', 'Paddle']) # compute trajectory for object. Largest,Smallest,same,iterations = entropy.ent_magnitudeMoreLessSame(gameStateDict[item]['Y1'],oldGameStateDict[item]['Y1']) if same: rel = "Same" elif Largest == gameStateDict[item]['Y1']: rel = "More" else: rel = "Less" # return object and trajectory. return [item, rel]
def getTimePredicate(self, gameStateDict, previousGameState, dimention, obj): if ("X" in gameStateDict["Paddle"].keys()): dim = dimention elif ("X1" in gameStateDict["Paddle"].keys()): dim = dimention + "1" Largest, Smallest, same, iterations = entropy.ent_magnitudeMoreLessSame( gameStateDict[obj][dim] + 1, previousGameState[obj][dim] + 1) pred = "" if (same): pred = "Same" elif (Largest == gameStateDict[obj][dim]): pred = "More" else: pred = "Less" return pred