Hallway Test

Show off your mod creations or just a work in progress.
User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

I ended up using "xorshift" for my random number generator. It inputs a seed, and then uses the following code to generate the number:
Spoiler!
long useSeed (long oldSeed)
{
long move1 = oldSeed+1;
long move2 = 13;
long move3 = 37;
long move4;

move1 ^= move1 << 16;
move1 ^= move1 >> 7;
move1 ^= move1 << 3;

move4 = move1;
move1 = move2;
move2 = move3;
move3 = move4 ^ move1 ^ move2;

Debug.Log(move3);
return move3;
}
Now I am wondering what is the best way of picking out digits from this number to decide how the dungeon gets generated. I've also noticed that, as the length of the input number increases, the length of the output increases as well. If I were to put the output back into the generator, would it still maintain the same level of randomness?

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Hallway Test

Post by LypyL »

Both Unity and C# have built-in classes for random number generation. I really doubt you have a need to use anything else than one of these.

https://www.dotnetperls.com/random

https://docs.unity3d.com/ScriptReference/Random.html

Code: Select all

Now I am wondering what is the best way of picking out digits from this number to decide how the dungeon gets generated
Second - can you define what you're doing with the random output to create the dungeon? I'm not clear on this.

User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

I wanted a random number generator so that I can take a predefined seed and turn it into a much larger number to work with, while still being consistent as to what number I get as an output. That way the dungeon is the same every time it is loaded.

What I want to know is how to use the seed in order to create a randomized, yet consistent, dungeon. If I want to pick out two random points on a grid, I need an input number to decide what those points are. Do I just take 2 digits from the seed at specific places and use those to choose a point of the grid, or do I take the entire seed value and do something with that? How do I use the seed to build out individual parts of my dungeon?

User avatar
LypyL
Posts: 512
Joined: Sun Mar 22, 2015 3:48 am

Re: Hallway Test

Post by LypyL »

I wanted a random number generator so that I can take a predefined seed and turn it into a much larger number to work with, while still being consistent as to what number I get as an output. That way the dungeon is the same every time it is loaded.
That's how all random number generation libraries work (there might be some exceptions of course). For example, with the one provided by Unity, you use InitState(seed) to seed the generator.
What I want to know is how to use the seed in order to create a randomized, yet consistent, dungeon.
The seed is just an input given to the generator to control the output. Forget about random number generators for a second - imagine instead you had a program that took any number given, and used in a basic math function like x*100

There obviously isn't anything random about that - if x is 2, the output is always 200. If three it's always 300. 4 it's always 400 and so on, an easy pattern to see.

Now let's pretend that each time after the first you called for a new random number, the generator added 1 to the last number used for the seed.

So if your original seed was 2, the first time you called for a number you would get 200 (x = 2), the second 300 (x=3), third 400 (x=4) and so on. As long as the original seed is the same, the outputs you're going to get from the generator remain the same.

This is essentially how random number generators work - they take a number you give it (the seed), and use it in some mathematical functions. So if you give it in the same seed, it's always giving you the same pattern like the stupid example above. The seed isn't helpful for you beyond knowing that if you give the generator seed X it will give you the same outputs every time your program runs.

Now, as to how you use random numbers generated to build your dungeon - that's a far more complicated matter. Picking random points in space isn't going to get you anywhere IMO. The "normal" way would be to use random numbers to chose assets. For example, say you started with a hallway piece, you know there are 2 open ends, so you have the random generator decide what goes on each end - maybe it picks a wall for one side, a room for the other (repeat until you have a dungeon - it's so easy :lol: ). random numbers could also be used for deciding textures, monsters, loot and so on.

keep in mind that procedural generation is not a magic bullet - it's very hard, probably harder than just manually building something like a dungeon.

This article might help you wrap your mind around the problem.

I would also suggest that maybe you don't just dive right into procedurally generating 3D dungeons. Following something like a tutorial for a traditional 2D roguelike might be better.

User avatar
LorrMaster42
Posts: 65
Joined: Thu Dec 24, 2015 12:09 am

Re: Hallway Test

Post by LorrMaster42 »

Here is an update of what I've been doing so far. I'm currently redoing my code in an attempt to make the dungeon system that I'm setting up simpler and more lenient for a wider variety of designs.

The following is the inspector system that I had set up for chosing dungeon models, as well as some examples of how a dungeon might change.
Spoiler!
Image
Image
Image
Image
In this example there are "design lists" in the inspector that each contain a list of "design sets". A "design list" would be a type of piece (such as a wall tile or a floor tile), while a "design set" would be a visual style for that piece (such as a flat ceiling or a curved ceiling) and each element in the "design set" would be a type of hallway tile (such as a straight piece or a corner piece). Upon generation, the script will choose a "design set" to decide the style for each "design list", which will then be mixed together to as some variation to the look of each dungeon, or potentially to make certain parts of the dungeon appear different from one another. The trouble that I'm running into on this part of the code is how to design the inspector and link the tile information. I want to have a class separate from the dungeon generation script that can be linked together, be I'm unsure of how I can store the models for the dungeon type and then link the script's models to the dungeon generator to produce my results.

As for the dungeon generation, I'm trying to come up with an algorithm that will try and make each room appear unique and have variables that can manipulate how a dungeon type is generated. Originally I was going to generate the dungeon on a chunk-based system, where each chunk would contain a room or series of hallways. However, I ended up deciding that this would be too repetitive, so I'm now working on a system where rooms can get built individually and then be placed and connected by hallways afterward. I'm thinking of giving each dungeon a power meter as well, which could be used to track how big the dungeon has grown and add extensions to it upon generation. This way you could have dungeons grow over time while still retaining their original layout.

Definitely looking for suggestions.

Post Reply