• Godot HelpProgramming
  • How do you properly and efficiently generate random numbers and noise for map generation?

I've been playing around with Godot for a while, and I decided to try and test programming an ASCII graphics (so, only using 2D here) game with Godot. It takes less than half a second for my computer to generate 6728 (116 rows and 58 columns) of '.' symbols. I tried a couple of things, ran into some errors that were easy to overcome but one of them isn't. A big thing about games with ASCII graphics (mostly roguelikes, I'm thinking of Dwarf Fortress and CDDA) is random map generation.

So I tried to generate a "space map" with white '*' symbols on a black background. Less than 0.5 seconds. Then I added a condition, for which the game would draw a '*' only if a random integer between 1 and 10 was bigger than 9, so that's 10% of the times.

The result isn't too bad for what I'm trying to do, but the problem is it takes my computer about 45 seconds to generate this. And the only thing I added was this var rndi = randi()%11+1 if rndi > 9: map[x][y][1] = '*' else : map[x][y][1] = '' condition. So clearly generating random numbers is something my computer can't do in a comfortable time.

So basically I would like to know in what ways do roguelikes generate random maps, and what ways of generating a random map full of features there are without my computer melting after 2 hours of programming and testing.

My plan was to generate different levels of maps, in which the sun would be a small part of the bigger map, then when you enter the solar system each planet has its own sector and so on. Sort of how the game "The Ur-Quan Masters" works. But if by only generating star symbols which hold no additional information it takes my computer 45 seconds, I clearly need a better way of doing this before my generation times get to hour-levels.

Thank you in advance for reading and helping!

Edit: It takes 45 seconds with google chrome open and running, it takes about 7 seconds without it lol....chrome is the programmer killer

7 months later

I am making a roguelike too and just started delving into random map generation over the last week, I can create these in a second, maybe 2.

That is a way zoomed out pic of a 100 x 100 cell map with a cellsize of 32

I fill a map with walls to start(all walls added to filler list)

Add stairs up and stairs down, link them to previous/next maps.

then I have a special Room type, I grab a random filler from the list, put the abstract room down and it expands randomally, grabbing up grid points that it takes out of filler and adds to the rooms list instead,

Once rooms are generated from filler... I add the DrunkenMiner node to the map(tilemap) and let it do it's Drunkards Walk, where it runs around gobbling up walls and adding them to the floors list instead.

I also require the DrunkenMiner to visit each room and map feature to ensure everything is reachable. I also add "noise" to those straight paths to map features. Basically grabbing a random number of random adjacent points to each line point and dig them out if they are filler, makes kewler caves :P.

I generate my maps on a 2dimensional array filled with a custom Terrain type, then add the appropiate tiles to the actual tilemap afterwards.

p.s. if you are using GD.Print() anywhere in your generation code it will slow it way down. Also I would check out Roguebasin, they have some great articles.

3 years later