Live data from Hacker News

A random dungeon generator that fits on a business card (2019)

gist.github.com

31–40 of 53 posts

Re: A random dungeon generator that fits on a business card (2019)

#31

Earlier quoted context omitted.

Surprisingly good for what purpose?

probably fun

It'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.

Re: A random dungeon generator that fits on a business card (2019)

#33
post #4

[flagged]

I sort of understand the knee-jerk reactions to this. Hacker News is for humans, not robots, and there was an annoying trend of commenters posting LLM-generated summaries of articles, which deserve to get flagged off the page until they stop. But I find it noteworthy, and in fact impressive, that ChatGPT can de-obfuscate and discern the meaning of this code. Letting the rest of us know that is a worthy contribution t…

ChatGPT is not de-obfuscating this code. For one thing:

> basic cellular automaton algorithm

is completely wrong. A cellular automaton is a standard approach to level-generation in a roguelike, but this code implements a different approach, the rooms-and-corridors one.

Another issue here is that ChatGPT is using a few key context clues to make its (incorrect but plausible) guess. Robert Nystrom, aka munificient, is well-known in the roguelikedev community for his game programming tutorials. I confirmed that ChatGPT knows who he is by asking "Who is @munificentbob and what is he known for?" The name of the function, "cave", that carves rooms makes it clear that this is some kind of level-generation algorithm - in fact, that's probably where the incorrect guess about cellular automata came from, because those algorithms are often used for "caves" (versus "dungeons" made with rooms-and-corridors). The characters printed are also roguelike standards.

If I remove @munificient's name and rename "cave" to "X", ChatGPT's output is worse. It says: "This code is a compact implementation of a simple game where characters move around a grid.", which is...vaguely in the ballpark.

Re: A random dungeon generator that fits on a business card (2019)

#34
post #31

Earlier quoted context omitted.

probably fun

It'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.

It's fast enough that you can just check possible outcomes for whatever criterion you want.

Re: A random dungeon generator that fits on a business card (2019)

#35
post #19

I 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 t + w; const v = y u + h; if (s ^ v && m[y][x] === "#") { d++; if (g(d) === 0) { e = x; f = y;…

I don't like this business card :( -- me, a JS dev far too often (but also, thank you for sharing this!)

Haha thanks for this laugh!

Re: A random dungeon generator that fits on a business card (2019)

#36
post #12

I'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 ): w=(╱ ╲);while :;do echo -n ${w[RANDOM%2]};done and how it looks like: https://i.stack.imgur.com/fRX05.png

> there's obviously no guarantees of solvability

In fact, as the size of the maze goes to infinity, the probability of solvability goes to zero. Source: https://cstheory.stackexchange.com/a/32381/20581

Re: A random dungeon generator that fits on a business card (2019)

#37
I 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/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 
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/cc5372a349559b9d1a3b220d5ea...

Re: A random dungeon generator that fits on a business card (2019)

#38
That 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

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.

Re: A random dungeon generator that fits on a business card (2019)

#39

Here'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 ([1] - The 10-line BASIC competition is happening again this year, details here: https://gkanold.wixsite.com/homeputerium/copy-of-rules )

I love that it includes an explanation too. Thanks for sharing!
Post reply on HN