Exemple #1
0
    def test_place_flat(self):
        g = tak.Position.from_config(tak.Config(size=5))
        g1 = g.move(tak.Move(
            x=0,
            y=0,
        ))
        assert g.ply == 0
        assert g[0, 0] == []
        assert g1[0, 0] == [tak.Piece(tak.Color.BLACK, tak.Kind.FLAT)]
        assert g1.ply == 1
        assert g1.stones[1].caps == 1
        assert g1.stones[1].stones == 20

        g2 = g1.move(tak.Move(
            x=4,
            y=4,
        ))

        assert g2[0, 0] == [tak.Piece(tak.Color.BLACK, tak.Kind.FLAT)]
        assert g2[4, 4] == [tak.Piece(tak.Color.WHITE, tak.Kind.FLAT)]
        assert g2.stones[0].stones == 20
        assert g2.stones[1].stones == 20

        g3 = g2.move(tak.Move(
            x=2,
            y=2,
        ))

        assert g3[2, 2] == [tak.Piece(tak.Color.WHITE, tak.Kind.FLAT)]
Exemple #2
0
def parse_row(rtext):
    squares = []
    bits = rtext.split(',')
    for b in bits:
        if b[0] == 'x':
            n = 1
            if len(b) > 1:
                n = int(b[1:])
            squares += [[]] * n
            continue

        stack = []
        for c in b:
            if c == '1':
                stack.append(tak.Piece(tak.Color.WHITE, tak.Kind.FLAT))
            elif c == '2':
                stack.append(tak.Piece(tak.Color.BLACK, tak.Kind.FLAT))
            elif c in ('C', 'S'):
                if not stack:
                    raise IllegalTPS("bare capstone or standing")
                typ = tak.Kind.CAPSTONE if c == 'C' else tak.Kind.STANDING
                stack[-1] = tak.Piece(stack[-1].color, typ)
            else:
                raise IllegalTPS("bad character: " + c)

        squares.append(list(reversed(stack)))
    return squares
Exemple #3
0
import tak
import pytest

W = tak.Piece(tak.Color.WHITE, tak.Kind.FLAT)
WC = tak.Piece(tak.Color.WHITE, tak.Kind.CAPSTONE)
WS = tak.Piece(tak.Color.WHITE, tak.Kind.STANDING)

B = tak.Piece(tak.Color.BLACK, tak.Kind.FLAT)
BC = tak.Piece(tak.Color.BLACK, tak.Kind.CAPSTONE)
BS = tak.Piece(tak.Color.BLACK, tak.Kind.STANDING)


def test_new():
    g = tak.Position.from_config(tak.Config(size=5))
    assert g.size == 5
    assert g.ply == 0
    assert g.stones[0].stones == 21
    assert g.stones[1].stones == 21
    assert g.stones[0].caps == 1
    assert g.stones[1].caps == 1

    assert g.to_move() == tak.Color.WHITE


class TestFromStones(object):
    def test_from_stones(self):
        g = tak.Position.from_squares(tak.Config(size=5), [
            [W],
            [W],
            [B],
            [W],