Exemple #1
0
def print_board(board):
    for row in range(board.num_rows, 0, -1):
        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('%2d %s' % (row, ''.join(line)))
    print('   ' + COLS[:board.num_cols])
Exemple #2
0
def print_board(board):
    for row in range(BOARD_SIZE, 0, -1):
        line = []
        for col in range(1, BOARD_SIZE + 1):
            stone = board.get(Point(row=row, col=col))
            line.append(STONE_TO_CHAR[stone])
        print('%2d %s' % (row, ''.join(line)))
    print('   ' + COLS[:BOARD_SIZE])
Exemple #3
0
    def encode(self, game_state, board_ext=None):
        board_tensor = np.zeros(self.shape())
        #Modify Board_ext for stones where value cost == 1 or cost == -1

        try:
            if len(board_ext._grid_ext) > 4:
                max_value, point_black = board_ext.find_max_value()
                go_string_black = game_state.board.get_go_string(point_black)
                for point in go_string_black.stones:
                    board_ext._grid_ext[point][2] = 1
        except:

            pass

        try:
            if len(board_ext._grid_ext) > 4:
                min_value, point_white = board_ext.find_min_value()
                go_string_white = game_state.board.get_go_string(point_white)
                for point in go_string_white.stones:
                    board_ext._grid_ext[point][2] = -1
        except:
            pass

        for row in range(self.board_height):
            for col in range(self.board_width):
                p = Point(row=row + 1, col=col + 1)
                go_string = game_state.board.get_go_string(p)

                if go_string is None:
                    if game_state.does_move_violate_ko(game_state.next_player,
                                                       Move.play(p)):
                        board_tensor[4][row][
                            col] = 1  # <1>  For Ko situation both is equal

                else:

                    if board_ext._grid_ext[p][2] < 0:  # for white stones
                        if board_ext._grid_ext[p][2] > -0.5:
                            board_tensor[2][row][col] = 0.5
                        else:
                            board_tensor[2][row][
                                col] = -board_ext._grid_ext[p][2]

                        liberty_white = 1 - 1.0 / (go_string.num_liberties + 1)
                        board_tensor[3][row][col] = liberty_white

                    if board_ext._grid_ext[p][2] > 0:  # for black stones
                        if board_ext._grid_ext[p][2] < 0.5:
                            board_tensor[0][row][col] = 0.5
                        else:
                            board_tensor[0][row][col] = board_ext._grid_ext[p][
                                2]

                        liberty_black = 1 - 1.0 / (go_string.num_liberties + 1)
                        board_tensor[1][row][col] = liberty_black
        return board_tensor
Exemple #4
0
 def encode(self, game_state):
     board_matrix = np.zeros(self.shape())
     next_player = game_state.next_player
     for r in range(self.board_height):
         for c in range(self.board_width):
             point = Point(row=r, col=c)
             color = game_state.get(point)
             if color is None:
                 continue
             if color == next_player:
                 board_matrix[0, r, c] = 1
             else:
                 board_matrix[0, r, c] = -1
 def encode(self, game_state):
     board_tensor = np.zeros(self.shape())
     base_plane = {
         game_state.next_player: 0,
         game_state.next_player.other: 3
     }
     for row in range(self.board_height):
         for col in range(self.board_width):
             p = Point(row=row + 1, col=col + 1)
             go_string = game_state.board.get_go_string(p)
             if go_string is None:
                 if game_state.does_move_violate_ko(game_state.next_player,
                                                    Move.play(p)):
                     board_tensor[6][row][col] = 1  # <1>
             else:
                 liberty_plane = min(3, go_string.num_liberties) - 1
                 liberty_plane += base_plane[go_string.color]
                 board_tensor[liberty_plane][row][col] = 1  # <2>
     return board_tensor
 def decode_point_index(self, index):
     row = index // self.board_width
     col = index % self.board_width
     return Point(row=row + 1, col=col + 1)