
A random dungeon generator that fits on a business card - munificent
https://twitter.com/munificentbob/status/1101903466111283200
======
coroxout
This is really cool, nice work (and sorry about your dog).

It reminds me that once upon a time the roguelike dev newsgroup had a "1k
(source code) roguelike challenge".

The thread is here [1] and submissions are here in a slightly annoying format
[2] but sadly I can't find the entry I remember, which I thought was in C and
actually quite playable, if slightly at the mercy of the random number
generator to make each new level solvable. Perhaps it was for a later
iteration of the same challenge.

[1]
[https://rec.games.roguelike.development.narkive.com/3tm7xGpn...](https://rec.games.roguelike.development.narkive.com/3tm7xGpn/first-1kb-
rl-challenge#post3) [2]
[https://sites.google.com/site/1024brl/](https://sites.google.com/site/1024brl/)

------
femto113
If like me you're interested in looking at how the code actually works I put a
deobfuscated fork here

[https://gist.github.com/femto113/28f69626acddc70a002ecead0b3...](https://gist.github.com/femto113/28f69626acddc70a002ecead0b311da4)

Just expands the macros/typedefs and applies standard indenting, code is
otherwise same as the original.

~~~
munificent
There are a few tweaks I made along the way while tightening it up, but here's
the readable original I started from:

[https://gist.github.com/munificent/ce8f7a9e6b09938ca8d2d43fa...](https://gist.github.com/munificent/ce8f7a9e6b09938ca8d2d43fa62f9864)

------
harperlee
This is not mine, but from the “clojure grams” twitter account:

    
    
      (defn maze [n]
        (->> (repeatedly (* n n) #(rand-nth "╱╲"))
          (partition n)
          (transduce
            (comp
              (map #(apply str %))
              (interpose "\n"))
            str)))
    

Simpler output but related and also quite interesting!

~~~
Aardappel
Looks like a port of this Basic one-liner:
[http://www.slate.com/articles/technology/books/2012/11/compu...](http://www.slate.com/articles/technology/books/2012/11/computer_programming_10_print_chr_205_5_rnd_1_goto_10_from_mit_press_reviewed.html)

------
msie
I like the old-school notion that I can just copy and paste it into vi and
then compile with gcc. It just works. No complicated installation of a runtime
or dependencies.

~~~
yorwba
Except a recent gcc will refuse to compile that code because of a
technicality.

Here's some modified code that runs on my machine if pasted directly into
bash:

gcc -x c - <<EOF

    
    
      #include <time.h> //  Robert Nystrom
      #include <stdio.h> // @munificentbob
      #include <stdlib.h> //     for Ginny
      #define  r return    //    2008-2019
      #define  l(a, b, c, d) for (i y=a;y\
      <b; y++) for (int x = c; x < d; x++)
      typedef int i;const i H=40;const i W
      =80;i m[40][80];i g(i x) {r rand()%x;}
      void cave(i s){i w=g(10)+5;i h=g(6)+
      3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u-
      1,u+h+2,t-1,            t+w+2)if(m[y
      ][x]=='.')                  r;i d=0;
      i e,f;        if(!s){l(u      -1,u+h
      +2,t-1    ,t+w+2){i s=x<t||     x>t+
      w; i    t=y<u||           y>    u+h;
      if(s    ^t&&              m[      y]
      [x    ]=='#'    ){d++;    if(g    (d
      )     ==0)    e=x,f=y;    }}if    (d
      ==    0)r;    }l(u-1,u    +h+2    ,t
      -1    ,t+w    +2){i s=    x< t    ||
      x>    t+w;    i t= y<u    ||y>    u+
      h;    m[y]      [x]= s    &&t?   '!'
      :s^t    ?'#'                    :'.'
      ;}if    (d>0)m                  [f][
      e]=g(2    )?'\'':'+';for(i j=0;j<(s?
      1:g(6)        +1);j++)m[g(h)+u][g(w)
      +t]=s?'@'                 :g(4) ==0?
      '$':65+g(62)              ;}i main(i
      argc, const char* argv[]) {srand((i)
      time(NULL));l(0, H, 0,W)m[y][x]=' ';
      for(i j=0;j<1000;j++)cave(j==0);l(0,
      H,0,W) {i c=m[y][x]; putchar(c=='!'?
      '#':c);if(x==W-1)printf("\n");}r 0;}

EOF

./a.out

~~~
philshem

                                                                   ###############  
                                                                   #.......^...$.#  
      ###################                ##############            #.....Z.......#  
      #..$...#..........#                #............#            #.....e.......#  
      #..a...#........$.#                #...$....$...# ############.............#  
      #......#.}........#      ###########....y.......# #.........#######+########  
      #......#..........#      #........##............# #.........##....~.#         
      #......#..........#      #........########'###### #....d....##......#         
      #......+..........#      #H....^$.#.....$...#     #.........##......#         
      ###########'#######      #........+c......O.#     #.........##......#         
       #...........#           ##########.........#     #...$.....##.z$...#         
       #.....x.$...#                    #.........#     #.........##......########  
       #...........#                    #.....Q...#     #.........##Q.....+......#  
       #...........#       ###########  #.........#     #.........##......#......#  
       ######'#########    #.........#  #.........#  ###########'###+######......#  
           #........`.#    #.....H...#  #.........#  #...............#    #.C....#  
           #..R.......#    #.........####+############~........P.....#    #..d...#  
           #..........#    #..{......#...............#...............#    #......#  
           #..$.......#    #.........#...............#....t..........#    #......#  
           #..........#    #.........#...............#...............#    #...`V.#  
         #######+######    #.........+...............#...............#    #......#  
         #....$...#        #.........#...............+....v..........#    ########  
         #fT......#        ###########....@..........#...............#              
         #........#                  #...............#########'#####'############   
         #...H....#                  #...............#    #......#..............#   
         #........#           ########+#######'#######    #..d.b.#..............#   
         #........#           #...X...s.#   #....$.#      #.J....#..............#   
       #######'#'##############..|....E.#   #...]a.#      #......#..............#   
       #.......#..............+$........#   #......#      ########..............#   
       #.......#..............#.........#   #......#             #..............#   
       #.......#......~.......#########'#   #......#             #$.............#   
       #.......#..v...........# #...\...#   #......#             #..............#   
       #n......#........}.....# #.......#   #......#             #..............#   
       #....$..#......`.......# #....u$.#   #......#             ################   
       #...r...#..............# #.......#   #......#                                
       #.......#..............# #########   ########                                
       #########..............#                                                     
               ################

~~~
munificent
My favorite part is that you get a totally different dungeon each time you run
it. It really is a working procedural generator, and not something more like a
demo that only produces a single carefully selected result.

------
PhasmaFelis
Is there an executable available somewhere?

This is kind of a pet peeve of mine, but if you post simple, standalone code
you really ought to post the compiled executable(s) as well. I don't currently
have a C compiler installed on my home Windows box.

~~~
yorwba
Why use an executable when you can run it on someone else's computer™:
[https://repl.it/repls/NiceEvilBoard](https://repl.it/repls/NiceEvilBoard)

I swear the URL wasn't chosen by me.

~~~
PhasmaFelis
Thanks for an actually constructive answer! That's pretty neat. I hadn't heard
of Repl.it before.

