-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
45 lines (37 loc) · 1.16 KB
/
utils.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
from typing import Dict, Optional
from goboard_slow import Board, Move
from gotypes import Player, Point
COLS = "ABCDEFGHJKLMNOPQRST"
STONE_TO_CHAR: Dict[Optional[Player], str] = {
None: " . ",
Player.BLACK: " x ",
Player.WHITE: " o ",
}
def print_move(player: Player, move: Move) -> None:
"""
Prints the player's move in a readable format.
Args:
player (Player): The player making the move.
move: The move being made.
"""
if move.is_pass:
move_str = "passes"
elif move.is_resign:
move_str = "resigns"
else:
move_str = f"{COLS[move.point.col - 1]}{move.point.row}"
print(f"{player} {move_str}")
def print_board(board: Board) -> None:
"""
Prints the current state of the board.
Args:
board: The board to be printed.
"""
for row in range(board.num_rows, 0, -1):
bump = " " if row <= 9 else ""
line = []
for col in range(1, board.num_cols + 1):
stone = board.get(Point(row=row, col=col))
line.append(STONE_TO_CHAR[stone])
print(f"{bump}{row} {''.join(line)}")
print(" " + " ".join(COLS[: board.num_cols]))