-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
124 lines (87 loc) · 2.93 KB
/
run.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# cython: language_level=3
import pyximport; pyximport.install()
import game
from game import Game, build_board_state, MovePiece, PlacePiece, RandomGame, Solver, SolverRecursive
import os
import time
def solve_start(depth, recursive, load):
print(depth, recursive, load)
start = time.time()
board_state = build_board_state('000000000000000000000000000')
test_game = Game(1, board_state)
print(test_game)
if recursive:
solver = SolverRecursive(test_game, depth)
if load:
if os.path.isfile('saved.pkl'):
solver.load('saved.pkl')
else:
solver = Solver(test_game, depth)
result,move,_ = solver.solve(test_game)
for (_,m,rot) in move:
test_game = test_game.rotate(rot)
test_game = test_game.apply_move(m)
print(test_game)
if recursive and load:
solver.save('saved.pkl')
print(result, move)
print('Total Time: %.3f' % (time.time()-start))
def solve_pos1(depth, load):
board_state = build_board_state('100100200000000000000020000')
test_game = Game(1, board_state)
print(test_game)
solver = SolverRecursive(test_game, depth)
if load:
solver.load('saved.pkl')
result,move = solver.solve(test_game)
print(result, move)
def solve_pos2(depth):
board_state = build_board_state('100200000000000000000000000')
test_game = Game(1, board_state)
print(test_game)
solver = Solver(test_game, depth)
result,move = solver.solve(test_game)
print(result, move)
def solve_pos3(depth):
board_state = build_board_state('100200000000100000000000000')
test_game = Game(2, board_state)
print(test_game)
solver = Solver(test_game, depth)
result,move = solver.solve(test_game)
print(result, move)
def solve_one_move():
board_state = build_board_state('100100000200200000000000000')
test_game = Game(1, board_state)
print(test_game)
solver = Solver(test_game)
result,move = solver.solve(test_game)
print(result, move)
def solve_two_move():
board_state = build_board_state('100200000200000000100000100')
test_game = Game(2, board_state)
print(test_game)
solver = Solver(test_game)
result,move = solver.solve(test_game)
print(result, move)
def random_game():
board_state = build_board_state('000000000000000000000000000')
test_game = Game(1, board_state)
print(test_game)
play = RandomGame(test_game)
play.play()
def test_hash():
board_state = build_board_state('000000000000000000000000000')
test_game = Game(1, board_state)
print(hash(test_game))
d = {test_game: '1'}
print(d)
board_state = build_board_state('000000000000000000000000000')
test_game = Game(1, board_state)
print(hash(test_game))
print(test_game in d)
if __name__ == '__main__':
solve_start(8, True, False)
#solve_start(8, True, True)
#solve_pos1(5, False)
#solve_pos2(3)
#solve_pos3(2)