So i want to do a Map generator and am currently at making it put out Bodies of water in a Tile Based Enviroment.
So i input a number of Squares that should be turned to water (from the Base that i spawned first) then the program playces a “seed” Water Tile which the other ones can be placed around (to create continious Lakes instead of Sprinkled puddles).
Up to this point it runs smoothly.
But now i want the programm to loop through all available Base tiles, check if its next to water and if so turn that square to water as well. Yes its gonna miss a lot but ever so often it should hit a tile thats next to water increasing the chances down the line until the requested amount of Watertiles has been made
… at least thats the idea…
But i get an infinite Loop error every time, unless i set the parameters for placement so high that it basicly lands on a hit every time (for exsample on a 20*30 map allow the water to be up to 15 tiles away from the next) as soon as i tune it down so the success rate is below aprox. 50% it downright says its infinite altho mathematicly it should resolve after not even uncountably many steps.
How do i solve that Error ?
Can it even be solved ?
Thanks in Advance
This is closer to what you said, but still wont work, because it has nothing to do when there are no water tiles. ( don’t run it ). Have a look while I re-read your stuff:
While amount of Watertiles = less than Set Percentage of Land Tiles → 2.Get all Land Tiles → 3. Select Random one → 4. Get distance to all Existing Watertiles → 5. If any is Below 160 (Size of my Tiles + small buffer), Spawn Watertile. If No, Repeat from 3.
Since there is a water tile created in the Previous Function (i tried the code multiple time and cut at different Points, up to here it definitly Works) it shouldnt be infinite here since after a certain amount of itorations its bound to hit close to one …
And yes u are correct i should have used Last Index instead of length to make the calculation precise, sadly that didnt fix the loop problem T-T
That looks really neat and Efficiant … but the whole idea is that i ont want to place a water tile on EVERY Land tile but rather place connected ones until a Threshhold is reached
Either way that small bit of code u put there allows me to start from another angle either way Thanks a lot already