Skip to content

Instantly share code, notes, and snippets.

@polm
Created July 4, 2012 23:24
Show Gist options
  • Save polm/3050047 to your computer and use it in GitHub Desktop.
Save polm/3050047 to your computer and use it in GitHub Desktop.
_ = require 'underscore'
r = Math.random
rr = (x) -> ~~(r() * x)
#How wide is the main hall?
hallwidth = (rr(3) * 2) + 4
#How tall can a room be?
#TODO make variable
depth = 12
#start with flatback
#Generate gaussian centered on 3, goes to six
cols = ~~(rr(2) + rr(2) + rr(2)) * 2
stack = (d,w) ->
rooms = ~~(_.foldr( (r() for xx in [0..w-1]), ((x,y) -> x+y), 0))
shares = (~~((r() + r() + r()) + 1) for ro in [0..rooms])
total = _.foldl(shares, ((x,y) -> x+y) , 0)
rsizes = ( ~~(rs * d / total) for rs in shares)
ntotal = _.foldl(rsizes, ((x,y) -> x+y) , 0)
#make up for rounding errors
rsizes[rsizes.length - 1] += d - ntotal if ntotal < d
rsizes
sideways = stack(20,6)
house = (([s,p] for p in stack(12,4)) for s in sideways)
printroom = (i) -> ('.' for [0..(i[1]-2)]).join('') + '|'
prr = (row) -> (printroom(ro) for ro in row).join('')
prw = (rw) -> (prr(rw) for x in [0..rw[0][0]]).join('\n') + '\n' + ('-' for x in [0..(_.foldl(rw,((x,y) -> x + y[1]), -1))]).join('')
console.log(house)
console.log((prw(x) for x in house).join('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment