6 ms·
A random dungeon generator that fits on a business card (2019)
- omoikane 3y agohttps://news.ycombinator.com/item?id=19309378 https://news.ycombinator.com/item?id=19309378 - A random dungeon generator in C, small enough to fit on a business card (2019) - 42 comments https://news.ycombinator.com/item?id=19290215 https://news.ycombinator.com/item?id=19290215 - original post referenced above - 23 comments
- dang 3y agoThanks! Those two threads were just a couple days apart so I've belatedly merged them, yielding: A random dungeon generator that fits on a business card - https://news.ycombinator.com/item?id=19290215 https://news.ycombinator.com/item?id=19290215 - March 2019 (64 comments)
- helpfulContrib 3y agoHere's a random dungeon generator GAME (get potion, avoid snake, explore dungeon) that fits in 10 lines of BASIC [1] and would probably easily fit on a business card, too: https://bunsen.itch.io/the-snake-temple-by-rax https://bunsen.itch.io/the-snake-temple-by-rax ([1] - The 10-line BASIC competition is happening again this year, details here: https://gkanold.wixsite.com/homeputerium/copy-of-rules https://gkanold.wixsite.com/homeputerium/copy-of-rules)
- mysterydip 3y agoI love that it includes an explanation too. Thanks for sharing!
- sowbug 3y ago[flagged]
- gkbrk 3y agoIn what way is what ChatGPT outputs when asked about this code relevant? There are more than 20 LLMs, do we expect to see a comment from each LLM about code submissions?
- ianbicking 3y agoThe code isn't very readable in the submitted form, so I appreciated the interpretation, whether or not it's ChatGPT or something else.
- jprete 3y agoThe interpretation is not correct, according to this comment: https://news.ycombinator.com/item?id=39422210 https://news.ycombinator.com/item?id=39422210
- sowbug 3y agoI'm not proficient at reading minimized code. Maybe you're better at it than I am. The ChatGPT output helps kickstart a meaningful discussion about the content of the code.
- kemotep 3y agoIt would probably help if you included that context in the beginning of the comment. Not just dumping ChatGPT output. From an outside observer it just seems like you wanted ChatGPT to contribute on your behalf, not start a discussion of the code.
- sowbug 3y agoFair enough. The Overton Window shifts quickly these days.
- sunbum 3y agoThis is what I have to say about this comment === Why... Why would you do this, in what world does this contribute to the discussion? ===
- BoppreH 3y agoI've always been a fan of generating mazes by randomly printing /, \, or a space. It ends up slanted, and there's obviously no guarantees of solvability, but it's surprisingly good for how simple it is. Here's a bash version in 50 characters (https://codegolf.stackexchange.com/a/26011/7934 https://codegolf.stackexchange.com/a/26011/7934): w=(╱ ╲);while :;do echo -n ${w[RANDOM%2]};done and how it looks like: https://i.stack.imgur.com/fRX05.png https://i.stack.imgur.com/fRX05.png
- heavenlyblue 3y agoSurprisingly good for what purpose?
- stevenpetryk 3y agoprobably fun
- kibwen 3y agoIt's not much fun to solve because there's no guarantee that a path exists between any given openings on the edge, so it's mostly just "pick a point on the edge at random and see how far you can get". However, it does look very pretty.
- zo1 3y agoIt's fast enough that you can just check possible outcomes for whatever criterion you want.
- nonethewiser 3y agoGenerating mazes
- deleted 3y ago[deleted]
- NelsonMinar 3y agoThat looks like a variant of Truchet Tiles: https://en.wikipedia.org/wiki/Truchet_tiles https://en.wikipedia.org/wiki/Truchet_tiles
- ttyyzz 3y agoI heard you like javascript so here you go: const H = 40; const W = 80; let m = new Array(H).fill().map(() => new Array(W).fill(" ")); function g(x) { return Math.floor(Math.random() * x); } function cave(s) { const w = g(10) + 5; const h = g(6) + 3; let t = g(W - w - 2) + 1; let u = g(H - h - 2) + 1; for (let y = u - 1; y < u + h + 2; y++) { for (let x = t - 1; x < t + w + 2; x++) { if (m[y][x] === ".") return; } } let d = 0; let e, f; if (!s) { for (let y = u - 1; y < u + h + 2; y++) { for (let x = t - 1; x < t + w + 2; x++) { const s = x < t || x > t + w; const v = y < u || y > u + h; if (s ^ v && m[y][x] === "#") { d++; if (g(d) === 0) { e = x; f = y; } } } } if (d === 0) return; } for (let y = u - 1; y < u + h + 2; y++) { for (let x = t - 1; x < t + w + 2; x++) { const s = x < t || x > t + w; const v = y < u || y > u + h; m[y][x] = s && v ? "!" : s ^ v ? "#" : "."; } } if (d > 0) m[f][e] = g(2) ? "'" : "+"; for (let j = 0; j < (s ? 1 : g(6) + 1); j++) { m[g(h) + u][g(w) + t] = s ? "@" : g(4) === 0 ? "$" : String.fromCharCode(65 + g(62)); } } function main() { for (let y = 0; y < H; y++) { for (let x = 0; x < W; x++) { m[y][x] = " "; } } for (let j = 0; j < 1000; j++) { cave(j === 0); } for (let y = 0; y < H; y++) { let row = ""; for (let x = 0; x < W; x++) { const c = m[y][x]; row += c === "!" ? "#" : c; } console.log(row); } } main();
- MenhirMike 3y agoYour business cards must be huge.
- ammanley 3y agoI don't like this business card :( -- me, a JS dev far too often (but also, thank you for sharing this!)
- actionfromafar 3y agoHaha thanks for this laugh!
- swayvil 3y agoSuave. The output reminds me of nethack.
- bartvk 3y agoI'd love a random dungeon generator that includes multiple plateaus inside one room. For example, a dungeon with a waterfall or a tree. Whenever I'd run an adventure, my players would often try me out, and open a door of some sorts. But the 2D maps feel very artificial. Guillaume Tavernier on Patreon makes maps with plateaus and multiple stories: https://www.patreon.com/dearchitecturart https://www.patreon.com/dearchitecturart A generator like that, would be awesome.
- skykooler 3y agoThe comments on that introduced me to cxx, which is also a really neat thing to learn about!
- a1o 3y agoSomeone deobfuscated it here https://gist.github.com/Joker-vD/cc5372a349559b9d1a3b220d5eaf2b01 https://gist.github.com/Joker-vD/cc5372a349559b9d1a3b220d5ea... Pretty interesting reading this code. Also nice to see things written in C around here.
- IAmNotACellist 3y agoNow also make it a text QR code
- SethMLarson 3y agoLove the "on a business card" format, thank you for creating this and sharing!
- deleted 3y ago[deleted]
- bheadmaster 3y agoI saw this post about 2 hours ago, and I was fascinated by it and curious how it worked. So I decided to de-obfuscate it and add comments. The code was too large for a comment, so here's the gist: https://gist.github.com/paskozdilar/48d7532733ccd11144bb43fed953c334 https://gist.github.com/paskozdilar/48d7532733ccd11144bb43fe... The approach is quite interesting - it (ab)uses the preprocessor to shorten the syntax of for loops: #define l(a, b, c, d) for (int y = a; y < b; y++) for (int x = c; x < d; x++) And then it does the heavy lifting by iterating over the whole map thousand times, randomly selecting a rectangle on the map and checking if the selected area is adjacent to an already-generated cave. It's a probabilistic algorithm, so there's a tiny chance that it will just print a single cave in the middle and nothing else. EDIT: Then I found that many other people also de-obfuscated it in the gist comments. :') This guy did a much better job than me: https://gist.github.com/Joker-vD/cc5372a349559b9d1a3b220d5eaf2b01 https://gist.github.com/Joker-vD/cc5372a349559b9d1a3b220d5ea...
- munificent 3y ago> And then it does the heavy lifting by iterating over the whole map thousand times, randomly selecting a rectangle on the map and checking if the selected area is adjacent to an already-generated cave. It's a probabilistic algorithm, so there's a tiny chance that it will just print a single cave in the middle and nothing else. Yeah, it's surprising how well this approach works. Performance is actually decent. There is a chance of "dud" levels that only have a couple of rooms, but it's rare. The nice thing about this approach is that it guarantees by construction that every room in the dungeon will be reachable from every other one.
- userbinator 3y agoThat functionality could probably fit in 1 line of APL... which means a business card could be enough space for a 3D renderer of the random dungeon. Related: https://news.ycombinator.com/item?id=6425714 https://news.ycombinator.com/item?id=6425714 Of course there's the demoscene productions where binary size is the measure (no cheating by using lots of libraries); and in a 1K binary, comparable in size to this source, they've gone much further with what can be generated.
- tanepiper 3y agoLove/hate that in 2023 someone is still writing CoffeeScript
- fatkam 3y agowould it fit in a QR code
- siddbudd 3y agoyes, copy the code: https://gist.githubusercontent.com/munificent/b1bcd969063da3e6c298be070a22b604/raw/387ada5316ed0ea69f74106f4babe1f4fc67ce21/generate.c https://gist.githubusercontent.com/munificent/b1bcd969063da3... paste in either: https://www.the-qrcode-generator.com/ https://www.the-qrcode-generator.com/ or: https://goqr.me/ https://goqr.me/
- joefitzgerald 3y agoIf you were wondering about the tribute to Ginny, here's the context: https://journal.stuffwithstuff.com/2022/02/13/stupid-dog/ https://journal.stuffwithstuff.com/2022/02/13/stupid-dog/.
- munificent 3y agoI love that people rediscover this every year or so. It was a really fun little distraction for me, and I'm delighted at how it came out.
- baruz 3y agoSorry about Ginny
- munificent 3y agoThanks. I still miss her sometimes.
- dndn1 3y agoI converted this to formulas in calculang, a language for calculations I'm developing, and visualize the dungeon and its evolution. I really liked this output from a very logical process (although I'll admit, I needed to use one of the commented versions linked in the discussion!) Here it is: https://declann.observablehq.cloud/calculang-dx-pattern-exampling/dungeon/dungeon https://declann.observablehq.cloud/calculang-dx-pattern-exam...