forked from asmalex/CPS480_IntroToAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleReflexAgent.py
37 lines (31 loc) · 1.01 KB
/
simpleReflexAgent.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
import gym
import random
#Create our CartPole environment
env = gym.make('CartPole-v0')
env.reset()
def RandomAgent():
#each episode is a game that is run to its end
randomAction=1
for epoch in range (10):
#now we break up the frames
for t in range (500):
env.render()
#state = env.obversation_space
#print(state)
if randomAction ==1:
action = env.action_space.sample()
randomAction == 0
else:
if next_state[3]>0:
action=0
else:
action=1
print (action)
#the next state, rewards, done flag, and info are all returned
next_state, reward, done, info = env.step(action)
print(t, next_state, reward, done, info, action)
if done:
env.reset()
randomAction == 1
break
RandomAgent()