The same way I detected (and named) the islands, I would like to detect oceans. (It helps with hints abouts shipwrecks and treasure burying, if I can say: "it sank in the blabla ocean".)
This is the idea.
All water in the game is connected. How do we differentiate bodies of water? Anywhere there's a gap of only 1 or 2 water tiles, we say is an edge between two separate oceans
How do we detect this? I propose the "grow algorithm":
We grow all islands by one tile. This simply means: for every land tile, temporarily set all neighbours (left/right/top/bottom) to land as well.
This way, gaps of 1 or 2 tiles will be closed off by land now!
Because of this, we can use the "island discover" algorithm, but instead of looking for land tiles, we only look for sea tiles. This way, we will find nice, separate, oceans.
Only one problem: what to do with the tiles we have "grown"?
First of all, we save the tiles that we expanded in a list.
Once the oceans have been established, we go through the list, and turn each tile into water again.
We ALSO check the neighbour tiles to see which ocean they belong to. If we find a tile which is part of an ocean, we simply make the current tile belong to the same ocean.
It's possible for some water tiles to NOT belong to any ocean, but that's actually realistic. These tiles will be very close to land and too far away from other bodies of water, and would, in real life, certainly not be called oceans.
Surprisingly, it works! After fiddling a bit with the settings (the islands grow one tile in all directions, and then another tile horizontally and vertically.)
Two more issues:
Naming the bodies of water (ocean vs sea vs gulf vs ... + an actual unique name)
Now we DON'T incorporate the grownTiles in the ocean size. Should we?
The same way I detected (and named) the islands, I would like to detect oceans. (It helps with hints abouts shipwrecks and treasure burying, if I can say: "it sank in the blabla ocean".)
This is the idea.
All water in the game is connected. How do we differentiate bodies of water? Anywhere there's a gap of only 1 or 2 water tiles, we say is an edge between two separate oceans
How do we detect this? I propose the "grow algorithm":
Only one problem: what to do with the tiles we have "grown"?
It's possible for some water tiles to NOT belong to any ocean, but that's actually realistic. These tiles will be very close to land and too far away from other bodies of water, and would, in real life, certainly not be called oceans.