SHARE
TWEET

Untitled

Goojira Mar 26th, 2019 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <time.h> //  Robert Nystrom
  2. #include <stdio.h> // @munificentbob
  3. #include <stdlib.h> //     for Ginny
  4. #define  r return    //    2008-2019
  5. #define  l(a, b, c, d) for (i y=a;y\
  6. <b; y++) for (int x = c; x < d; x++)
  7. typedef int i;const i H=40;const i W
  8. =80;i m[40][80];i g(i x){r rand()%x;
  9. }void cave(i s){i w=g(10)+5;i h=g(6)
  10. +3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
  11. -1,u+h+2,t-1            ,t+w+2)if(m[
  12. y][x]=='.'                  )r;i d=0
  13. ;i e,f        ;if(!s){l(      u-1,u+
  14. h+2,t-    1,t+w+2){i s=x<t     ||x>t
  15. +w;i    t=y<u||           y>    u+h;
  16. if(s    ^t&&              m[      y]
  17. [x    ]=='#'    ){d++;    if(g    (d
  18. )     ==0)    e=x,f=y;    }}if    (d
  19. ==    0)r;    }l(u-1,u    +h+2    ,t
  20. -1    ,t+w    +2){i s=    x< t    ||
  21. x>    t+w;    i t= y<u    ||y>    u+
  22. h;    m[y]      [x]= s    &&t?   '!'
  23. :s^t    ?'#'                    :'.'
  24. ;}if    (d>0)m                  [f][
  25. e]=g(2    )?'\'':'+';for(i j=0;j<(s?
  26. 1:g(6)        +1);j++)m[g(h)+u][g(w)
  27. +t]=s?'@'                 :g(4) ==0?
  28. '$':65+g(62)              ;}i main(i
  29. argc, const char* argv[]) {srand((i)
  30. time(NULL));l(0, H, 0,W)m[y][x]=' ';
  31. for(i j=0;j<1000;j++)cave(j==0);l(0,
  32. H,0,W) {i c=m[y][x]; putchar(c=='!'?
  33. '#':c);if(x==W-1)printf("\n");}r 0;}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top