Esempio n. 1
0
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)
Esempio n. 2
0
def depth_first_search():
    """non recursive depth first search on a game state"""
    start = towers.towers()
    print "starting state:"
    start.toString()
    print ""
    open_states = [start]
    closed = list()
    while open_states:
        X = open_states.pop()
        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)
Esempio n. 3
0
def main():
	t = towers.towers()
	while not t.solved():
		t.moveOneValid()
		t.toString()
		print ""
	
	print "solved!"
Esempio n. 4
0
def main():
    t = towers.towers()
    while not t.solved():
        t.moveOneValid()
        t.toString()
        print ""

    print "solved!"