forked from atomic-maths/target1000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
47 lines (32 loc) · 863 Bytes
/
benchmark.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
import random
from dice import roll_dice
from grid import Grid
from strategy import auto_pick_position
def debug(msg, show_debug):
if (show_debug):
print(msg)
def run_game(show_debug):
grid = Grid()
while not grid.is_complete():
roll = roll_dice()
debug("Rolled a " + str(roll), show_debug)
auto_pick_position(roll, grid)
score = grid.score_complete_grid()
if (show_debug): grid.pretty_print()
return score
def benchmark(runs):
i = 0
score_total = 0
while i < runs:
i += 1
score = run_game(False)
score_total += score
print("\n")
print("benchmark = " + str(score_total / runs))
def main():
benchmark_runs = 100000
option = int(input("Would you like to (1) show a debug or (2) run a benchmark? "))
if (option == 2): return benchmark(benchmark_runs)
print("Score was ", run_game(True))
if __name__ == "__main__":
main()