I've been trying to create the diamond square algorithm in ruby and whilst it works (that is to say it doesn't error) it doesn't output as expected, so
far here's the output at various states:
This is the output of when I first got it working, as you can see it's in straight lines and there's no colourisation difference
I realised what I was doing wrong and fixed the colourisation problem by flipping the case select, I should have been checking for the highest hight first and then go downwards, because I was looking for the lowest first, it would hit that and stop, hence everything was ether water or sand.
I realised that it was how I was initialising the array that was causing the array to be filled with lines, Instead of creating 10 arrays of 10 elements, it was creating one array of 10 elements with 10 references to the same array, changing the array in one place would change it for every array at the same place, changing how I initialised the array fixed it, it now generates a new array for each element in the main array.
As you can see from the last pic, it was generating somthing but it wasn't a proper land mass, so I've re-attempted that algorthm in a different way and well, it now generates this.
My github repot for this can be found here, to run it is simple, clone, bundle install and then just
ruby test.rb and it should display somthing simmilair to below.
The algorithm specifically lives here.
The method that handles base execution is
#main, the main loop is actually a recursive call to
#step and the methods
#square_step handle each step.
The old version of the algorthm lives in the commented out
#square_step methods (though they won't work without some tweaking).
The code used in the current algorithm was adapted from: here.
The code from the older algorithm was taken from a question on gamedev stack but I can't find the question/answer I took the code from.
So, where am I going wrong, why is my implementation not printing out a reasonable looking landmass?