def testSmartness4(self): hobo = Hobo() hobo.runningResults = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0]] hobo.runningL0 = [15, 20] hobo.runningL1 = [10, 5] hobo.info = [[0, 0], []] hobo.act(4) self.assertEqual([0, 1], hobo.positionHistory)
def testSmartness3(self): hobo = Hobo() hobo.info = [[1, 1], []] hobo.runningResults = [[1, 1, 1, 1, 1], [0, 0]] hobo.runningL0 = [8, 10] hobo.runningL1 = [5, 3] hobo.act(3) self.assertEqual([0, 1], hobo.positionHistory)
def simulateGame(L0, L1, numTrains, lengthOfGame, hoboSmartness, trackResults=[]): def showGraphs(): fig, ax = plt.subplots(numTrains) fig.suptitle("Presence of Trains on Tracks every second") deathTrack = 0 for i in range(len(trackResults)): hoboHistoryOnThisTrack = [] for j in range(len(dumbledore.positionHistory)): if dumbledore.positionHistory[j] == i: # # print("J: "+str(j)) hoboHistoryOnThisTrack.append(.5) if j == score: # print("SCORE: "+str(score)) # print("DEATH TRACK: "+str(i)) deathTrack = i else: hoboHistoryOnThisTrack.append(None) ax[i].plot([x for x in range(lengthOfGame)], trackResults[i], hoboHistoryOnThisTrack, 'ro') ax[i].set_title("Track " + str(i)) ax[deathTrack].text(score, .5, "HOBO DIED", bbox=dict(facecolor='red', alpha=0.5)) plt.show() # for each 60second window generate TrainTrack results tracks = [TrainTrack(L0, L1) for x in range(numTrains)] if trackResults == []: trackResults = [x.simulate(lengthOfGame) for x in tracks] # print("TRACKRESULTS: "+str(trackResults)) dumbledore = Hobo() dumbledore.runningResults = [[0] for x in range(numTrains)] score = lengthOfGame for i in range(lengthOfGame): # DID HE GET HIT? if trackResults[dumbledore.position][i] == 1: dumbledore.hp -= 1 # O SHIT, HE DED END THE GAME if dumbledore.hp == 0: score = i # showGraphs() return score # GET PAPER PLANE paperPlane = [] if (random.randint(1, 100) <= 75) and i < lengthOfGame - 1: for y in range(numTrains): paperPlane.append(trackResults[y][i+1]) else: for y in range(numTrains): paperPlane.append(random.randint(0, 1)) dumbledore.getSuggestion(paperPlane) # LOOKS AROUND AT TRAINS dumbledore.lookAtTracks(i, trackResults) # STORES WHAT HE SEES dumbledore.updateResults() # JUMP dumbledore.act(hoboSmartness) # showGraphs() return score
def simulateGame(L0, L1, numTrains, lengthOfGame, hoboSmartness): def showGraphs(): fig, ax = plt.subplots(numTrains) fig.suptitle("Presence of Trains on Tracks every second") deathTrack = 0 for i in range(len(trackResults)): hoboHistoryOnThisTrack = [] for j in range(len(dumbledore.positionHistory)): if dumbledore.positionHistory[j] == i: deathTrack = i else: hoboHistoryOnThisTrack.append(None) ax[i].plot([x for x in range(lengthOfGame)], trackResults[i], hoboHistoryOnThisTrack, 'ro') ax[i].set_title("Track " + str(i)) ax[deathTrack].text(score, .5, "HOBO DIED", bbox=dict(facecolor='red', alpha=0.5)) plt.show() # for each time period generate a trainTrack simulation tracks = [TrainTrack(L0, L1) for x in range(numTrains)] trackResults = [x.simulate(lengthOfGame) for x in tracks] # initialize our hobo object dumbledore = Hobo() dumbledore.runningResults = [[0] for x in range(numTrains)] score = lengthOfGame # MAIN GAME LOOP, each i represents a game slice or a second of the whole window for i in range(lengthOfGame): # DID HE GET HIT? Does the track he is on have a 1 at the given index? If so, decrement HP if trackResults[dumbledore.position][i] == 1: dumbledore.hp -= 1 # O SHIT, HE DIED END THE GAME if dumbledore.hp == 0: score = i showGraphs() return score # GET PAPER PLANE paperPlane = [] if (random.randint(1, 100) <= 99) and i < lengthOfGame - 1: for y in range(numTrains): paperPlane.append(trackResults[y][i + 1]) else: for y in range(numTrains): paperPlane.append(random.randint(0, 1)) dumbledore.getSuggestion(paperPlane) # LOOKS AROUND AT TRAINS dumbledore.lookAtTracks(i, trackResults) # STORES WHAT HE SEES dumbledore.updateResults() # JUMP dumbledore.act(hoboSmartness) showGraphs() return "GAME OVER! SCORE: " + str(score)
def testSmartness2(self): hobo = Hobo() hobo.info = [[1, 1], [1, 0]] # Second list is paper plane. hobo.act(2) self.assertEqual([0, 1], hobo.positionHistory)
def testSmartness1(self): hobo = Hobo() hobo.info = [[1, 0], []] hobo.act(1) self.assertEqual([0, 1], hobo.positionHistory)