Created
December 8, 2016 13:40
-
-
Save nariaki3551/8290d1457da917d3b6eb59cbb12070df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bord = [[-1 for _ in range(8)] for __ in range(8)] | |
#初期配置 | |
bord[3][3] = bord[4][4] = 1 | |
bord[3][4] = bord[4][3] = 0 | |
def is_all(_list, BorW): | |
for i in _list: | |
if i != BorW: | |
return False | |
else: | |
return True | |
def serch_left_index(_list, x, BorW): | |
sub_list = _list[:x] | |
for index, elm in enumerate(sub_list[::-1]): | |
if elm == BorW: | |
return x-index-1 | |
else: | |
return None | |
def serch_right_index(_list, x, BorW): | |
sub_list = _list[x+1:] | |
for index, elm in enumerate(sub_list): | |
if elm == BorW: | |
return x+index+1 | |
else: | |
return None | |
def run(x, y, BorW): | |
bord[x][y] = BorW | |
# 横 --------------------------- | |
row_list = bord[x] | |
left_index = serch_left_index(row_list, y, BorW) | |
right_index = serch_right_index(row_list, y, BorW) | |
if left_index is not None: # 横左 | |
can_list = row_list[left_index+1:y] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(left_index+1, y): | |
bord[x][z] = BorW | |
if right_index is not None: # 横右 | |
can_list = row_list[y+1:right_index] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(y+1, right_index): | |
bord[x][z] = BorW | |
# 縦 ----------------------------- | |
column_list = [bord[i][y] for i in range(8)] | |
left_index = serch_left_index(column_list, x, BorW) | |
right_index = serch_right_index(column_list, x, BorW) | |
if left_index is not None: # 縦上 | |
can_list = column_list[left_index+1:x] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(left_index+1, x): | |
bord[z][y] = BorW | |
if right_index is not None: # 縦下 | |
can_list = column_list[x+1:right_index] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(x+1, right_index): | |
bord[z][y] = BorW | |
# 右斜め -------------------------- | |
slide_index = [(i, x+y-i) for i in range(x+y+1) if i < 8 and x+y-i < 8] | |
key_x = slide_index.index((x, y)) | |
slide_list = [bord[i][j] for i, j in slide_index] | |
left_index = serch_left_index(slide_list, key_x, BorW) | |
right_index = serch_right_index(slide_list, key_x, BorW) | |
if left_index is not None: | |
can_list = slide_list[left_index+1:key_x] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(left_index+1, key_x): | |
i, j = slide_index[z] | |
bord[i][j] = BorW | |
if right_index is not None: | |
can_list = slide_list[key_x+1:right_index] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(key_x, right_index): | |
i, j = slide_index[z] | |
bord[i][j] = BorW | |
# 左斜め -------------------------- | |
diff = max(x-y, y-x) | |
slide_index = [(x-i, y-i) for i in range(8) if x >= i and y >= i] \ | |
+ [(x+i, y+i) for i in range(1, 8) if x+i < 8 and y+i < 8] | |
key_x = slide_index.index((x, y)) | |
slide_list = [bord[i][j] for i, j in slide_index] | |
left_index = serch_left_index(slide_list, key_x, BorW) | |
right_index = serch_right_index(slide_list, key_x, BorW) | |
if left_index is not None: | |
can_list = slide_list[left_index+1:key_x] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(left_index+1, key_x): | |
i, j = slide_index[z] | |
bord[i][j] = BorW | |
if right_index is not None: | |
can_list = slide_list[key_x+1:right_index] | |
if is_all(can_list, (BorW+1)%2): | |
for z in range(key_x, right_index): | |
i, j = slide_index[z] | |
bord[i][j] = BorW | |
N = int(input()) | |
count = 0 | |
while count < N: | |
# for _ in range(8): | |
# for __ in range(8): | |
# if bord[_][__] == -1: | |
# print('-', end='') | |
# else: | |
# print(bord[_][__], end='') | |
# print() | |
BorW, x, y = input().split() | |
BorW = 0 if BorW == 'B' else 1 | |
x = int(x) - 1 | |
y = int(y) - 1 | |
run(x, y, BorW) | |
count = count + 1 | |
y_score = 0 | |
for i in range(8): | |
for j in range(8): | |
if bord[i][j] == 1: | |
y_score += 1 | |
x_score = N+4 - y_score | |
if x_score > y_score: | |
s = 'The black won!' | |
elif y_score > x_score: | |
s = 'The white won!' | |
else: | |
s = 'Draw!' | |
print('{xx:02d}-{yy:02d} {s}'.format(xx=x_score, yy=y_score, s=s)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment