Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def plateau_Zero(lig,col):
- lst=[0] * lig #ajouter autant de lignes qu'il faut
- for i in range(lig): #parcours des lignes
- lst[i]=[0] * col #pour chaques lignes mettre col fois 0
- return lst
- #print(plateau_Zero(3,2))
- def est_sur_plateau(cell,nb_lig,nb_col):
- if (cell[0] < 0) or (cell[0] > nb_lig - 1) or (cell[1] < 0) or (cell[1] > nb_col - 1) :
- return False
- return True
- #print(est_sur_plateau((2,2),5,5))
- def obstacle(lig,col):
- lstobstacle=plateau_Zero(lig,col)
- for i in range(lig):
- for j in range(col):
- if random.random()<0.4:
- lstobstacle[i][j]=1
- return lstobstacle
- #print(obstacle(4,4))
- def listeAlea(lst):
- nbr = random.randint(0, len(lst) - 1)
- return lst[nbr]
- def voisinFinal(cell,obstacle):
- 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] ]
- new_voisin = []
- for c in all_voisin:
- if (est_sur_plateau(c,len(obstacle),len(obstacle[0]))==True) and (obstacle[c[0]][c[1]]==0):
- new_voisin+=[c]
- return new_voisin
- #obs=obstacle(5,4)
- #for c in obs:
- #print(c)
- #print(voisinFinal((2,2),obs))
- def serpent(cell,obstacle):
- print(cell)
- if len(voisinFinal(cell,obstacle)) == 0:
- print("fini")
- return (0)
- obstacle[cell[0]][cell[1]] = 1
- #cell = listeAlea(voisinFinal(cell,obstacle))
- serpent(listeAlea(voisinFinal(cell,obstacle)), obstacle)
- if __name__ == '__main__':
- obs=plateau_Zero(5,5)#initialiser une liste de liste avec que des 0
- print(obs)
- serpent([2,2],obs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement