def test_valid_moves(): field = BottomField(1) for top in range(1 << 16): field.data[0] = top & 255 field.data[1] = top >> 8 assert (_reference_valid_moves(field.data) == field._valid_moves())
def test_overlapping_overlay(): field = BottomField(4) field.overlay([R, B, _, _, _, _, _, _]) field.render() print() field.overlay([G, Y, G, _, _, _, _, _]) field.render() stack = field.to_list() assert (stack[:8] == [R, B, G, _, _, _, _, _])
def test_render_in_place(): field = BottomField(2) for i in range(16): field.data[i] = ((i + 4234)**5) % 256 for i in range(8): field.data[i] &= ~field.data[i + 8] for i in range(10): print(i) util.print_up(8) print("Let's shift this a bit!", end="") field.render(in_place=True) print("hello") field.render(width=6, height=7)
def __init__(self, height, width, num_layers, num_deals=None, tsu_rules=False, has_garbage=False, deals=None, seed=None): if height not in ALLOWED_HEIGHTS: raise NotImplementedError( "Only heights {} supported".format(ALLOWED_HEIGHTS)) if width > BottomField.WIDTH: raise NotImplementedError("Maximum width is {}".format( BottomField.WIDTH)) if height == 13 and not tsu_rules: raise NotImplementedError( "Height 13 only available with tsu ruleset") if tsu_rules and not height == 13: raise NotImplementedError( "Tsu ruleset available only for height 13") if num_deals and deals: raise ValueError("Cannot use a partial number of fixed deals") if height == BottomField.HEIGHT: self.field = BottomField(num_layers, has_garbage=has_garbage) else: self.field = TallField(num_layers, tsu_rules=tsu_rules, has_garbage=has_garbage) self.width = width self.height = height self.num_deals = num_deals self.garbage_x = 0 if has_garbage else None self.make_actions() self.seed(seed) if deals is None: self.make_deals() else: self.deals = list(deals)
def test_overlay(): field = BottomField(3) field.overlay([R, G, _, _, _, _, _, _]) field.handle_gravity() field.render() print() field.overlay([ _, Y, _, _, _, _, _, _, _, Y, _, _, _, _, _, _, ]) field.handle_gravity() field.render() stack = field.to_list() assert (stack == [ _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, Y, _, _, _, _, _, _, _, Y, _, _, _, _, _, _, R, G, _, _, _, _, _, _, ])