CoolFace
Apppublic

AkshatSahay72/GridWorld

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test.py29 linesDownload Raw Back to root
1from env import GridWorld
2import pickle
3import time
4
5# Load trained model
6with open("q_table.pkl", "rb") as f:
7    q_table = pickle.load(f)
8
9def get_q(state, action):
10    return q_table.get((tuple(state), action), 0)
11
12env = GridWorld()
13
14state = env.reset()
15
16print("\n--- TESTING ---")
17
18for step in range(20):
19    env.render()
20    time.sleep(0.5)
21
22    action = max(range(4), key=lambda a: get_q(state, a))
23
24    state, reward, done, _ = env.step(action)
25
26    if done:
27        env.render()
28        print("Finished!")
29        break