-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve_all.py
104 lines (78 loc) · 2.59 KB
/
solve_all.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
92
93
94
95
96
97
98
99
100
101
102
103
104
from itertools import combinations
import numpy as np
from genius_star import Dice, Game, NoSolution
solver = "exact_cover" # alternative is "xcover"
def naive_solution_count():
dice = Dice()
game = Game()
star_games = 0
for i, roll in enumerate(dice.all_rolls()):
game.new_roll(roll, star=True)
solution = game.solve(solver)
if solution.game.star == True:
star_games += 1
print(f" {i+1} games solved ({star_games} star games)", end="\r")
print(f" {i+1} games solved ({star_games} star games)")
def count_dice_roll_solutions():
dice = Dice()
solution_count(dice.all_rolls())
def count_all_solutions():
rolls = combinations(range(1, 49), 7)
solution_count(rolls)
def solution_count(rolls):
game = Game()
star_games = 0
solved_games = 0
nosolution_games = 0
unique_star_games = 0
unique_solved_games = 0
unique_nosolution_games = 0
star_seen = set()
nostar_seen = set()
nosolution_seen = set()
for r in rolls:
roll = tuple(game.board.equivalent_roll(r))
# Only solve problems which are related by symmetry once
if roll in star_seen:
star_games += 1
solved_games += 1
continue
if roll in nostar_seen:
solved_games += 1
continue
if roll in nosolution_seen:
nosolution_games += 1
continue
game.new_roll(roll, star=True)
try:
solution = game.solve(solver)
except:
unique_nosolution_games += 1
nosolution_games += 1
nosolution_seen.add(roll)
continue
solved_games += 1
unique_solved_games += 1
if solution.game.star == True:
star_games += 1
unique_star_games += 1
star_seen.add(roll)
else:
nostar_seen.add(roll)
print(
f" {unique_solved_games} unique games solved ({unique_star_games} unique star games)",
end="\r",
)
print(
f" {unique_solved_games} unique games solved ({unique_star_games} unique star games)"
)
print(f" {solved_games} games solved ({star_games} star games)")
if nosolution_games > 0:
print(
f"Searched {solved_games + nosolution_games} games ({unique_solved_games+unique_nosolution_games} unique)"
)
if __name__ == "__main__":
print("Counting dice roll solutions:")
count_dice_roll_solutions()
print("Counting solutions for all blocker positions (takes a long time!):")
count_all_solutions()