# Random 100x100 map using all levels from 1 to 100

I'm developing a game where players walk though a 100x100 grid of different rooms. Each room has a level associated with it starting from lvl 1 to lvl 100.

The map is divided into 10x10 areas and in the middle of each area there's a 2x2 "castle" which players must conquer in order to access next levels castles (so if players start off at lvl 1 they need to conquer the lvl 1 castle before being able to enter lvl 2 castles).

Each room in a castle (2x2 area in the middle of each 10x10 area) has the same level and there must be a castle for each level from 1 to 100.

As for now I was generating the whole map "statically" and use the matrix blur to interpolate room levels between castles.

What I would like to achieve is having a seeded function f(x,y) that returns the level of the room at position (x,y) without pre-defining the matrix.

I checked out Perlin Noise functions, but it doesn't guarantee each level between 1 and 100 is taken nor the right position of the "castles".

The image above is the starting point of the game map, lower levels of green represent lower room levels, the blue squares in the center are the castles. This image is then blurred preserving just the castles level.

Players can move around the map and will meet harder challenges in higher level rooms. The goal is reaching level 100 by spotting and conquering each castle in sequence.

• What I'm reading doesn't seem to add up. If I understand correctly, you plan for there to be ten 10x10 areas—one for each level and for each castle. But 100x100 fits a hundred 10x10 areas — 10x100 would fit just ten in a line, by comparison. (Drop it down an ordinal to make it clear: a 1x1 zone, in a 10x10 space, makes for 100 zones.) Things could be more spread out, but zones would have to be adjacent, because if the level 3 castle is on the opposite side of the map from the level 1 castle, it would likely be impossible to reach it. Are you sure you've described what you want? Nov 10, 2020 at 16:57
• Including a diagram of one or more desired generator outputs could be a big help here, so we can judge answers by how well they can produce maps like the examples you showed. Nov 10, 2020 at 16:59
• Do you need to guarantee that from the starting location to the i-th castle, there is a path moving only between adjacent rooms of level <= i ? Or do you have any other constraints on how the region levels may be distributed? Nov 10, 2020 at 21:26
• Why do you not want to pre-define the matrix? That seems like a trivially simple solution. Nov 10, 2020 at 21:43
• So do I understand it correctly if I say that you have a 10X10 grid containing the numbers 0 to 99 which you want to distribute randomly with no further constraints whatsoever? (for instance, level 0 may end up in the middle and level 1 may end up in the bottom right) You also want to be able to then add another 10x10 grid to any side where the numbers 0 to 99 (or 100 to 199?) are randomly distributed within that other grid. And the most important thing is you want to get that randomly distributed number using a method that looks like this: GetAreaLevel(xPos, yPos, seed) Nov 11, 2020 at 11:37

To ensure all castles 1-100 are present, simply shuffle an array containing all the numbers 1-100. You can either do this once when you first generate the map and then hold onto it, or you can use a seeded random number generator to assist with the shuffle so that you get consistent results each time. Here is an example in Python. If you're using another language, there may or may not be an equivalent, but it's a simple enough process that you could write your own shuffler.

The following example (pseudo-code) assumes you'll generate it once and re-use it; if you really want to re-generate it each time, just use a seeded shuffle to ensure consistency.

    world_map = generate_world_map(10)

def generate_world_map(size):
castles = range(1, size*size)
shuffle castles
split castles into array[size][size]
return castles

def get_room_level(x, y):
map_x = floor(x/10)
map_y = floor(y/10)
castle_level = world_map[map_x][map_y] # Replace this with func call if re-generating every time
adjacent_catles = world_map[map_x +/-1][map_y +/-1] (up to 4 - or 8 if diagonals included - other castles; fewer if at an edge)
do blurring thing



It sounds like you've got the blurring bit right and are just concerned about castle consistency. This approach should handle that. Just remember to look out for edges.

• Instead of building the whole 100x100 room array to blur it, you may want to consider using a Perlin Noise style approach, where you can get the level of any random room on demand by looking up the levels of the 4 castles that surround it, and applying an interpolation based on its offset from each. Nov 12, 2020 at 14:09
• @DMGregory That's the intent of this answer. I see that the adjacent_levels line is maybe a bit too handwavey and the comment ambiguous, so I'll try to clarify Nov 12, 2020 at 14:13
• I think it's worth elaborating on the use of an interpolation function rather than a blur kernel here. Nov 12, 2020 at 14:26
• Hey thanks I upvoted this! I'll try out what you suggested and come back with feedbacks! Nov 12, 2020 at 14:30
• @DMGregory I'm not sure it is necessary. They seem to have that part covered, and the issue at hand was really ensuring proper distribution of castles/levels before dealing with the individual rooms around each castle. Nov 13, 2020 at 14:24