-
Notifications
You must be signed in to change notification settings - Fork 3
/
gui.py
75 lines (63 loc) · 2.21 KB
/
gui.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
import copy
import board
import config
from util import line_2_plane
string_board = [
list(" A B C D E F G H"),
list("1 ┌─┬─┬─┬─┬─┬─┬─┐"),
list("2 ├─┼─┼─┼─┼─┼─┼─┤"),
list("3 ├─┼─┼─┼─┼─┼─┼─┤"),
list("4 ├─┼─┼─┼─┼─┼─┼─┤"),
list("5 ├─┼─┼─┼─┼─┼─┼─┤"),
list("6 ├─┼─┼─┼─┼─┼─┼─┤"),
list("7 ├─┼─┼─┼─┼─┼─┼─┤"),
list("8 └─┴─┴─┴─┴─┴─┴─┘")
]
black_sign = "●"
white_sign = "○"
legal_move_sign = "×"
def bit_to_sign(bit, sign, cur_string_board):
bit_list = list(reversed((("0" * config.board_length) + bin(bit)[2:])[-config.board_length:]))
for i, v in enumerate(bit_list):
if v == "1":
x = i % config.N
y = i // config.N
x += 2 + x
y += 1
cur_string_board[y][x] = sign
def array_to_sign(array, sign, cur_string_board):
for i, v in enumerate(array):
if i == config.pass_move:
return
if v == 1:
x = i % config.N
y = i // config.N
x += 2 + x
y += 1
cur_string_board[y][x] = sign
def print_node(node):
cur_string_board = copy.deepcopy(string_board)
bit_to_sign(node.board.black, black_sign, cur_string_board)
bit_to_sign(node.board.white, white_sign, cur_string_board)
array_to_sign(node.legal_moves, legal_move_sign, cur_string_board)
print("=================")
for line in cur_string_board:
print("".join(line))
last_move = ""
if node.move == config.pass_move:
last_move = "pass"
else:
last_move = line_2_plane(node.move)
player = ""
opponent = ""
if node.player == config.black:
player = black_sign + " black"
opponent = white_sign + " white"
else:
player = white_sign + " white"
opponent = black_sign + " black"
print("")
if node.is_game_root is not True:
print(opponent + " plays " + last_move + ".")
if node.is_terminal is not True:
print("it's " + player + " turn.")