-
Notifications
You must be signed in to change notification settings - Fork 0
/
splendor_fastest_win.py
66 lines (59 loc) · 1.64 KB
/
splendor_fastest_win.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
#!/usr/bin/env python
"""A tool to bruteforce fastest winning moves for the board game Splendor."""
import argparse
import sys
from src.buys import export_buys_to_txt, load_buys
from src.color import Color
from src.solver import State
def cli():
parser = argparse.ArgumentParser(
description=__doc__,
)
parser.add_argument(
'goal_pts',
help='target amount of points',
nargs='?',
type=int,
)
parser.add_argument(
'-u',
'--use_heuristic',
help='use a heuristic formula to limit the search space of BFS',
action='store_true',
)
parser.add_argument(
'-b',
'--buys',
help='regenerate and store all possible buys',
action='store_true',
)
parser.add_argument(
'-e',
'--export',
help='export possible buys to a .txt file',
action='store_true',
)
if len(sys.argv) == 1: # no arguments given
parser.print_help()
parser.exit()
args = parser.parse_args()
try:
if args.export:
export_buys_to_txt()
return
if args.buys:
load_buys(update=True)
if args.goal_pts:
solution = State.newgame().solve(
goal_pts=args.goal_pts,
use_heuristic=args.use_heuristic,
)
print('\nSolution:')
print(f'({", ".join(c.name.title() for c in Color)}) Cards')
for state in solution:
print(state)
except KeyboardInterrupt:
print('Execution stopped by the user.')
parser.exit()
if __name__ == '__main__':
cli()