diff --git a/tetris.py b/tetris.py index 8c2e4c0..c389f29 100755 --- a/tetris.py +++ b/tetris.py @@ -11,13 +11,13 @@ import random class Tetrad: block_rotations = 4 block_configs = [ - (1, [[(1, 0), (1, 1), (1, 2), (1, 3)], [(0, 1), (1, 1), (2, 1), (3, 1)], [(1, 0), (1, 1), (1, 2), (1, 3)], [(0, 1), (1, 1), (2, 1), (3, 1)]]), # Shape_I - (2, [[(0, 1), (1, 1), (2, 1), (1, 2)], [(1, 0), (1, 1), (2, 1), (1, 2)], [(1, 0), (0, 1), (1, 1), (2, 1)], [(1, 0), (0, 1), (1, 1), (1, 2)]]), # Shape T - (3, [[(0, 0), (0, 1), (1, 0), (1, 1)], [(0, 0), (0, 1), (1, 0), (1, 1)], [(0, 0), (0, 1), (1, 0), (1, 1)], [(0, 0), (0, 1), (1, 0), (1, 1)]]), # Shape O - (4, [[(1, 0), (1, 1), (1, 2), (2, 2)], [(2, 0), (2, 1), (1, 1), (0, 1)], [(0, 0), (1, 0), (1, 1), (1, 2)], [(0, 1), (1, 1), (2, 1), (0, 2)]]), # Shape L - (5, [[(1, 0), (1, 1), (1, 2), (0, 2)], [(2, 1), (2, 2), (1, 1), (0, 1)], [(1, 0), (2, 0), (1, 1), (1, 2)], [(0, 0), (1, 1), (2, 1), (0, 1)]]), # Shape J - (6, [[(1, 1), (2, 1), (0, 2), (1, 2)], [(1, 0), (1, 1), (2, 1), (2, 2)], [(1, 1), (2, 1), (0, 2), (1, 2)], [(1, 0), (1, 1), (2, 1), (2, 2)]]), # Shape S - (7, [[(0, 1), (1, 1), (1, 2), (2, 2)], [(1, 1), (1, 2), (2, 0), (2, 1)], [(0, 1), (1, 1), (1, 2), (2, 2)], [(1, 1), (1, 2), (2, 0), (2, 1)]]) # Shape Z + (1, 0x00f0222200f02222), + (2, 0x0232007202620270), + (3, 0x0033003300330033), + (4, 0x0170022300740622), + (5, 0x0071022604700322), + (6, 0x0462036004620360), + (7, 0x0264063002640630) ] @@ -32,8 +32,13 @@ class Tetrad: def layout(self): - layout = self.block_configs[self.config][1][self.rotation] - return map(lambda p: (self.position[0]+p[0], self.position[1]+p[1]), layout) + layout = list() + mask = self.block_configs[self.config][1] >> (16 * self.rotation) + for bit in xrange(16): + position = bit % 4, bit / 4 + if mask & (1 << bit): + layout.append((self.position[0] + position[0], self.position[1] + position[1])) + return layout def moved_left(self):