Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. n = 9
  5. m = 9
  6. a = []
  7.  
  8. for i in range(n):
  9.     temp = []
  10.     for j in range(m):
  11.         temp.append(0)
  12.     a.append(temp)
  13.  
  14. center_x = int(n / 2)
  15. center_y = int(m / 2)
  16. # center_x = 1
  17. # center_y = 1
  18.  
  19. a[center_x][center_y] = 1
  20.  
  21.  
  22. pos_x = [0, 1, 1, 1, 0, -1, -1, -1]
  23. pos_y = [-1, -1, 0, 1, 1, 1, 0, -1]
  24. s = 0
  25. f = 1
  26. fifo_x = []
  27. fifo_y = []
  28. fifo_x.append(center_x)
  29. fifo_y.append(center_y)
  30.  
  31. point = [0]
  32. inc = [0]
  33.  
  34. while s < f:
  35.     x = fifo_x[s]
  36.     y = fifo_y[s]
  37.  
  38.     if s == 100:
  39.         print(1)
  40.  
  41.     for i in range(len(pos_x)):
  42.         if (x + pos_x[i] >= 0 and x + pos_x[i] < n and y + pos_y[i] >= 0 and y + pos_y[i] < m and a[x + pos_x[i]][y + pos_y[i]] == 0):
  43.             temp = max(abs(center_x - (x + pos_x[i])), abs(center_y - (y + pos_y[i]))) + 1
  44.  
  45.             if temp not in point:
  46.                 point.append(temp)
  47.                 q = inc[-1] + int(random.random() * 5) + 1
  48.                 inc.append(q)
  49.             else:
  50.                 q = inc[point.index(temp)]
  51.  
  52.             fifo_x.append(x + pos_x[i])
  53.             fifo_y.append(y + pos_y[i])
  54.             f += 1
  55.  
  56.             w = int((random.random() * 6) - 3)
  57.  
  58.             a[x + pos_x[i]][y + pos_y[i]] = q + w
  59.  
  60.     s += 1
  61.  
  62.  
  63. for i in a:
  64.     print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement