What is the best way to locate a region inside a map?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Somar
 Before I start just want to let you know that I am very new to Godot and programming in general, and that I do not know every concept of programming, and math is not really my forte. But I am very keen to learning new things. Sorry for any English mistakes and thanks in advance.

I have this drawing of what I am trying to achieve:

This is a map with 30x30 tiles, each tile being 8x8 pixels. The objective of my code is to:

  1. Select three random locations having the regions as modifiers for the chance of the seed being located there. The red region would be the rarest, the yellow the uncommon and the green would have a higher chance of spawning a seed.
  2. Each seed would define its own region and spawn other two to three seeds that would again create their own areas.
  3. In step three all the map would be filled with tiles. The regions created in steps one and two would highly increase the chance of spawning water tiles, while the remaining area out of the regions would be populated with grass tiles.

The result without the tiles being something like this:

The code I am currently using is very repetitive and not very editable. And makes it necessary to make if statementsfor every corner of every region created this way. Becoming very, very repetitive and not very editable (I’ve not been able to make variations of regions size and quantity of secondary nodes).

This is a snippet of what I am currently using:

func _getChance(cellX, cellY):
if cellX >= 21 and cellX <= mapSize-21 and cellY >= 21 and cellY <= mapSize-21:
	chance = 2
elif cellX >= 5 and cellX <= mapSize-5 and cellY >= 5 and cellY <= mapSize-5:
	chance = 11
	chance = 28

This only creates the three original regions. I would have to repeat it 17 times! to achieve something like the second image. How can I automatize this?

:bust_in_silhouette: Reply From: CharlesMerriam

This is the algorithm you seem to be asking about:

map = a grid world (32x32) that will hold tiles 

# set up the spawn rate
spawn_rate = a grid world that holds probability (0.0 to 1.0), with 1.0 being 'it is always land'.   Initialize to some low value for land, like 0.05 (5%), meaning 'not near any seed'.
for bonus in [10, 5, 3]:  # bonus regions of red, yellow, green.
   center = random point in grid, which allows regions to overlap
   # area around seeds is more land-likely
   increase_region_by_bonus(bonus, center, 6)  
   for sub_bonus in [5, 3, 2]:  
      sub_center = random point within radius of the center
     # area around extra seeds inside a region is even more land-likely
      increase_region_by_bonus(sub_bonus, sub_center, 2)  

# Now use the spawn rate to actually make the map
for square in grid:
   if random between 0 and 1  < spawn_rate[square]:
       grid[square] = water
      grid[square] = land

return the grid and whatever you want.

How realistic the maps look is another question.