# Help with Basic Array Logic

Ok so let’s do this one step at a time:

• Ideally, you would have each different “biome” represented with an int, that represents its index. So a forest would be 0, a desert would be 1, water would be 2, etc.
• Then, you would have an array (in your case 8x8, so with 64 elements), and you just add the corresponding index the amount of times you need. So, if you want a mountain at least 6 times, you add the index corresponding to the mountain (let’s assume that index is 4) 6 times to the array. Then you do that for all the tiles you want at least a certain amount of times in your world.
• When you’ve added all the amounts you want, but your array is still not full with 64 elements, simply add biome indexes at random until your array has 64 elements.
• When you’re spawning your biomes, pick a random index from your 64-size array, use it to spawn a biome, and remove it from the array. That way, you’ll have the amount of biomes you want, but still randomized.

Hi,

I have created an array (currently 8x8) in order to make a 64 cube grid. The idea of the grid is to be a map for players to combat on. So I am looking to make the map randomly generated. I have created several blueprint tiles, mountain, Forest, Water, ETC and I have placed them in to the map and they are placed randomly on construction and it works to a degree.

My issue is I would like to set a minimum and maximum amount of water tiles, a min, max amount of mountain tiles and so on. So that the map always has the same ingredients just in different locations. (for game balancing purposes)

At the moment my logic is overwriting previously set elements, so it looks through and makes say 8 index elements a 1 and 1 corresponds with water, but then I loop through and grab random index and set their element to 2 to create mountains. However as the whole thing is random there are times that the, let’s say water tiles, that were previously set are being overwritten by the new mountain loop.

So does anyone know any basic logic to create an array with randomly filled indices but with a specific number of specific Elements?

Using Shuffle and then for loops to insert items at an index might work. Like so.

(Edit: The second for loop’s first index (Max Water Grid) needs to be added into the second for loop’s last index)

Thanks for the response. I’ll take look.

Wow I never even knew the shuffle was there, that might help!

I assume an array of BPs was created in order to form grid array?

You can make a struct in order to store as many variables into an array as you want.

is with basic shuffle and a struct that only has X Y grid coordinates to spawn with.

is another method with which you can store the class to spawn into the array itself, and keep the grid coordinates in line with the array index.

the latter might make things more manageable in the long run.