Exemplo n.º 1
0
def test_get_all_scales():
    sc = [map(to_tuple_pos, i) for i in get_all_iscales(0, Rook.vects) if i != []]

    ok(sc).length(2)
    s1, s2 = sc

    ok(min(s1[0][0], s2[0][0])) == 0

    if s1[0][0] != 0:
        s1, s2 = s2, s1

    ok(set(s1)) == {(0, i) for i in range(1, 8)}
    ok(set(s2)) == {(i, 0) for i in range(1, 8)}

    sc = [map(to_tuple_pos, i) for i in get_all_iscales(0, Bishop.vects) if i != []]
    ok(sc).length(1)
    ok(set(sc[0])) == {(i, i) for i in range(1, 8)}

    for pos in [(3, 4), (0, 0), (2, 3), (7, 7), (0, 7)]:
        for color in "BW":
            for piece_cl in (Rook, Queen, Bishop):
                pmc1 = get_all_iscales(to_int_pos(pos), piece_cl.vects)
                pmc2 = piece_cl(to_int_pos(pos), color).move_cells()
                pmc1.sort()
                pmc2.sort()

                ok(pmc1) == pmc2
Exemplo n.º 2
0
def test_get_all_scales():
    sc = [
        map(to_tuple_pos, i) for i in get_all_iscales(0, Rook.vects)
        if i != []
    ]

    ok(sc).length(2)
    s1, s2 = sc

    ok(min(s1[0][0], s2[0][0])) == 0

    if s1[0][0] != 0:
        s1, s2 = s2, s1

    ok(set(s1)) == {(0, i) for i in range(1, 8)}
    ok(set(s2)) == {(i, 0) for i in range(1, 8)}

    sc = [
        map(to_tuple_pos, i) for i in get_all_iscales(0, Bishop.vects)
        if i != []
    ]
    ok(sc).length(1)
    ok(set(sc[0])) == {(i, i) for i in range(1, 8)}

    for pos in [(3, 4), (0, 0), (2, 3), (7, 7), (0, 7)]:
        for color in "BW":
            for piece_cl in (Rook, Queen, Bishop):
                pmc1 = get_all_iscales(to_int_pos(pos), piece_cl.vects)
                pmc2 = piece_cl(to_int_pos(pos), color).move_cells()
                pmc1.sort()
                pmc2.sort()

                ok(pmc1) == pmc2
Exemplo n.º 3
0
def test_pos_transform():
    pos_pairs = [((0, 0), "A1", 0x00), ((7, 0), "H1", 0x70),
                 ((0, 7), "A8", 0x07), ((7, 7), "H8", 0x77),
                 ((3, 4), "D5", 0x34)]

    for tupl, sp, ip in pos_pairs:
        ok(to_tuple_pos(sp)) == tupl
        ok(to_tuple_pos(ip)) == tupl

        ok(to_str_pos(tupl)) == sp
        ok(to_str_pos(ip)) == sp

        ok(to_int_pos(sp)) == ip
        ok(to_int_pos(tupl)) == ip

    for x in range(8):
        for y in range(8):
            ok(to_tuple_pos(to_str_pos((x, y)))) == (x, y)
            ok(to_tuple_pos(to_int_pos((x, y)))) == (x, y)
Exemplo n.º 4
0
def test_pos_transform():
    pos_pairs = [
        ((0, 0), "A1", 0x00),
        ((7, 0), "H1", 0x70),
        ((0, 7), "A8", 0x07),
        ((7, 7), "H8", 0x77),
        ((3, 4), "D5", 0x34),
    ]

    for tupl, sp, ip in pos_pairs:
        ok(to_tuple_pos(sp)) == tupl
        ok(to_tuple_pos(ip)) == tupl

        ok(to_str_pos(tupl)) == sp
        ok(to_str_pos(ip)) == sp

        ok(to_int_pos(sp)) == ip
        ok(to_int_pos(tupl)) == ip

    for x in range(8):
        for y in range(8):
            ok(to_tuple_pos(to_str_pos((x, y)))) == (x, y)
            ok(to_tuple_pos(to_int_pos((x, y)))) == (x, y)
Exemplo n.º 5
0
 def pos(self, value):
     self.ipos = to_int_pos(value)
Exemplo n.º 6
0
 def __init__(self, pos, color):
     self.ipos = to_int_pos(pos)
     self.color = color
     self.cost = color_sig[self.color] * self.def_cost
Exemplo n.º 7
0
 def pos(self, value):
     self.ipos = to_int_pos(value)
Exemplo n.º 8
0
 def __init__(self, pos, color):
     self.ipos = to_int_pos(pos)
     self.color = color
     self.cost = color_sig[self.color] * self.def_cost