buckinha / DiamondSquare

A python implementation of a diamond-square algorithm
MIT License
29 stars 8 forks source link

Square-step efficiency #1

Closed buckinha closed 8 years ago

buckinha commented 8 years ago

The "square step" is not being done as efficiently as possible. Namely, A grid of 2n points are being checked for each n points that need to be changed, so half of those that are iterated over are just being skipped.

buckinha commented 8 years ago

Fixed. However, the random number generator, though invoked the same number of times, is used for cells in a different order, so the landscapes generated by the updated version will not be identical to those produced by the older version, even when the same seed is used.

The new method consistently runs in about 92% of the time of the old one (at multiple map sizes), so it's not an earth-shaking improvement, but it can't hurt.

If you need replicability for the older version, just add the optional, argument: USE_NEW_SQUARE_STEP=False, and the older (slower) method will be invoked instead.