-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
91 lines (73 loc) · 2.64 KB
/
test.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import multiprocessing
import sys
from game.game import Game
from game.deck import DECK50, DECK55
if __name__ == "__main__":
# default values
ai = "alphahanabi"
ai_params = {}
num_players = 5
num_simulations = 1000
deck_type = DECK55
if '-a' in sys.argv[1:]:
# select AI to be used
i = sys.argv.index('-a')
assert len(sys.argv) >= i+2
ai = sys.argv[i+1]
if '-n' in sys.argv[1:]:
# read number of players
i = sys.argv.index('-n')
assert len(sys.argv) >= i+2
num_players = int(sys.argv[i+1])
if '-m' in sys.argv[1:]:
# read number of simulations
i = sys.argv.index('-m')
assert len(sys.argv) >= i+2
num_simulations = int(sys.argv[i+1])
if '-p' in sys.argv[1:]:
# set difficulty parameter
i = sys.argv.index('-p')
assert len(sys.argv) >= i+2
ai_params['difficulty'] = sys.argv[i+1]
if '-d' in sys.argv[1:]:
# choose deck type
i = sys.argv.index('-d')
assert len(sys.argv) >= i+2
assert sys.argv[i+1] in ['standard', 'black']
if sys.argv[i+1] == 'standard':
deck_type = DECK50
results = []
print "Starting %d simulations with %d players..." % (num_simulations, num_players)
def run_game(i):
#print(i, end=' ', file=sys.stderr, flush = True)
game = Game(
num_players=num_players,
ai=ai,
ai_params=ai_params,
strategy_log=False,
dump_deck_to='deck.txt',
load_deck_from=None,
deck_type=deck_type,
)
game.setup()
for current_player, turn in game.run_game():
pass
return game.statistics
pool = multiprocessing.Pool(4)
#pool.map = map # uncomment for debugging purposes
results = pool.map(run_game, range(num_simulations))
print
scores = [statistics.score for statistics in results]
print "Results"
print sorted(scores)
print "Number of players:", num_players
print "Average result:", float(sum(scores)) / len(scores)
print "Best result:", max(scores)
print "Worst result:", min(scores)
print "Rate of perfect scores: %.2f %%" % (float(scores.count(30 if deck_type == DECK55 else 25)) / len(scores) * 100.0)
lives = [statistics.lives for statistics in results]
print "Average number of remaining lives:", float(sum(lives)) / len(lives)
num_turns = [statistics.num_turns for statistics in results]
print "Average number of turns:", float(sum(num_turns)) / len(num_turns)