def test_fixed_pentominos(self): orbitSize = dict() for p in pentominos.all_pentominos(): orbitSize[p.name] = pentominos.fixed_pentominos_of(p).size() self.assertEqual(dict({'F': 8, 'I': 2, 'L': 8, 'N': 8, 'P': 8, 'U': 4, 'T': 4, 'W': 4, 'V': 4, 'Y': 8, 'X': 1, 'Z': 4}), orbitSize) self.assertEqual(pentominos.all_fixed_pentominos().size(), 63)
def n_solutions(self): #initialize the appropriate incidence matrix fields = [str(c[1])+str(c[4]) for c in self.board.capacities if self.board.capacities[c] > 0] I = incidence_matrix.IncidenceMatrix([t.name for t in self.tileSet.set] + fields + ['constraint']) #name collisions for tiles which are more than once available tmpPent = None for p in self.tileSet.set: if p.name in self.fixedTiles: for c in [coos for coos in self.fixedTiles[p.name] if self.board.valid_tile_placement(coos)]: I.appendRow(p.name,[str(coo[0])+str(coo[1]) for coo in c]) if c == [[1,2],[2,2],[2,1],[2,3],[3,2]]: constraintCell = incidence_matrix.IncidenceCell(I.columnObjectOfName['X'].up.left,I.columnObjectOfName['X'].up,I.columnObjectOfName['constraint'].up,I.columnObjectOfName['constraint'], I.columnObjectOfName['constraint'],I.columnObjectOfName['X'].up.name + "_constraint") constraintCell.left.right = constraintCell.right.left = constraintCell.up.down = constraintCell.down.up = constraintCell else: for q in pentominos.fixed_pentominos_of(p): #m = q.max() for i in range(8):#self.board.size[0]-m[0]-1): for j in range(8):#self.board.size[1]-m[1]-1): if self.board.valid_tile_placement(q.coos): I.appendRow(p.name,[str(c[0])+str(c[1]) for c in q.coos]) if 'constraint' in I.columnObjectOfName: tmpPent = copy.deepcopy(q).normalize() if tmpPent in [pentominos.P().flip(0), pentominos.P().flip(0).turn90(), pentominos.P().flip(0).turn90().turn90(), pentominos.P().flip(0).turn90().turn90().turn90()]: constraintCell = incidence_matrix.IncidenceCell(I.columnObjectOfName['P'].up.left,I.columnObjectOfName['P'].up,I.columnObjectOfName['constraint'].up,I.columnObjectOfName['constraint'], I.columnObjectOfName['constraint'],I.columnObjectOfName['P'].up.name + "_constraint") constraintCell.left.right = constraintCell.right.left = constraintCell.up.down = constraintCell.down.up = constraintCell q.translate_one(1) q.normalize_coo(1) q.translate_one(0) I.h.size = float("inf") I.columnObjectOfName['constraint'].size = float("inf") return self.solve(I, 0)
def completeMatrix(self): """creates all rows""" for p in self.WorkingSet: if self.pFlip and p.name == "P": tiles = pentominos.TileSet() tiles.add(p) p.turn90() tiles.add(p) p.turn90() tiles.add(p) p.turn90() tiles.add(p) p.turn90() else: tiles = pentominos.fixed_pentominos_of(p) for t in tiles: for i in range(self.FRange): for j in range(self.FRange): t.translate_by([i,j]) l = True for x in t.coos: if not self.legal(x): l = False break if l: self.IncMatrix.appendRow(t.name,self.placement(t)) t.translate_by([-i,-j])
def appendPentominoRows(self, pentomino): pentomino.normalize() coords = [] for p in pentominos.fixed_pentominos_of(pentomino): for i in range(8): for j in range(8): if p.legal(): for k in range(5): coords.append(str(p.coos[k][0])+str(p.coos[k][1])) self.appendRow(p.name, coords) p.translate_one(0) coords=[] p.translate_by([-8,0]) p.translate_one(1)
def insertAllPlacements(self, pentomino): pentomino.normalize() versionList=pentominos.fixed_pentominos_of(pentomino) coordinatesAsStrings=[] for p in versionList: for i in range(8): for k in range(8): if p.legal(): for l in range(5): coordinatesAsStrings.append(str(p.coos[l][0])+str(p.coos[l][1])) self.appendRow(p.name, coordinatesAsStrings) p.translate_one(1) coordinatesAsStrings=[] p.translate_by([0,-8]) p.translate_one(0)
def appendPentominoRows(self, pentomino): pentomino.normalize() coords = [] for p in pentominos.fixed_pentominos_of(pentomino): for i in range(8): for j in range(8): if p.legal(): for k in range(5): coords.append( str(p.coos[k][0]) + str(p.coos[k][1])) self.appendRow(p.name, coords) p.translate_one(0) coords = [] p.translate_by([-8, 0]) p.translate_one(1)
def insertAllPlacements(self, pentomino): pentomino.normalize() versionList = pentominos.fixed_pentominos_of(pentomino) coordinatesAsStrings = [] for p in versionList: for i in range(8): for k in range(8): if p.legal(): for l in range(5): coordinatesAsStrings.append( str(p.coos[l][0]) + str(p.coos[l][1])) self.appendRow(p.name, coordinatesAsStrings) p.translate_one(1) coordinatesAsStrings = [] p.translate_by([0, -8]) p.translate_one(0)