sraaphorst / spelunker

Maze generation and solving library
Other
11 stars 2 forks source link

Fix `RNG` to use an instance instead of static methods #46

Closed sraaphorst closed 6 years ago

sraaphorst commented 6 years ago

Right now, the implementation of RNG only allows subclasses to implement two methods, namely:

and it then uses these on a concrete, registered instance of a subclass of RNG to handle all tasks requiring randomness.

This is not very good, for example, when it comes to shuffling a container, or picking a random element from a container.

Instead, RNG should have static methods that call default virtual protected Impl methods. The current static implementation will be moved to these Impl methods, and subclasses of RNG can override them with more efficient implementations.

For example, right now we have:

public static auto RNG::randomElement

which uses the concrete RNG subclass implementation's randomRangeImpl to get the element in an inefficient way.

Instead, we should have, in RNG:

Then DefaultRNG will override this with a more efficient implementation.

sraaphorst commented 6 years ago

Never mind: we can't do this because templates cannot be virtual.