Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- n = 9
- m = 9
- a = []
- for i in range(n):
- temp = []
- for j in range(m):
- temp.append(0)
- a.append(temp)
- center_x = int(n / 2)
- center_y = int(m / 2)
- # center_x = 1
- # center_y = 1
- a[center_x][center_y] = 1
- pos_x = [0, 1, 1, 1, 0, -1, -1, -1]
- pos_y = [-1, -1, 0, 1, 1, 1, 0, -1]
- s = 0
- f = 1
- fifo_x = []
- fifo_y = []
- fifo_x.append(center_x)
- fifo_y.append(center_y)
- point = [0]
- inc = [0]
- while s < f:
- x = fifo_x[s]
- y = fifo_y[s]
- if s == 100:
- print(1)
- for i in range(len(pos_x)):
- 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):
- temp = max(abs(center_x - (x + pos_x[i])), abs(center_y - (y + pos_y[i]))) + 1
- if temp not in point:
- point.append(temp)
- q = inc[-1] + int(random.random() * 5) + 1
- inc.append(q)
- else:
- q = inc[point.index(temp)]
- fifo_x.append(x + pos_x[i])
- fifo_y.append(y + pos_y[i])
- f += 1
- w = int((random.random() * 6) - 3)
- a[x + pos_x[i]][y + pos_y[i]] = q + w
- s += 1
- for i in a:
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement