Compressing tetrad definitions

This commit is contained in:
Alex Yatskov 2014-05-17 08:47:45 +09:00
parent c8969c6f82
commit 4995619de7

View File

@ -11,13 +11,13 @@ import random
class Tetrad: class Tetrad:
block_rotations = 4 block_rotations = 4
block_configs = [ 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 (1, 0x00f0222200f02222),
(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 (2, 0x0232007202620270),
(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 (3, 0x0033003300330033),
(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 (4, 0x0170022300740622),
(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 (5, 0x0071022604700322),
(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 (6, 0x0462036004620360),
(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 (7, 0x0264063002640630)
] ]
@ -32,8 +32,13 @@ class Tetrad:
def layout(self): def layout(self):
layout = self.block_configs[self.config][1][self.rotation] layout = list()
return map(lambda p: (self.position[0]+p[0], self.position[1]+p[1]), layout) 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): def moved_left(self):