コード例 #1
0
def test_game_board():
    game = game_from_sgf("""
        (;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]
        RU[Japanese]SZ[9]HA[2]KM[6.50]
        PW[White]PB[Black]AB[gc][cg]
        (;W[gg]
        ;B[ff]
        ;W[dd])
        (;W[ee]
        ;B[gg]))
        """)

    assert len(game.board.tree) == 6
    assert game.board.current_node_id == 0
    assert len(game.board.current_node.children) == 2
    assert game.board.current_node.action == 'E'

    child = game.board.tree[game.board.current_node.children[0]]
    grand_child = game.board.tree[child.children[0]]
    assert child.action == 'W'
    assert child.move == coord_from_sgf('gg', game.board.size)
    assert grand_child.action == 'B'
    assert grand_child.move == coord_from_sgf('ff', game.board.size)

    child = game.board.tree[game.board.current_node.children[1]]
    grand_child = game.board.tree[child.children[0]]
    assert child.action == 'W'
    assert child.move == coord_from_sgf('ee', game.board.size)
    assert grand_child.action == 'B'
    assert grand_child.move == coord_from_sgf('gg', game.board.size)
コード例 #2
0
def test_game_board_setup_stones():
    game = game_from_sgf('(;AB[dd][de]AW[qq][qr])')

    assert len(game.board.tree) == 1

    node = game.board.tree[0]
    assert len(node.children) == 0
    assert len(node.edits.items()) == 4
    assert node.edits.get(str(coord_from_sgf('dd', 19))) == BLACK
    assert node.edits.get(str(coord_from_sgf('de', 19))) == BLACK
    assert node.edits.get(str(coord_from_sgf('qq', 19))) == WHITE
    assert node.edits.get(str(coord_from_sgf('qr', 19))) == WHITE
コード例 #3
0
def _replay_game(board, node):
    if node.props.get('AB') or node.props.get('AW') or node.props.get('AE'):
        board.add_edits(_prop_coords(node.props.get('AB'), board.size),
                        _prop_coords(node.props.get('AW'), board.size),
                        _prop_coords(node.props.get('AE'), board.size))

    if node.prop_one('B'):
        board.current = BLACK
        board.play(coord_from_sgf(node.prop_one('B'), board.size))

    if node.prop_one('W'):
        board.current = WHITE
        board.play(coord_from_sgf(node.prop_one('W'), board.size))

    current_node_id = board.current_node_id

    for child in node.children:
        board.current_node_id = current_node_id
        _replay_game(board, child)
コード例 #4
0
ファイル: test_games.py プロジェクト: Jiankun-Huang/JGS
def play_one_game(node, db, socket):
    game = GameFactory(board=Board(19))
    svc_black = GameService(db, socket, game.black_user)
    svc_white = GameService(db, socket, game.white_user)

    black_turn = True

    while True:
        coord = node.prop_one('B') if black_turn else node.prop_one('W')
        coord = coord_from_sgf(coord, 19)

        svc = svc_black if black_turn else svc_white
        svc.execute('move', {'game_id': game.id, 'move': coord})

        if not node.children:
            break

        node = node.children[0]
        black_turn = not black_turn
コード例 #5
0
def _prop_coords(coords, size):
    if not coords:
        return []
    return [coord_from_sgf(c, size) for c in coords]
コード例 #6
0
def test_coord_from_sgf():
    assert coord_from_sgf("Aa", 19) == coord2d(1, 1, 19)
    assert coord_from_sgf("Ca", 19) == coord2d(3, 1, 19)
    assert coord_from_sgf("dD", 19) == coord2d(4, 4, 19)
    assert coord_from_sgf("Dp", 19) == coord2d(4, 16, 19)
    assert coord_from_sgf("sS", 19) == coord2d(19, 19, 19)