コード例 #1
0
def test_stitch_unconnected_dragons(board):
    board.dragons[1] = Dragon(1, board)
    board.dragons[2] = Dragon(2, board)
    for x in range(3):
        p = board.pos_by_location((1, 1 + x))
        board.dragons[1].add_member(p)
        q = board.pos_by_location((3, 1 + x))
        board.dragons[2].add_member(q)

    assert len(board.dragons) == 2
    with pytest.raises(NotImplementedError):
        board.stitch_dragons(1, 2)
コード例 #2
0
def test_stitch_dragons(board):
    board.dragons[1] = Dragon(1, board)
    board.dragons[2] = Dragon(2, board)
    for x in range(3):
        p = board.pos_by_location((1, 1 + x))
        p.player = 'b'
        board.dragons[1].add_member(p)
        q = board.pos_by_location((3, 1 + x))
        q.player = 'b'
        board.dragons[2].add_member(q)
    r = board.pos_by_location((2, 1))
    r.player = 'b'
    board.dragons[1].add_member(r)

    assert len(board.dragons) == 2
    board.stitch_dragons(1, 2)
    assert len(board.dragons) == 1
    with pytest.raises(KeyError):
        assert board.dragons[2]
コード例 #3
0
def test_is_member(board):
    d = Dragon(1, board)
    p = board.positions[1][2]
    assert not d.is_member(p)

    d.add_member(p)
    assert d.is_member(p)
コード例 #4
0
def test_edge_neighbors(board):
    d = Dragon(1, board)
    p = board.positions[18][2]
    p2 = board.positions[18][3]
    d.add_member(p2)
    d.add_member(p)

    assert len(d.neighbors) == 4
    assert len(d.members) == 2
    assert len(d.liberties) == 4
コード例 #5
0
def test_capture_dragon(board):
    d = Dragon(1, board)
    board.dragons[1] = d
    for x in range(4):
        p = board.positions[3][2+x]
        p.player = 'b'
        p.dragon = 1
        d.add_member(p)

    p = board.positions[4][5]
    p.player = 'b'
    p.dragon = 1
    d.add_member(p)
    rv = board.capture_dragon(1)
    assert rv == 5
コード例 #6
0
def test_imagine_position(board):
    d = Dragon(1, board)
    board.dragons[1] = d
    for x in range(3):
        p = board.positions[3][2+x]
        p.player = 'b'
        p.dragon = 1
        d.add_member(p)
    p = board.positions[4][4]
    p.player = 'b'
    d.add_member(p)
    d = Dragon(2, board)
    board.dragons[2] = d
    for x in range(3):
        p = board.positions[5][2+x]
        p.player = 'w'
        p.dragon = 2
        d.add_member(p)
    p = board.positions[4][2]
    p.player = 'w'
    d.add_member(p)

    p = board.positions[4][3]
    rv = board.imagine_position(p, 'b')
    assert not rv['suicide']
    assert rv['stitched'] == {board.dragons[1]}
    assert not rv['captured']