Esempio n. 1
0
def search(robot):

	maze = Maze()
	to_be_explored = Stack()
	backtrace_directions = Stack()

	current_square = create_current_square(robot)
	current_square.neighbors.bottom = False
	add_moves(robot, to_be_explored, maze)
	maze.add_square(current_square, robot.x, robot.y)

	while to_be_explored.size() > 0:

		current_move = to_be_explored.pop()

		if (current_move.x, current_move.y) in maze.squares:
			continue

		while not move_valid_from_square(current_move, current_square):
			back_move = backtrace_directions.pop()
			robot.rotate_to_direction(get_relative_move(Direction.down, back_move.direction))
			robot.move_forward()
			current_square = create_current_square(robot)
		
		robot.rotate_to_direction(current_move.direction)
		robot.move_forward()
		backtrace_directions.add(current_move)

		current_square = create_current_square(robot)
		add_moves(robot, to_be_explored, maze)
		maze.add_square(current_square, robot.x, robot.y)

	maze.link_squares()

	return maze