def print_board(board): 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(gotypes.Point(row=row, col=col)) line.append(STONE_TO_CHAR[stone]) print('%s%d %s' % (bump, row, ''.join(line))) print(' ' + ' '.join(COLS[:board.num_cols]))
def capture_diff(game_state): black_stones = 0 white_stones = 0 for r in range(1, game_state.board.num_rows + 1): for c in range(1, game_state.board.num_cols + 1): p = gotypes.Point(r, c) color = game_state.board.get(p) if color == gotypes.Player.black: black_stones += 1 elif color == gotypes.Player.white: white_stones += 1 diff = black_stones - white_stones # <1> if game_state.next_player == gotypes.Player.black: # <2> return diff # <2> return -1 * diff # <3>
def point_from_coords(coords): col = COLS.index(coords[0]) + 1 row = int(coords[1:]) return gotypes.Point(row=row, col=col)