### import nécéssaires pour le TP import time from tkinter import * from pile import Pile #################################################################################### # Labyrinthe #################################################################################### def find_e(t): """Permet de trouver l'entrée du labyrinthe""" # ----------------------- # ----------------------- pass def aff(t): """Affiche le labyrinth t""" # ----------------------- # ----------------------- pass def avance(maze, p): """Avance dans le labyrinthe""" # ----------------------- # ----------------------- pass # Notre labyrinthe maze_str = """ ###################################### #e # # # # # ###### ## # # # # # # ############## # ## # # # # # ##s # ###### ## # # #### # # ## # # ## # # # # # ## # # # ############## # # ######## # # ## # # # # # # # ## # # ##### ############ # # # ### ## # # # # # ## # ## ###################################### """ # On transforme le labyrinthe en listes de chaînes de caractères maze = maze_str.split("\n") # pile des positions inexplorées p = Pile() p.add(find_e(maze)) AFFICHAGE_CONSOLE = False # Mettre à True pour activer l'affichage dans la console # Tant que la pile n'est pas vide ... on avance while not p.is_empty() and AFFICHAGE_CONSOLE: avance(maze, p) aff(maze) time.sleep(0.5) ######################## # Interface avec tkinter ######################## # Réinitialisation du labyrinthe maze = maze_str.split("\n") p.add(find_e(maze)) # Taille des cellules et du labyrinthe # ----------------------- # ----------------------- # Affichage root = Tk() root.title = "Labyrinthe" # canevas = Canvas(root, width=xmax, height=ymax, background="#FFFFFF") # canevas.pack() # Affichage labyrinthe avant l'algorithme de recherche # ----------------------- # ----------------------- # Boucle principale d'affichage def loop(): # ----------------------- # ----------------------- root.after(50, loop) root.after(50, loop) AFFICHAGE_TKINTER = False if AFFICHAGE_TKINTER: root.mainloop() #################################################################################### # Labyrinthes à tester :) #################################################################################### maze_str = """ ###################################### #e # # # # # ###### ## # # # # # # ############## # ## # # # # # ##s # ###### ## # # #### # # ## # # ## # # # # # ## # # # ############## # # ######## # # ## # # # # # # # ## # # ##### ############ # # # ### ## # # # # # ## # ## ###################################### """ maze_str = """ ######### #### ## ## ##### s# # # ## # ## # # ## # # #### ## # # # #### # # # # # ##### #### ### # # # # # # #### # # # # # # # ## # # ###### # # ### # # # ## # # # #### # ##### ## # ## # # # # # ### ### # # # e#### ##### # # ######## """ maze_str = """ #### #e # ## ######## ####### # # # # # # # # # ## # # ## # # ### ## # # # ######### # # ## # ## # # # ## # # ## # # # # # ## # ### # # ### # # # ### # # ## ## # ## ##### # # ## # # # # # ### # # # ### ### ## # ## # # # ## # # ## ## # ## ## # # ## # # # # ## ## # ### ## ## # # # # # # ### # ##### # # # ### ## # # # # #s### ######## ########### """