-
Notifications
You must be signed in to change notification settings - Fork 0
/
drive.py
47 lines (37 loc) · 1.19 KB
/
drive.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
from absl import flags, logging, app
import numpy as np
import game
import players
FLAGS = flags.FLAGS
flags.DEFINE_string("player", "random", "random / sequential / estimator")
flags.DEFINE_integer("trials", 1000, "number of trials")
def main(argv):
player_class = players.player_factory(FLAGS.player)
if player_class is None:
raise ValueError("No player named %s", FLAGS.player)
res = np.zeros(FLAGS.trials, dtype=int)
top_score = 0
for n in range(FLAGS.trials):
draw = game.draw()
player = player_class()
for tile in draw:
player.play(tile)
score = player.score()
if score > top_score:
top_score = score
logging.info("game number = %s", n)
logging.info("New max score of %s", score)
logging.info("draw = %s", draw)
logging.info("play = %s", player.state)
res[n] = score
logging.warning(
"Did %s trials with player %s: mean, median, min, max = %.2f, %.2f, %s, %s",
FLAGS.trials,
FLAGS.player,
res.mean(),
np.median(res),
res.min(),
res.max(),
)
if __name__ == "__main__":
app.run(main)