Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def plateau_Zero(lig,col):
  5.     lst=[0] * lig #ajouter autant de lignes qu'il faut
  6.     for i in range(lig): #parcours des lignes
  7.         lst[i]=[0] * col #pour chaques lignes mettre col fois 0
  8.     return lst
  9.  
  10. #print(plateau_Zero(3,2))
  11.  
  12. def est_sur_plateau(cell,nb_lig,nb_col):
  13.     if (cell[0] < 0) or (cell[0] > nb_lig - 1) or (cell[1] < 0) or (cell[1] > nb_col - 1) :
  14.         return False
  15.     return True
  16.  
  17. #print(est_sur_plateau((2,2),5,5))
  18.  
  19. def obstacle(lig,col):
  20.     lstobstacle=plateau_Zero(lig,col)
  21.     for i in range(lig):
  22.         for j in range(col):
  23.             if random.random()<0.4:
  24.                 lstobstacle[i][j]=1
  25.     return lstobstacle
  26.  
  27. #print(obstacle(4,4))
  28. def listeAlea(lst):
  29.     nbr = random.randint(0, len(lst) - 1)
  30.     return lst[nbr]
  31.  
  32. def voisinFinal(cell,obstacle):
  33.   all_voisin = [ [cell[0] - 1, cell[1] + 1], [cell[0] - 1, cell[1] - 1], [cell[0] + 1, cell[1] + 1], [cell[0] + 1, cell[1] - 1] ]
  34.   new_voisin = []
  35.   for c in all_voisin:
  36.     if (est_sur_plateau(c,len(obstacle),len(obstacle[0]))==True) and (obstacle[c[0]][c[1]]==0):
  37.       new_voisin+=[c]
  38.   return new_voisin
  39.  
  40. #obs=obstacle(5,4)
  41. #for c in obs:
  42.     #print(c)
  43.  
  44. #print(voisinFinal((2,2),obs))
  45.  
  46.  
  47. def serpent(cell,obstacle):
  48.     print(cell)
  49.     if len(voisinFinal(cell,obstacle)) == 0:
  50.         print("fini")
  51.         return (0)
  52.     obstacle[cell[0]][cell[1]] = 1
  53.     #cell = listeAlea(voisinFinal(cell,obstacle))
  54.     serpent(listeAlea(voisinFinal(cell,obstacle)), obstacle)
  55.  
  56.  
  57. if __name__ == '__main__':
  58.     obs=plateau_Zero(5,5)#initialiser une liste de liste avec que des 0
  59.     print(obs)
  60.     serpent([2,2],obs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement