-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_play_history.py
49 lines (40 loc) · 1.18 KB
/
generate_play_history.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
44
45
46
47
48
import numpy as np
import pickle
from game import UNO
from agents.greedyAgent import GreedyAgent
all_actions = []
all_prev = []
all_hands = []
agent_1 = GreedyAgent()
agent_2 = GreedyAgent()
for i in range(10000):
action_list = [[],[]]
hands_list = [[],[]]
prev_list = [[],[]]
uno = UNO([agent_1, agent_2], "finite_deck", forced_draw_only=False)
while True:
while True:
action = uno.get_action()
current_player = uno.current_player
hands_list[current_player].append(uno.hands[current_player].copy())
prev_list[current_player].append(uno.previous_card)
action_list[current_player].append(action)
if uno.apply_action(action):
break
if uno.current_win():
winner = uno.current_player
break
uno.next_player()
uno.penalize()
all_actions.append(action_list[0])
all_actions.append(action_list[1])
all_prev.append(prev_list[0])
all_prev.append(prev_list[1])
all_hands.append(hands_list[0])
all_hands.append(hands_list[1])
with open('hands.pkl','wb') as f:
pickle.dump(all_hands, f)
with open('prev.pkl','wb') as f:
pickle.dump(all_prev, f)
with open('actions.pkl','wb') as f:
pickle.dump(all_actions, f)