class SquareGrid3DTests(unittest.TestCase): o = coordsys.SquareGrid3D((0,0,0)) o_rotated = ((0,0,0), (0,0,1), (-1,0,0), (0,-1,1)) c100 = coordsys.SquareGrid3D((1,0,0)) c111 = coordsys.SquareGrid3D((1,1,1)) rotated = {'c100/0': ((1,0,0), (0,1,1), (-2,0,0), (0,-2,1)), 'c111/0': ((1,1,1), (-2,1,0), (-1,-2,1), (1,-1,0)),} def test_flip0(self): self.assertEquals(self.o.flip0(), (-1,0,0)) self.assertEquals(self.c100.flip0(), (-2,0,0)) def test_rotate0(self): o = self.o for r in range(4): self.assertEquals(self.o.rotate0(r), self.o_rotated[r]) o = o.rotate0(1) self.assertEquals(o, self.o_rotated[(r + 1) % 4]) c = self.c100 for r in range(4): self.assertEquals(self.c100.rotate0(r), self.rotated['c100/0'][r]) c = c.rotate0(1) self.assertEquals(c, self.rotated['c100/0'][(r + 1) % 4]) c = self.c111 for r in range(4): self.assertEquals(self.c111.rotate0(r), self.rotated['c111/0'][r]) c = c.rotate0(1) self.assertEquals(c, self.rotated['c111/0'][(r + 1) % 4])
def coordinates(self): for coord in self.coordinates_bordered(self.main_width, self.height): x, y, z = coord if (2 <= x + y <= 9) and (-3 <= y + z - x <= 4): yield coord for coord in self.omitted_piece_coordinates: yield coordsys.SquareGrid3D(coord)
def get_piece_cells(self, s_matrix, x, y, z): cell_content = s_matrix[z][y][x] coord = coordsys.SquareGrid3D((x, y, z)) cells = set([coord]) if cell_content != '0': self._get_piece_cells(cells, coord, s_matrix, cell_content) return cells
def coordinates(self): for coord in self.coordinates_bordered(self.main_width, self.height): yield coord for coord in self.omitted_piece_coordinates: yield coordsys.SquareGrid3D(coord)
def coordinate_offset(cls, x, y, z, offset): if offset: return coordsys.SquareGrid3D((x, y, z)) + offset else: return coordsys.SquareGrid3D((x, y, z))