-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_random.py
43 lines (29 loc) · 1.05 KB
/
main_random.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
import asyncio
import sys
sys.path.append("modules")
import time # noqa: E402
import numpy as np # noqa: E402 F401
from gobblet_rl import gobblet_v1 # noqa: E402
PLAYER = 0
DEPTH = 2
RENDER_MODE = "human"
RENDER_DELAY = 0.1
async def main() -> None:
env = gobblet_v1.env(render_mode="human", args=None)
env.reset()
env.render() # need to render the environment before pygame can take user input
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
if termination or truncation:
print(f"Agent: ({agent}), Reward: {reward}, info: {info}")
break
action_mask = observation["action_mask"]
action = np.random.choice(
np.arange(len(action_mask)), p=action_mask / np.sum(action_mask)
)
# Wait .5 seconds between moves so the user can follow the sequence of moves
time.sleep(0.5)
env.step(action)
await asyncio.sleep(0) # Very important, and keep it 0
if __name__ == "__main__":
asyncio.run(main())