Beispiel #1
0
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:
                    hoboHistoryOnThisTrack.append(.5)
                    if j == score:
                        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
                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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 def testGuaranteedSafe(self):
     hobo = Hobo()
     hobo.runningResults = [[0, 0]]
     hobo.runningL0 = [1000]
     hobo.runningL1 = [5]
     value = hobo.doMaths()
     answer = [100]
     self.assertEqual(answer, value)
Beispiel #5
0
 def testNormal(self):
     hobo = Hobo()
     hobo.runningResults = [[0, 0], [1, 1]]
     hobo.runningL0 = [3, 4]
     hobo.runningL1 = [4, 5]
     value = hobo.doMaths()
     answer = [46, 66]
     self.assertEqual(answer, value)
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
Beispiel #7
0
 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)
Beispiel #8
0
 def testSmartness1(self):
     hobo = Hobo()
     hobo.info = [[1, 0], []]
     hobo.act(1)
     self.assertEqual([0, 1], hobo.positionHistory)