コード例 #1
0
ファイル: breadth.py プロジェクト: zmobie/towers_of_hanoi
def breadth_first_search():
	"""non recursive depth first search on a game state"""
	start = towers.towers()
	print "starting state:"
	start.toString()
	print ""
	open_states = deque([start])
	closed = list()
	while open_states:
		X = open_states.popleft()
		if X.solved():
			return X
		else:
			X.generateMoves
			moves = X.validMoves
			#generate children of X
			children = []
			for move in moves:
				Y = deepcopy(X)
				Y.move(move)
				children.append(Y)
			#put X on closed
			closed.append(X)
			#discard children of X if already on open or closed
			children = prune_children(children, open_states, closed)
			#put remaining children on left end of open
			open_states.extend(children)
コード例 #2
0
ファイル: strategy.py プロジェクト: zmobie/towers_of_hanoi
def main():
	t = towers.towers()
	while not t.solved():
		t.moveOneValid()
		t.toString()
		print ""
	
	print "solved!"