コード例 #1
0
ファイル: oneplane.py プロジェクト: BraneXZ/GoProject
 def decode_point_index(self, index):
     """
     Turns an integer index into a board point
     """
     row = index // self.board_width
     col = index % self.board_width
     return Point(row=row + 1, col=col + 1)
コード例 #2
0
    def encode(self, game_state):
        # 空箱
        board_tensor = np.zeros(self.shape())

        # 白は0,1,2黒は3,4,5を使うためにズラすとき使う
        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
                else:
                    # 呼吸点が3以上か,2か,1か
                    liberty_plane = min(3, go_string.num_liberties) - 1
                    liberty_plane += base_plane[go_string.color]
                    board_tensor[liberty_plane][row][col] = 1

        return board_tensor
コード例 #3
0
    def encode(self, game_state, board_ext=None):  # <2>
        #board_ext = Board_Ext(game_state.board)  #Nail inserted
        l = len(board_ext._grid_ext)
        board_matrix = np.zeros(self.shape())

        next_player = game_state.next_player
        color = 'w'
        if next_player.name == 'black':
            color = 'b'
        for r in range(self.board_height):
            for c in range(self.board_width):
                p = Point(row=r + 1, col=c + 1)

                try:
                    stone, cost = board_ext._grid_ext[p][
                        1], board_ext._grid_ext[p][2]  #Nail
                except:
                    stone = None
                    cost = 0

                if stone is None:
                    continue
                if stone == 'b':
                    board_matrix[0, r, c] = cost
                if stone == 'w':
                    board_matrix[0, r, c] = -cost
                # if stone.name == 'black' :
                #     board_matrix[0, r, c] = cost
                # if stone.name == 'white':
                #     board_matrix[0, r, c] = -cost

        #print(board_matrix)
        return board_matrix
コード例 #4
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])
コード例 #5
0
 def encode(self, game_state):  # <2>
     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):
             p = Point(row=r + 1, col=c + 1)
             go_string = game_state.board.get_go_string(p)
             if go_string is None:
                 continue
             if go_string.color == next_player:
                 board_matrix[0, r, c] = 1
             else:
                 board_matrix[0, r, c] = -1
     return board_matrix
コード例 #6
0
 def encode(self, game_state: GameState):
     board_tensor = np.zeroes(self.shape())
     board_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):
             point = Point(row+1, col+1)
             go_string = game_state.board.get_go_string(point)
             if go_string is None:
                 if game_state.does_move_violate_ko(game_state.next_player, Move(point)):
                     board_tensor[VIOLATE_KO][row][col] = 1
             else:
                 liberty_plane = min(3, go_string.num_liberties)
                 liberty_plane += board_plane[go_string.color]
                 board_tensor[liberty_plane][row][col] = 1
     return board_tensor
コード例 #7
0
ファイル: oneplane.py プロジェクト: sliceking/shmalpha-go
 def encode(self, game_state):
     # to encode we fill a matrix with 1 if the point contains
     # one of the current player's stones, -1 if the point contains
     # the opponent's stones and 0 if the point is empty.
     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):
             p = Point(row=r + 1, col=c + 1)
             go_string = game_state.board.get_go_string(p)
             if go_string is None:
                 continue
             if go_string.color == next_player:
                 board_matrix[0, r, c] = 1
             else:
                 board_matrix[0, r, c] = -1
     return board_matrix
コード例 #8
0
 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
コード例 #9
0
    def encode(self, game_state):
        board_tensor = np.zeros(self.shape())
        if game_state.next_player == Player.black:
            board_tensor[8] = 1
        else:
            board_tensor[9] = 1
        for r in range(self.board_height):
            for c in range(self.board_width):
                p = Point(row=r + 1, col=c + 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[10][r][c] = 1
                else:
                    liberty_plane = min(4, go_string.num_liberties) - 1
                    if go_string.color == Player.white:
                        liberty_plane += 4
                    board_tensor[liberty_plane][r][c] = 1

        return board_tensor
コード例 #10
0
ファイル: sevenplane.py プロジェクト: LJQCN101/alphago
 def decode_point_index(self, index):
     row = index // self.board_width
     col = index % self.board_width
     return Point(row=row + 1, col=col + 1)
コード例 #11
0
ファイル: oneplane.py プロジェクト: sliceking/shmalpha-go
 def decode_point_index(self, index):
     # turn an integer index into a board point
     row = index // self.board_width
     col = index % self.board_height
     return Point(row=row + 1, col=col + 1)