Re: My cave room generator using wave functions



On 12 ago, 23:53, ghostFace <jake_k...@xxxxxxxxxxx> wrote:
Hello all.  I've been a long time Roguelike fan, and I've recently
been developing one of my own.  I just finished working on a method
for generating a generic cave room generator. I say generic because it
actually can generate a variety of different shapes that could be used
as caves in some cases. Also, this is a room generator, not a level
generator, so the rooms will need to be connected in some way later.
I thought I'd put it out there for people to look at, and possibly
improve upon and use for themselves. I'll repeat the general algorithm
here, but a full description along with sample screenshots can be
found on my development blog at:

 http://roguerunner.110mb.com/blog.html

There are a number of different methods out there for generating cave-
like levels or cave-like rooms, but most of them didn't fit my needs.
For one, I need to gaurantee connectivity in the room itself. The
Cellular Automata algorithms I've seen can't gaurantee this. Next, I'm
starting with a room of set width and height, so the room has bounds.
Algorithms like the Drunken Walk may wander out of these bounds, and
if I restrict the walk to the bounds nothing is keeping it from
walking along the room edges, creating a flat portions of the room.
This is undesireable. Raycasting seemed like a lot of work, and the
results I've seen don't look that great. So I came up with my own
algorithm, which I'm rather proud of. Here's the psuedo code:

1. Randmonly choose n values to seed the wave function to be used. I
am currently using n=6, but I've gone as low as n=3 and still got good
results. We'll call these values phase, and they should be different
from each other. I have a variable called wavyness that provides the
range for each value. A wavyness of 2.0 would put n[ 0 ] between 0.0
and 2.0, n[ 1 ] would be between 2.0 and 4.0, and so forth. For even
more variance you can also randomly generate a shift values for each
of the terms as well.

2. These seed values will drive a wave function of the form
cos( phase[ 0 ] * x ) + cos( phase[ 1 ] * x ) + ... + cos( phase[ n ]
* x ). Find the min and max of this function between 0.0 and 2 * PI.
This is the worst part of the algorithm, as I currently brute force
this. Using the min and max, you can now shift and scale any value of
the function to the range 0.0 to 1.0.

3. Loop through each of the cells of the room rectangle and determine
the angle to the center of the room. This angle becomes your 'x' to
the wave function.

4. Plug this value into the wave function, then scale and shift it to
the 0.0 to 1.0 range. There is also a fluctuation variable that takes
the 0.0 to 1.0 range and adjusts it to something like 0.5 to 1.0. This
gives control over how far into the center of the room the edges will
dip. Notice - since the wave function won't loop at exactly 2 * PI,
the values near 0 and 2 * PI need to be blended in some way. I
linearly blend these both ends of the wave function and it works
great.

5. If the distance to the center is less than the radius of the room
multiplied by the function result, draw a floor cell.

6. Go back to 3.

A final pass can then be made to draw the walls to the cell by
checking if any neighboring cells are floor. The general idea of the
algorithm is that a circle is a midpoint with a constant radius, and a
cave or blob is simply a midpoint with a varying radius. The cosine
wave function provides a nice way to create smooth radius changes
while staying seemingly random. It is very flexible and can create a
variety of rooms, depending on the parameters given it. My current
code only allows for rooms with square dimensions, but it could be
adapted to use a horizontal radius and a vertical radius.

Once again, go to my blog for some sample screenshots using different
parameters.

My connection with 110mb pages (including my own...) is permanently
down while I'm at work. Possibly a firewall issue or something...

Anyways, from what I understand by reading the algorithm description,
your aim is to create rooms with the form of a... well, a "splat", a
blob or whatever... I'd love to see the screenshots.

I might try this out at home. Instead of using waves and angles and
such, I'll rather use Perlin noise :).

Mingos.
.



Relevant Pages

  • My cave room generator using wave functions
    ... for generating a generic cave room generator. ... algorithm, ... Randmonly choose n values to seed the wave function to be used. ... If the distance to the center is less than the radius of the room ...
    (rec.games.roguelike.development)
  • Re: Agduria dungeon generation
    ... stage of the algorithm and rise appropriate error, ... A NTAE generator doesn't have to have any ... NTAE will happily accept all valid inputs and RNG states and produce ...
    (rec.games.roguelike.development)
  • Re: Math.random
    ... That's not the only possible algorithm; ... without much difficulty implement a long shift-register generator; ... doublevalue or null/undefined/false for auto reseeding, ... I think 0 to 364 would be better; it goes well with zero-based arrays, ...
    (comp.lang.javascript)
  • Re: real random
    ... Feel free to post such an algorithm, ... it as a generator of a stream of numbers, ... You need a genuine source of entropy, ... By suggesting Fortuna (which gathers genuine entropy as it goes), ...
    (comp.lang.c)
  • Re: Agduria dungeon generation
    ... Depends entirely on the pseudo random number generator, ... algorithm don't suddenly change that probability. ... TAE isn't even obviously less ... algorithms but do understand their NTAE algorithms, ...
    (rec.games.roguelike.development)