-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
28 lines (25 loc) · 858 Bytes
/
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
from q_state import next_state, random_state, actions
from q_learning import QLearning
from q_table import QTable
if __name__ == "__main__":
episode = 100
model_save_interval = 10
table = QTable(actions)
learning = QLearning(table)
for step in range(episode):
init_state = random_state()
i = 0
reward = 0
while reward != 1:
state = init_state
while True:
i += 1
action = learning.choose_action(state)
state2, reward, done = next_state(state, action, table)
learning.learn(state, action, reward, state2, done)
if done:
break
state = state2
print(init_state, i, len(table.q_table))
if (step + 1) % model_save_interval == 0:
table.save()