Attachment ''


   1 #!/usr/bin/env python
   2 # coding: utf
   3 # Намеренно непонятный генератор лабиринтов
   4 import sys, random
   6 M=len(sys.argv)>1 and int(sys.argv[1]) or 17
   7 N=len(sys.argv)>2 and int(sys.argv[2]) or 11
   8 T=[[1]*M for i in xrange(N)]
   9 T[0][0],P=0,[(0,0)]
  10 while P:
  11     V=[(P[-1][0]+dx,P[-1][1]+dy) for dx,dy in ((-2,0),(0,2),(2,0),(0,-2)) if 0<=P[-1][0]+dx<M and 0<=P[-1][1]+dy<N and T[P[-1][1]+dy][P[-1][0]+dx]]
  12     if not V: P.pop()
  13     else:
  14         P.append(random.choice(V))
  15         T[(P[-2][1]+P[-1][1])/2][(P[-2][0]+P[-1][0])/2]=T[P[-1][1]][P[-1][0]]=0
  17 print T

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.