Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. # Hello World program in Python
  2.  
  3. print ("==Le monde==");
  4.  
  5. carte = [['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  6. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  7. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  8. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  9. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  10. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  11. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  12. ['.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
  13. ]
  14.  
  15. def voir_carte():
  16. for ligne in carte:
  17. for e in ligne:
  18. print(e, end = '')
  19. print("")
  20.  
  21. # Taile de la carte en Y et X
  22. def taille_carte(carte):
  23. lignes = len(carte)
  24. colonnes = len(carte[0])
  25. return lignes, colonnes
  26.  
  27. def BFS(carte, pos): #current_pos
  28.  
  29. for neighbor in voisins(carte, pos):
  30. print(neighbor)
  31. #discovered = [pos]
  32. #while len(discovered) >= 0:
  33. #current_pos = discovered.pop()
  34. #x, y = current_pos
  35. #if carte[y][x] == 'o':
  36. #break
  37. #for neighbor in voisins(carte, current_pos):
  38. #if neighbor in discovered:
  39. #continue
  40. #discovered.append(neighbor)
  41. #
  42. #return discoverd.pop()
  43.  
  44. # On cherche pour des cases vides où on peut aller (les '.')
  45. def voisins(carte, pos):
  46. x, y = pos
  47. voisins = []
  48. #print("pos:", x, y)
  49. #print("ele:", carte[y][x])
  50. print(len(carte[y]))
  51. print("pos:", x, y)
  52. if x + 1 < len(carte[0]) and carte[y][x + 1] == '.':
  53. voisins.append((x + 1, y))
  54. if x > 0 and carte[y][x - 1] == '.':
  55. voisins.append((x - 1, y))
  56. if y + 1 < len(carte) and carte[y + 1][x] == '.':
  57. voisins.append((x, y + 1))
  58. if y > 0 and carte[y - 1][x] == '.':
  59. voisins.append((x, y - 1))
  60.  
  61. return voisins
  62.  
  63.  
  64. voir_carte()
  65. print("Taille de la matrice de la carte:", taille_carte(carte))
  66.  
  67. # Ajouter un joueur, des barrières et des biscuits à collecter sur la carte
  68. carte[7][6] = 'x'
  69.  
  70. carte[3][5] = '='
  71. carte[3][6] = '='
  72. carte[3][7] = '='
  73. #carte[3][8] = '='
  74. carte[3][9] = '='
  75. carte[3][10] = '='
  76.  
  77. carte[5][6] = '='
  78. carte[5][8] = '='
  79. carte[5][4] = '='
  80.  
  81. carte[1][10] = 'o'
  82. carte[3][2] = 'o'
  83. carte[4][6] = 'o'
  84.  
  85. voir_carte()
  86.  
  87. pos = 6, 7
  88.  
  89. i = 0
  90. while i < 3:
  91. i += 1
  92. BFS(carte, pos)
  93. x, y = pos
  94. carte[y][x] = 'x'
  95. voir_carte()
  96.  
  97. if x == None or y == None:
  98. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement