Advertisement
tuning68

Untitled

Nov 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import lib.Labyrinthe
  2. from . import affichage
  3. from . import move
  4.  
  5. def cordoner (lstlst, n):
  6. for y in range(len(lstlst)):
  7. for x in range(len(lstlst[y])):
  8. if (lstlst[y][x] == n):
  9. return [y, x]
  10.  
  11. def entre (lab):
  12. return (cordoner(lab, 2))
  13.  
  14. def sortie (lab):
  15. if lab == None:
  16. return
  17. return(cordoner(lab, 3))
  18.  
  19. def voisin_lab_acc(couple, lab):
  20. voisin = []
  21.  
  22. if (((lab[couple[0]][couple[1] + 1]) != 0) and ((lab[couple[0]][couple[1] + 1]) != 2)):
  23. voisin += [[couple[0], couple[1] + 1]]
  24. if (((lab[couple[0]][couple[1] - 1]) != 0) and ((lab[couple[0]][couple[1] - 1]) != 2)):
  25. voisin += [[couple[0], couple[1] - 1]]
  26. if (((lab[couple[0] + 1][couple[1]]) != 0) and ((lab[couple[0] + 1][couple[1]]) != 2)):
  27. voisin += [[couple[0] + 1, couple[1]]]
  28. if (((lab[couple[0] - 1][couple[1]]) != 0) and ((lab[couple[0] - 1][couple[1]]) != 2)):
  29. voisin += [[couple[0] - 1, couple[1]]]
  30.  
  31. return (voisin)
  32.  
  33. def avance(laby, start):
  34. dessin = []
  35.  
  36. if laby[start[0][0]][start[0][1]] != 3:
  37. laby[start[0][0]][start[0][1]] = 0
  38. dessin = affichage.check(start[0][0], start[0][1], 40)
  39. affichage.my_carrer(dessin[0], dessin[1], dessin[2], dessin[3], "blue")
  40.  
  41. def check(laby, path):
  42. dessin = []
  43. tempo = []
  44.  
  45. for x in range(len(path) - 1, -1, -1):
  46. if len(voisin_lab_acc(path[x], laby)) >= 1:
  47. return [path[x]]
  48. else:
  49. tempo = [path[x]]
  50. dessin = affichage.check(tempo[0][0], tempo[0][1], 40)
  51. affichage.my_carrer(dessin[0], dessin[1], dessin[2], dessin[3], "#a8c6f0")
  52. del path[x]
  53. affichage.lib.graph.refresh()
  54. return None
  55.  
  56. def play_algo(laby):
  57. start = [entre(laby)]
  58. path = start
  59. nb = 0
  60.  
  61. while laby[start[0][0]][start[0][1]] != 3:
  62. if len(voisin_lab_acc(start[0], laby)) == 0:
  63. start = check(laby, path)
  64. elif len(voisin_lab_acc(start[0], laby)) == 1:
  65. start = voisin_lab_acc(start[0], laby)
  66. path += start
  67. avance(laby, start)
  68. else:
  69. start = voisin_lab_acc(start[0], laby)
  70. start = [start[0]]
  71. path += start
  72. avance(laby, start)
  73. affichage.lib.graph.refresh()
  74.  
  75. return (0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement