-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrl_wp_reward_simulate.py
65 lines (50 loc) · 1.78 KB
/
rl_wp_reward_simulate.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 19 14:23:52 2021
@author: guansanghai
"""
import torch
import numpy as np
import random
import koikoigame
import koikoilearn
import pickle
import multiprocessing
rl_folder = 'model_rl_wp'
discard_model_path = f'{rl_folder}/discard_0_0.pt'
pick_model_path = f'{rl_folder}/pick_0_0.pt'
koikoi_model_path = f'{rl_folder}/koikoi_0_0.pt'
discard_model = torch.load(discard_model_path, map_location=torch.device('cpu'))
pick_model = torch.load(pick_model_path, map_location=torch.device('cpu'))
koikoi_model = torch.load(koikoi_model_path, map_location=torch.device('cpu'))
ai_agent = koikoilearn.Agent(discard_model, pick_model, koikoi_model)
def make_win_prob_dict(agent, round_num, point, dealer, n_test):
game_state_kwargs = {'round_num':round_num,
'init_point':[point,60-point],
'init_dealer':dealer}
arena = koikoilearn.Arena(agent, agent, game_state_kwargs)
arena.multi_game_test(n_test)
result = (round_num, point, dealer, arena.test_win_num)
print(result)
return result
if __name__ == '__main__':
dealer = 1
n_test = 200
result = []
pool = multiprocessing.Pool(24)
for round_num in [8,7,6,5,4,3,2,1]:
for point in range(1,60):
args = (ai_agent, ai_agent, round_num, point, dealer, n_test)
pool.apply_async(make_win_prob_dict, args=args, callback=result.append)
pool.close()
pool.join()
'''
for round_num in [8,7,6,5,4,3,2,1]:
for point in range(1,60):
result.append(make_win_prob_dict(ai_agent, ai_agent, round_num, point, dealer, n_test))
'''
result.sort()
print(result)
with open('result_wp_sim.pkl','wb') as f:
pickle.dump(result,f)