-
Notifications
You must be signed in to change notification settings - Fork 1
/
CheckPlayer.py
65 lines (57 loc) · 2.32 KB
/
CheckPlayer.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
65
import importlib.util
from setup import SHOT_PATH
import sys
from system import logger
import warnings
warnings.filterwarnings('ignore')
from numba.core.errors import NumbaDeprecationWarning, NumbaPendingDeprecationWarning,NumbaExperimentalFeatureWarning, NumbaWarning
warnings.simplefilter('ignore', category=NumbaDeprecationWarning)
warnings.simplefilter('ignore', category=NumbaPendingDeprecationWarning)
warnings.simplefilter('ignore', category=NumbaExperimentalFeatureWarning)
warnings.simplefilter('ignore', category=NumbaWarning)
COUNT_TEST = 1000
#check hết hệ thống
def CheckAllFunc(Agent, BOOL_CHECK_ENV, msg):
for func in ['DataAgent', 'Train', 'Test']:
try:
getattr(Agent, func)
except:
#logger.warn(f'Không có hàm: {func}')
msg.append(f'Không có hàm: {func}')
BOOL_CHECK_ENV = False
return BOOL_CHECK_ENV, msg
def setup_game(game_name):
try:
spec = importlib.util.spec_from_file_location('env', f"{SHOT_PATH}base/{game_name}/env.py")
except:
spec = importlib.util.spec_from_file_location('env', f"base/{game_name}/env.py")
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def CheckRunGame(Agent, BOOL_CHECK_ENV, msg):
for game_name in ['Splendor_v2', 'Splendor_v3', 'MachiKoro', 'SushiGo', 'TLMN', 'TLMN_v2']:
env = setup_game(game_name)
try:
per = Agent.DataAgent()
win, per = env.numba_main_2(Agent.Train, COUNT_TEST, per, 0)
except:
#logger.warn(f'Train đang bị lỗi ở game {game_name}')
msg.append(f'Train đang bị lỗi {game_name}')
BOOL_CHECK_ENV = False
break
try:
per = Agent.DataAgent()
win, per = env.numba_main_2(Agent.Test, COUNT_TEST, per, 0)
except:
#logger.warn(f'Test đang bị lỗi {game_name}')
msg.append(f'Test đang bị lỗi {game_name}')
BOOL_CHECK_ENV = False
break
return BOOL_CHECK_ENV, msg
def check_agent(Agent):
BOOL_CHECK_ENV = True
msg = []
BOOL_CHECK_ENV, msg = CheckAllFunc(Agent, BOOL_CHECK_ENV, msg)
BOOL_CHECK_ENV, msg = CheckRunGame(Agent, BOOL_CHECK_ENV, msg)
return BOOL_CHECK_ENV, msg