Changeset - 7a1226ab980e
[Not reviewed]
default
0 2 0
Laman - 7 years ago 2018-06-28 00:27:05

ladění
2 files changed with 32 insertions and 24 deletions:
dlx.py
24
11
tetris.py
8
13
0 comments (0 inline, 0 general)
dlx.py
Show inline comments
 
@@ -4,17 +4,30 @@
 

	
 

	
 
class Cell:
 
	def __init__(self,left=None,right=None,up=None,down=None,col=None):
 
		self.left=left
 
		self.right=right
 
		self.up=up
 
		self.down=down
 
	def __init__(self,col):
 
		self.left=self
 
		self.right=self
 
		self.up=self
 
		self.down=self
 
		self.col=col
 

	
 
	def attachRight(self,c):
 
		"""...-(b)-(self)->  <-(c)-(d)-..."""
 
		self.right.left=c.left
 
		c.left.right=self.right
 
		self.right=c
 
		c.left=self
 

	
 
	def attachDown(self,c):
 
		self.down.up=c.up
 
		c.up.down=self.down
 
		self.down=c
 
		c.up=self
 

	
 

	
 
class Column(Cell):
 
	def __init__(self,name,*args,**kwargs):
 
		super().__init__(*args,up=self,down=self,**kwargs)
 
	def __init__(self,name):
 
		super().__init__(self)
 
		self.name=name
 
		self.size=0
 

	
 
@@ -48,8 +61,7 @@ class Column(Cell):
 
class Header(Column):
 
	def __init__(self):
 
		super().__init__("head")
 
		self.left=self
 
		self.right=self
 
		self.up=self.down=self.size=None
 
		self._res=[]
 

	
 
	def search(self,k=0):
 
@@ -63,17 +75,17 @@ class Header(Column):
 
		col.cover()
 
		row=col.down
 
		while row is not col:
 
			row=row.down
 
			self._res[k]=row
 
			c=row.right
 
			while c is not row:
 
				c.col.cover()
 
				c=c.right
 
				self.search(k+1)
 
				c=row.right
 
			c=row.left
 
			while c is not row:
 
				c.col.uncover()
 
				c=c.left
 
			row=row.down
 
		col.uncover()
 

	
 
	def chooseCol(self):
 
@@ -89,6 +101,7 @@ class Header(Column):
 

	
 
	def print(self):
 
		for r in self._res:
 
			print(r.col.name,end=" ")
 
			c=r.right
 
			while c is not r:
 
				print(c.col.name,end=" ")
tetris.py
Show inline comments
 
@@ -27,30 +27,25 @@ for (name,piece) in pieces:
 
				for coords in fit: row[index[coords]]=1
 
				matrix.append(row)
 

	
 
# print(header)
 
# for row in matrix: print(row)
 
print(header)
 
for row in matrix: print(row)
 

	
 
columns=[]
 
head=Header()
 
for label in header:
 
	c=Column(label)
 
	head.left.right=c
 
	c.left=head.left
 
	head.left=c
 
	c.right=head
 
	c.attachRight(head)
 
	columns.append(c)
 

	
 
for row in matrix:
 
	cells=[]
 
	for (item,col) in zip(row,columns):
 
		if item!=1: continue
 
		c=Cell(up=col.up,down=col,col=col)
 
		col.up.down=c
 
		col.up=c
 
		c=Cell(col)
 
		c.attachDown(col)
 
		cells.append(c)
 
		c.right=cells[0]
 
		c.left=cells[0].left
 
		c.left.right=c
 
		c.right.left=c
 
		c.attachRight(cells[0])
 
		col.size+=1
 

	
 
print()
 
head.search()
0 comments (0 inline, 0 general)