forked from uvicaiclub/dqncar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (47 loc) · 1.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
import random as rnd
import time
import matplotlib.pyplot as plt
import math
import gym
import pygame
import torch
import tensorflow as tf
# all of the libraries above can be installed with pip
# ex: pip install numpy or pip install torch
#from DQN import DQNAgent
# Hyperparams
input_dims = 4
output_dims = 2
# likely want to put in some other cool things here like batch size, learning rate, etc.
episodes = 0
# Global Constants, change these
MAX_EPISODES = 1
if __name__ == "__main__":
env = gym.make('CartPole-v1', render_mode='human')
# agnet = DQNAgent(input_dims, output_dims)
# Make the main game loop.
while episodes < MAX_EPISODES:
time_step = 0
rewards = []
#agent.replay_memory.erase_memory()
observation, info = env.reset()
time_step = 0
done = False
while not done:
# Get action, ideally through your agent
action = env.action_space.sample()
# Take the action and observe the result
observation, reward, terminated, trunicated, info = env.step(action)
# Accumulate the reward
# Check if we lost
if terminated or trunicated:
done = True
# Store our memory
# learn?
#agent.learn()
time_step += 1
env.render()
# TODO: Check if reward normalization makes sense!
# agent.save()
env.close()