Ejemplo n.º 1
0
def parse_template(art):
	art = art.strip('\n')
	tplate = []
	swap = []
	for y, line in enumerate(art.split('\n')):
		for x, char in enumerate(line.strip()):
			if char in ('X', 'A'):
				tplate.append(point(x, y))
			if char in ('A', 'b'):
				swap.append(point(x, y))
	return Template(tplate, swap)
Ejemplo n.º 2
0
	def search(self, grid):
		possibles = []
		for x in xrange(self.edge[0]+1):
			for y in xrange(self.edge[1]+1):
				g = point(x, y)
				points = [grid[g+p] for p in self.pattern]
				#if len(list(dropwhile(lambda x: x==grid[g+t[0]], points))) <= 1:
				if all([p == grid[g+self.pattern[0]] for p in points]):
					possibles.append(((self.swap[0]+g).tuple(), (self.swap[1]+g).tuple()))
		return possibles
Ejemplo n.º 3
0
def alter_template(f, t):
	newtemp = map(f, t.pattern)
	newswap = map(f, t.swap)
	hadjust = 0
	vadjust = 0
	for p in newtemp:
		if p.a < hadjust:
			hadjust = p.a
		if p.b < vadjust:
			vadjust = p.b
	shift = point(-hadjust, -vadjust)
	newtemp = map(shift.__add__, newtemp)
	newswap = map(shift.__add__, newswap)
	return Template(newtemp, newswap)
Ejemplo n.º 4
0
def reflecth(p):
	x = -p.a
	y = p.b
	return point(x, y)
Ejemplo n.º 5
0
def rotate_90(p):
	x = -p.b
	y =  p.a
	return point(x, y)