Hill climbing

Hill climbing is a simple enhancement to random walks that only takes a step if the fitness of the new solution is better than the current solution. This means that we definitely get better and better solutions, but it is also guaranteed to get stuck at the first peak it finds, whether it's any good or not.

In this example, like with the other random walks, the fitness of a particular location is shown by how light the grey colour is. This is randomly generated when the page loads.

Each (x, y) point in the square is a solution, and our goal is to find the best (lightest). We start in the centre and move a set distance at a random angle at each step. Like the enumeration method, I've made the edges wrap around. There's no need for a trick like using irrational angles this time, since we're not imposing an order on the search space. This is an advantage of algorithms based on random walks, since they can be dumped on to any problem without any messing around like craft an exhaustive enumeration.

Current fitness: