Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- arr = [[n for n in range(1, 11)]]
- for i in range (0, 10):
- arr.append([n for n in range(1, 11)])
- def path(i, j):
- arr[i][j] = 0
- ni = 5
- nj = 4
- while ni > len(arr) - 1:
- ni -= 1
- dirs = [1, 2] #right and left
- #Remove right
- if j == len(arr[i]) - 1:
- dirs.remove(1)
- #Remove left
- if j == 0:
- dirs.remove(2)
- #Choose random direction
- direction = random.choice(dirs)
- while nj > len(arr[i]) - 1 and direction == 1:
- nj -= 1
- while nj < 1 and direction == 2:
- nj += 1
- #Go down
- for i in range(i, i + random.randrange(2, ni)):
- arr[i][j] = 0
- #Then go right
- if direction == 1:
- for j in range(j, j + random.randrange(1, nj)):
- arr[i][j] = 0
- #Or go left
- elif direction == 2:
- for j in range(j, j - random.randrange(1, nj), -1):
- arr[i][j] = 0
- try:
- return path(i + 1, j)
- except:
- return None
- path(0, random.randrange(0, 10))
- for i in range(0, len(arr)):
- print(arr[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement