I am referencing a tutorial for a snake AI game using Tensorflow and pygame.

Reference: https://github.com/tolotrasam/snakegame_ai_tensorflow/tree/master/dist

For the "some random games first" and "evaluate" methods, I want to display the entire game, instead of just the final frame. For example: in the player.py code, the "some random games first" method only displays the final step frame. I want to render each frame of each game played. How would this be done?

Also, how would I use this code to display the the "trained" model, such as the saved data in the saved.py file generated?

Any help would be appreciated.

Reference Code:

LR = 1e-3
goal_steps = 300
score_requirement = 50
initial_games = 5000

def some_random_games_first():
    # Each of these is its own game.
    for episode in range(10):

        env = game()
        env.reset()
        first = True
        for _ in range(goal_steps):

            # action = random.randrange(0, 3)
            action = random.randrange(0, 3)
            # action = 2

            if first:
                first = False
                action = 2

            # do it! render the previous view
            env.render()
            observation, reward, done, info = env.step(action)
            a = 0
            if done: break

Snake game can be found in the GitHub link, don't want to paste that entire code.

Render method:


def render(self):
        # score
        d = self.screen.blit(self.bg, SCORE_POS, pygame.Rect(SCORE_POS, (50, 100)))
        f = pygame.font.Font(None, 12)
        scoreimage = f.render(SCORE_PREFIX + str(self.currentscore), True, SCORE_COLOR)
        d2 = self.screen.blit(scoreimage, SCORE_POS)

        # drawing
        dirty = self.all.draw(self.screen)
        dirty.append(d)
        dirty.append(d2)

        # updating screen
        pygame.display.update(dirty)

        # waiting
        self.clock.tick(FPS)

0 Answers