forked from NourOM02/Tic-Tac-Toe-RL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_agents.py
32 lines (22 loc) · 853 Bytes
/
train_agents.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
from agents import ValueIteration, PolicyIteration
import json
from tqdm import tqdm
##################################### Value Iteration #####################################
agent = ValueIteration()
agent.value_iteration()
policy = {}
for x in agent.policy:
policy[str(x)] = agent.policy[x]
with open("Policies/valueIteration.json", 'w') as json_file:
json.dump(policy, json_file)
##################################### Policy Iteration #####################################
"""
agent = PolicyIteration()
agent.policy_iteration()
policy = {}
for x in agent.policy:
policy[str(x)] = agent.policy[x]
with open("Policies/policyIteration.json", 'w') as json_file:
policy_json = {str(state): int(agent.policy[state]) if agent.policy[state] != None else None for state in agent.policy}
json.dump(policy_json, json_file)
"""