-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
92 lines (69 loc) · 2.53 KB
/
debug.py
File metadata and controls
92 lines (69 loc) · 2.53 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from modules.TestManager import TestMapManager, TestGamesManager
from modules.GoldStrike import GoldStrike
from modules.MCTS import MCTS
# game_test=TestGamesManager()
# game_manager=TestMapManager()
import pickle
import time
import multiprocessing as mp
from functools import partial
'''
D:\PythonProjects\Alpha_gold\.venv\Scripts\python.exe D:\PythonProjects\Alpha_gold\debug.py
'''
N_ITER=100
M_SIM=100
M_ROLL=100
LEVEL=20
def mcts_play(args):
game, preloaded_map = args
mcts_n_simulations = M_SIM
mcts_rollout_max_depth = M_ROLL
display_board = False
mcts = MCTS(game)
while not mcts.root.game_state.isTerminated():
mcts.run(mcts_n_simulations, mcts_rollout_max_depth)
action = mcts.select_action()
mcts.root.game_state.make_move(action, preloaded_map)
mcts=MCTS(mcts.root.game_state)
if display_board:
mcts.root.game_state.display_pretty_board()
print(mcts.root.game_state.game_result)
return mcts.root.game_state.game_result
def mcts_play(args):
game, preloaded_map = args
mcts_n_simulations = M_SIM
mcts_rollout_max_depth = M_ROLL
display_board = False
mcts = MCTS(game)
while not mcts.root.game_state.isTerminated():
mcts.run(mcts_n_simulations, mcts_rollout_max_depth)
action = mcts.select_action()
mcts.root.game_state.make_move(action, preloaded_map)
mcts=MCTS(mcts.root.game_state)
if display_board:
mcts.root.game_state.display_pretty_board()
print(mcts.root.game_state.game_result)
return mcts.root.game_state.game_result
if __name__ == '__main__':
print({
'level':LEVEL,
'm_sim':M_SIM,
'rolls':M_ROLL,
})
start_time = time.time()
test_map_manager = TestMapManager()
game_states = [GoldStrike(LEVEL) for _ in range(N_ITER)]
test_maps = [test_map_manager.load_test_map(LEVEL, iteration) for iteration in range(0, N_ITER)]
game_map_pairs = list(zip(game_states, test_maps))
pool = mp.Pool(processes=6)
results = pool.map(mcts_play, game_map_pairs)
print(results)
end_time = time.time()
elapsed_time = end_time - start_time
hours, remainder = divmod(elapsed_time, 3600)
minutes, seconds = divmod(remainder, 60)
formatted_time = "{:02}:{:02}:{:02}".format(int(hours), int(minutes), int(seconds))
print(formatted_time)
# Save the results list to a file using pickle
with open(r'D:\PythonProjects\Alpha_gold\data\results.pickle', 'wb') as f:
pickle.dump(results, f)