Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
from curses import * from random import * s=initscr() r=range m=[40*[' '] for l in r(20)] d=enumerate def f(g): for y in r(20): for x in r(40): g(y,x) def n(y,x): if random()<0.1: m[y][x]='#' f(n) x,y,c,h=0,0,0,5 o,t,n=ord,s.addstr,randint w=[[n(0,19),n(0,39),1] for e in r(10)] def u(y,x): for i,e in d(w): if y==e[0] and x==e[1]: return i return -1 def v(y,x): if u(y,x)>0: w[u(y,x)][2]-=1 return m[y][x]==' ' while(c!=o('q')): t(0,41,"h: "+str(h)) for j,e in d(w): m[e[0]][e[1]]=' ' if e[2]<1: continue z,q=max(min(w[j][0]+n(-1,1),19),0),max(min(w[j][1]+n(-1,1),39),0) if(z==y and q==x): h=h-1 if(m[z][q]==' '): w[j][0],w[j][1]=z,q m[e[0]][e[1]]='e' m[y][x]='@' f(lambda y,x:t(y,x,m[y][x])) c=s.getch() m[y][x]=' ' if o('2')==c and y<19: if v(y+1,x): y+=1 if o('8')==c and y>0: if v(y-1,x): y-=1 if o('6')==c and x<39: if v(y,x+1): x+=1 if o('4')==c and x>0: if v(y,x-1): x-=1 if h<1: break
This paste will be private.
From the Design Piracy series on my blog: