示例#1
0
def test_can_find_gaps():
    #because tabs start random, repeat a bunch of times to compensate
    for i in range(1000):
        tab = Tableau()
        gaps = tab.find_gaps()
        assert len(gaps) == 4
        for g in gaps:
            assert tab.grid[g[0]][g[1]] is None
示例#2
0
def test_can_find_gaps():
    #because tabs start random, repeat a bunch of times to compensate
    for i in range(1000):
        tab = Tableau()
        gaps = tab.find_gaps()
        assert len(gaps) == 4
        for g in gaps:
            assert tab.grid[g[0]][g[1]] is None
示例#3
0
def busted_tableau():
    tab = Tableau()
    kings = tab.find_kings()
    continue_loop = True
    loop_counter = 0
    while continue_loop:
        if loop_counter > 100:
            tab = Tableau()
        gaps = tab.find_gaps()
        kings = tab.find_kings()
        i = 0
        for g in gaps:
            gap_row = g[0]
            gap_col = g[1]
            king_row = kings[i][0]
            king_col = kings[i][1]
            if gap_col == 0:
                tab.grid[gap_row][0],tab.grid[king_row][king_col] = \
                    tab.grid[king_row][king_col], None
            else:
                tab.grid[gap_row][gap_col-1], tab.grid[king_row][king_col] = \
                tab.grid[king_row][king_col], tab.grid[gap_row][gap_col-1]
            i += 1
        kings = tab.find_kings()
        continue_loop = False
        for king in kings:
            try:
                if king[1] == 12 or tab.grid[king[0]][king[1]+1] is not None:
                    continue_loop = True
                    loop_counter += 1
                    break
            except IndexError as ex:
                print king
                raise ex

    assert len(tab.find_gaps()) == 4
    assert len(tab.find_kings()) == 4
    return tab
示例#4
0
def busted_tableau():
    tab = Tableau()
    kings = tab.find_kings()
    continue_loop = True
    loop_counter = 0
    while continue_loop:
        if loop_counter > 100:
            tab = Tableau()
        gaps = tab.find_gaps()
        kings = tab.find_kings()
        i = 0
        for g in gaps:
            gap_row = g[0]
            gap_col = g[1]
            king_row = kings[i][0]
            king_col = kings[i][1]
            if gap_col == 0:
                tab.grid[gap_row][0],tab.grid[king_row][king_col] = \
                    tab.grid[king_row][king_col], None
            else:
                tab.grid[gap_row][gap_col-1], tab.grid[king_row][king_col] = \
                tab.grid[king_row][king_col], tab.grid[gap_row][gap_col-1]
            i += 1
        kings = tab.find_kings()
        continue_loop = False
        for king in kings:
            try:
                if king[1] == 12 or tab.grid[king[0]][king[1] + 1] is not None:
                    continue_loop = True
                    loop_counter += 1
                    break
            except IndexError as ex:
                print king
                raise ex

    assert len(tab.find_gaps()) == 4
    assert len(tab.find_kings()) == 4
    return tab
示例#5
0
def test_moveables_are_moveable():
    for i in range(1000):
        tab = Tableau()
        while not tab.has_moves():
            tab = Tableau()
        moveables = tab.find_moveable()
        for m in moveables:
            card = tab.card_at(m)
            if card.rank == Ranks.TWO:
                left_gaps = [gap for gap in tab.find_gaps() if gap[1] == 0]
                assert len(left_gaps) > 0
            else:
                target_card = Card(card.suit, Ranks.lower_rank(card.rank))
                assert target_card is not None
                target_loc = tab.find_card(target_card)
                assert tab.card_at((target_loc[0], target_loc[1]+1)) is None 
示例#6
0
def test_moveables_are_moveable():
    for i in range(1000):
        tab = Tableau()
        while not tab.has_moves():
            tab = Tableau()
        moveables = tab.find_moveable()
        for m in moveables:
            card = tab.card_at(m)
            if card.rank == Ranks.TWO:
                left_gaps = [gap for gap in tab.find_gaps() if gap[1] == 0]
                assert len(left_gaps) > 0
            else:
                target_card = Card(card.suit, Ranks.lower_rank(card.rank))
                assert target_card is not None
                target_loc = tab.find_card(target_card)
                assert tab.card_at((target_loc[0], target_loc[1] + 1)) is None