-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRummy.py
More file actions
27 lines (23 loc) · 859 Bytes
/
Copy pathRummy.py
File metadata and controls
27 lines (23 loc) · 859 Bytes
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
from rummy.env import RummyEnv
from rummy.agents import RandomAgent
def main() -> None:
env = RummyEnv(["Alice", "Bob"], seed=42)
agent = RandomAgent(seed=42)
observation = env.reset()
print("Starting Rummy environment")
env.render()
while not env.done:
action = agent.choose_action(observation)
observation, reward, done, info = env.step(action)
if action["type"] in {"draw_deck", "draw_discard"}:
discard = agent.choose_discard(observation)
observation, reward, done, info = env.step(discard)
print(f"Action: {action}, reward: {reward}, done: {done}")
if done:
print("Game finished", info)
break
observation = env._observation(env.game.current_player)
print("Final state:")
env.render()
if __name__ == "__main__":
main()