Created
March 4, 2014 21:00
-
-
Save wkta/9355524 to your computer and use it in GitHub Desktop.
#MonthOfCode day 2 - border
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import random | |
chars=[' ','┌','┐','└','┘','─','│'] | |
N,M = 32,16 | |
matr = list() | |
for i in xrange(M): | |
line = list() | |
for i in xrange(N): | |
line.append( random.choice( chars) ); | |
matr.append(line) | |
# adding difficulties | |
for y in xrange(2,M-2): | |
for x in xrange(2,N-2): | |
if( '─'==matr[y][x] ): | |
if (random.choice( (True,False))): | |
matr[y][x-1] = matr[y][x+1] = '─' | |
matr[y][x-2] = '└' ; matr[y][x+2]= '┐' | |
continue | |
if (random.choice( (True,False))): | |
matr[y-1][x] = matr[y+1][x]= '│' | |
matr[y-2][x] = '┐' ; matr[y+2][x]= '└' | |
# adding irregular boundaries | |
H_ELT_PAIR = ('─', '┬','┴' ) ; V_ELT_PAIR = ('│','├','┤' ) | |
ind_entrance, ind_exit = 1, random.randint(1,N-1) | |
for x in xrange(N): | |
matr[0][x] =\ | |
random.choice(H_ELT_PAIR ) if (x!=ind_entrance) else ' ' | |
matr[M-1][x] =\ | |
random.choice(H_ELT_PAIR ) if (x!=ind_exit) else ' ' | |
for y in xrange(M): | |
matr[y][0] = random.choice(V_ELT_PAIR ) | |
matr[y][N-1] = random.choice(V_ELT_PAIR) | |
# adding corners | |
matr[0][0], matr[0][N-1],matr[M-1][0], matr[M-1][N-1] = \ | |
[ '┌', '┐', '└', '┘' ] | |
#display | |
print "\n".join( [ ''.join(line) for line in matr ]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
screenshot available on twitter @spartangeek