text: import queue #library nodig
  
  def createMaze():
      maze = []# Dit het doolhof je kan het doolhof veranderen als je wilt.
      maze.append(["#","#", "#", "#", "#", "O", "#", "#", "#"])
      maze.append(["#"," ", " ", " ", " ", " ", " ", " ", "#"])
      maze.append(["#"," ", "#", "#", " ", "#", "#", " ", "#"])
      maze.append(["#"," ", "#", " ", " ", " ", "#", " ", "#"])
      maze.append(["#"," ", "#", " ", "#", " ", "#", " ", "#"])
      maze.append(["#"," ", "#", " ", " ", "#", "#", " ", "#"])
      maze.append(["#"," ", "#", " ", "#", " ", "#", "#", "#"])
      maze.append(["#"," ", " ", " ", " ", " ", " ", " ", "#"])
      maze.append(["#","#", "#", "#", "#", "#", "#", "X", "#"])
  
      return maze
  
  def printMaze(maze, path=""):#maze bekijken
      for x, pos in enumerate(maze[0]):
          if pos == "O":
              start = x
  
      i = start
      j = 0
      pos = set()
      for move in path:
          if move == "L":
              i -= 1
  
          elif move == "R":
              i += 1
  
          elif move == "U":
              j -= 1
  
          elif move == "D":
              j += 1
          pos.add((j, i))
      
      for j, row in enumerate(maze):
          for i, col in enumerate(row):
              if (j, i) in pos:
                  print("+ ", end="")
              else:
                  print(col + " ", end="")
          print()
          
  
  
  def valid(maze, moves):# begin en verplaatsen
      for x, pos in enumerate(maze[0]):
          if pos == "O":
              start = x
  
      i = start
      j = 0
      for move in moves:
          if move == "L":
              i -= 1
  
          elif move == "R":
              i += 1
  
          elif move == "U":
              j -= 1
  
          elif move == "D":
              j += 1
  
          if not(0 <= i < len(maze[0]) and 0 <= j < len(maze)):
              return False
          elif (maze[j][i] == "#"):
              return False
  
      return True
  
  
  def findEnd(maze, moves):# het einde zoeken
      for x, pos in enumerate(maze[0]):
          if pos == "O":
              start = x
  
      i = start
      j = 0
      count = 0
      for move in moves:
          if move == "L":
              i -= 1
              count += 1
          elif move == "R":
              i += 1
              count += 1
          elif move == "U":
              j -= 1
              count += 1
          elif move == "D":
              j += 1
              count += 1
      if maze[j][i] == "X":
          print("Gevonden: " + moves)
          printMaze(maze, moves)
          print(F"Het heeft {count} moves gekost om het doolhof te oplossen.")
          return True
  
      return False
  
  # MAIN ALGORITHM
  
  nums = queue.Queue()
  nums.put("")
  add = ""
  maze  = createMaze()
  
  while not findEnd(maze, add): 
      add = nums.get()
      #print(add)
      for j in ["L", "R", "U", "D"]:
          put = add + j
          if valid(maze, put):
              nums.put(put)