Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- from copy import deepcopy
- grid=[[' ' for _ in range(10)] for _ in range(10)]
- letters='qwertyuiopasdfghjklzxcvbnm'
- posx,posy=0,0
- done=1
- def displaygrid():
- for row in grid:
- print('\n+--+--+--+--+--+--+--+--+--+--+\n|',end='')
- for col in row:
- print(col,end=' |')
- print('\n+--+--+--+--+--+--+--+--+--+--+')
- while done:
- displaygrid()
- grid[posy][posx]=letters[randint(0,25)]
- randlist=[]
- if posy!=0 and grid[posy-1][posx]==' ':
- randlist+=[0]
- if posx!=9 and grid[posy][posx+1]==' ':
- randlist+=[1]
- if posy!=9 and grid[posy+1][posx]==' ':
- randlist+=[2]
- if posx!=0 and grid[posy][posx-1]==' ':
- randlist+=[3]
- if not randlist:
- done=0
- else:
- direction=randlist[randint(0,len(randlist)-1)]
- if direction==0:
- posy-=1
- elif direction==1:
- posx+=1
- elif direction==2:
- posy+=1
- else:
- posx-=1
- displaygrid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement