-
Notifications
You must be signed in to change notification settings - Fork 0
/
gp.py
64 lines (37 loc) · 2.16 KB
/
gp.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def greedy_policy(en=None,tot=20000,action_freq={},actions_matrix=[],game=None,fp_flag=False,debug=False,save_all_states = False,save_collected_data= {},save_actions_matrix=False):
actions_m = []
start_state = en.copy_state()
game_states = [start_state]
for step in range(tot):
for action in range(6):
won,taken = en.step(action,fp_flag,debug)
if won == True:
action_freq[action]+=1
actions_m.append(action)
if save_actions_matrix == True:
game_states.append(en.state)
actions_matrix[game] = [game,actions_m,en.state,start_state,"won"]
hashable_state = en.generate_hashable_state_modified(en.state)
save_collected_data[hashable_state] = action
if save_all_states == True:
actions_matrix[game].append(game_states)
return len(actions_m),True
if taken == True:
action_freq[action]+=1
actions_m.append(action)
if save_actions_matrix == True:
game_states.append(en.state)
hashable_state = en.generate_hashable_state_modified(en.state)
save_collected_data[hashable_state] = action
break
if taken == False:
if save_actions_matrix:
actions_matrix[game] = [game,actions_m,en.state,start_state,"No action could be taken"]
if save_all_states == True:
actions_matrix[game].append(game_states)
return len(actions_m),False
if save_actions_matrix:
actions_matrix[game] = [game,actions_m,en.state,start_state,"Steps exhausted"]
if save_all_states == True:
actions_matrix[game].append(game_states)
return len(actions_m),False