Beispiel #1
0
def get_own_board(fn, until=None):
    """Use goplanes library from this repository for board representation.

    Remarks:
        This uses the feature-plane code (input for NN) to create the board positions.
        We just use it for testing. So far all final board configurations from `GoGoD`
        matches the ones from GnuGO.

    Args:
        fn (str): path to *.sgfbin file
        until (int, optional): number of moves to play (with handicap stones)

    Returns:
        (np.array, np.array): all placed white tokens, all placed black tokens
    """
    max_moves = os.path.getsize(fn + 'bin') / 2
    print('[own] has %i moves' % max_moves)
    planes = np.zeros((47, 19, 19), dtype=np.int32)
    if until is not None:
        until = max(0, until + 2)
    else:
        until = -1
    print('[own] play %i moves' % until)
    goplanes.planes_from_file(fn + 'bin', planes, until)

    from_black = (planes[-1][0][0] == 1)
    if from_black:
        actual_b = planes[0]
        actual_w = planes[1]
    else:
        actual_b = planes[1]
        actual_w = planes[0]

    return actual_w, actual_b
Beispiel #2
0
def get_own_board(fn, until=None):
    """Use goplanes library from this repository for board representation.

    Remarks:
        This uses the feature-plane code (input for NN) to create the board positions.
        We just use it for testing. So far all final board configurations from `GoGoD`
        matches the ones from GnuGO.

    Args:
        fn (str): path to *.sgfbin file
        until (int, optional): number of moves to play (with handicap stones)

    Returns:
        (np.array, np.array): all placed white tokens, all placed black tokens
    """
    max_moves = os.path.getsize(fn + 'bin') / 2
    planes = np.zeros((47, 19, 19), dtype=np.int32)
    if until is not None:
        max_moves = max(0, until - 1)
    max_moves -= 1
    next_move = goplanes.planes_from_file(fn + 'bin', planes, max_moves)

    current_player_is_black = (planes[-1][0][0] == 1)

    if current_player_is_black:
        print('from perspective of black')
    else:
        print('from perspective of white')
        # own stones in plane[0]

    y = next_move % 19
    x = (next_move - y) // 19
    print x, y

    planes[0][x][y] = 1

    if current_player_is_black:
        actual_b = planes[0]
        actual_w = planes[1]
    else:
        actual_w = planes[0]
        actual_b = planes[1]

    return actual_w, actual_b
Beispiel #3
0
next_is_white = (until % 2 == 0)

if next_is_white:
    print "situation for white"
else:
    print "situation for black"

fn = "2p0y-gokifu-20170527-Ke_Jie-AlphaGo.sgf"

gnugo = GnuGoEngine('gnugo', ["--infile", fn, '-L', str(until)], verbose=True)
gnugo.call_show_board()
gnugo_planes = gnugo.get_planes(next_is_white)


tfgo_planes = np.zeros((NUM_FEATURES, 19, 19), dtype=np.int32)
next_move = goplanes.planes_from_file(fn + 'bin', tfgo_planes, until)
x = next_move % 19
y = next_move // 19


prob = np.zeros((19, 19), dtype=np.int32)
prob[x, y] = 100
i = 0
candidates = np.dstack(np.unravel_index(np.argsort(prob.ravel())[::-1], (19, 19)))
x, y = candidates[0][i][0], candidates[0][i][1]


def tuple2string(pos):
    # 12, 13 from top left --> O7
    charset = "ABCDEFGHJKLMNOPQRST"
    x, y = pos
Beispiel #4
0
parser.add_argument('--steps',
                    help='number of moves to play',
                    type=np.int32,
                    default=10)
args = parser.parse_args()

path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                    '../../data/game.sgfbin')
assert os.path.isfile(path)

# Version from file
# --------------------------------------------------------
max_moves = os.path.getsize(path) / 2
planes = np.zeros((47 * 19 * 19), dtype=np.int32)
steps = min(int(args.steps), max_moves - 1)
next_move = goplanes.planes_from_file(path, planes, steps)
planes = planes.reshape((47, 19, 19))

board = np.zeros((19, 19), dtype=str)
board[planes[0, :, :] == 1] = 'o'
board[planes[1, :, :] == 1] = 'x'
board[planes[2, :, :] == 1] = '.'

for i in range(19):
    print " ".join(board[i, :])
print "max", max_moves
print "next", next_move

# Version from bytes
# --------------------------------------------------------
raw = np.fromfile(path, dtype=np.int8)