screen = UI() game = SnakeGame(screen) screen.set_game(game) model = DQN(11, 256, 3) train = QTrain(model, lr=LR, gamma=GAMMA) model = train.load_checkpoint() agent = Agent(model, train, game) # training loop while True: current_state = agent.get_state() next_action = agent.get_action(current_state) game_over, score, reward = game.play_step(next_action) new_state = agent.get_state() agent.train_over_sample(current_state, next_action, reward, new_state, game_over) agent.save_values(current_state, next_action, reward, new_state, game_over) if game_over: game.restart() agent.num_of_games += 1 agent.train_over_batch() if score > maximum_score: # save checkpoint