-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass_live.py
142 lines (115 loc) · 3.15 KB
/
pass_live.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import sys
import simple_go
from utils import *
start_no = long(sys.argv[1])
end_no = long(sys.argv[2])
fp = open("pass_live.log", "w")
whole_board_flag = False
if whole_board_flag:
#size = 3
#limit = 3
size = 6
limit = 12
else:
#size = 2
#limit = 2
#size = 3
#limit = 3
#size = 4
#limit = 5
#size = 5
#limit = 7
size = 6
limit = 11
bits = size**2
if whole_board_flag:
win_condition = size**2 #whole board win
else:
win_condition = 1
if not end_no:
end_no = 2**bits
def write(s):
sys.stdout.write(s)
sys.stdout.flush()
fp.write(s)
fp.flush()
write("Running with size %i with stone limit at %i\n" % (size, limit))
write("from position %s to position %s\n" % (start_no, end_no))
write("Result to screen and to pass_live.log\n")
write("Win condition: %i points\n\n" % win_condition)
best_bit_win = {}
for i in range(limit+1):
best_bit_win[i] = 1
def create_board(size):
simple_board = []
for y in range(size):
simple_board.append([0]*size)
return simple_board
def ref1(b2, b1, x, y, size=size):
b2[x][y] = b1[size-1-x][y]
def ref2(b2, b1, x, y, size=size):
b2[x][y] = b1[x][size-1-y]
def ref3(b2, b1, x, y, size=size):
b2[x][y] = b1[size-1-x][size-1-y]
def ref4(b2, b1, x, y, size=size):
b2[x][y] = b1[y][x]
def ref5(b2, b1, x, y, size=size):
b2[x][y] = b1[y][size-1-x]
def ref6(b2, b1, x, y, size=size):
b2[x][y] = b1[size-1-y][x]
def ref7(b2, b1, x, y, size=size):
b2[x][y] = b1[size-1-y][size-1-x]
def iterate_bit_goban(no, bits=bits):
x = 1
y = 1
for i in xrange(bits):
if (1L<<i) & no:
yield x,y
x += 1
if x>size:
x = 1
y += 1
def binary_str(no):
s = ""
while no:
s = str(no%2) + s
no = no / 2
return s
simple_board2 = create_board(size)
no = start_no
while no<=end_no and no<2**bits:
bit_count = 0
for i in xrange(bits):
if (1L<<i) & no:
bit_count += 1
if no%1000==0:
sys.stderr.write("%i\r" % no)
#print "?", binary_str(no), bit_count
if bit_count > limit:
i = 0
while not ((1L<<i) & no):
i += 1
if i > 0:
#print "skip by", (2**i - 1)
no += (2**i - 1)
#print "!", binary_str(no), bit_count
if bit_count<=limit:
simple_board = create_board(size)
for x,y in iterate_bit_goban(no):
simple_board[x-1][y-1] = 1
for reflection_function in ref1, ref2, ref3, ref4, ref5, ref6, ref7:
for x in range(size):
for y in range(size):
reflection_function(simple_board2, simple_board, x, y)
if simple_board2 < simple_board:
break
else:
b = simple_go.Board(size)
for x,y in iterate_bit_goban(no):
b.add_stone(simple_go.BLACK, (x, y))
score = b.unconditional_score(simple_go.BLACK)
if score>=best_bit_win[bit_count]:
write("no: %i, bits: %i, score: %i\n%s\n" % (no, bit_count, score, b))
best_bit_win[bit_count] = score
no = no + 1
fp.close()