Tout est dans le titre et ci-dessous 🙂
largeur = 13 hauteur = 8 L = [[0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0], [1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] def affichage(t, n, p): for lin in range(n): for col in range(p): print(t[lin][col], end = ' ') print() print() def colorerVisite(L, case): y, x = case # y ligne x colonne L[y][x] = 2 affichage(L, hauteur, largeur) def colorerImpasse(L, case): y, x = case # y ligne x colonne L[y][x] = 3 affichage(L, hauteur, largeur) def voisins(L, case): y, x = case ''' # bas, droit, haut, gauche v_possibles = [(y + 1, x), (y, x + 1), (y - 1, x), (y, x - 1)] return [(lin, col) for (lin, col) in v_possibles if 0 <= lin < hauteur and 0 <= col < largeur and L[lin][col] == 0] ''' v = [] # en bas ? if y < hauteur - 1 and L[y + 1][x] == 0: v.append((y + 1, x)) # à droite ? if x < largeur - 1 and L[y][x + 1] == 0: v.append((y, x + 1)) # en haut ? if y > 0 and L[y - 1][x] == 0: v.append((y - 1, x)) # à gauche ? if x > 0 and L[y][x - 1] == 0: v.append((y, x - 1)) return v def f(L, debut, fin): colorerVisite(L, debut) # bleu for case in voisins(L, debut): if case == fin or f(L, case, fin): return True colorerImpasse(L, debut) return False affichage(L, hauteur, largeur) depart = 0, 0 arrivee = hauteur -1, largeur -1 print(f(L, depart, arrivee))