The ball starts at a point
The ball is at x = 3, with fitness 0.17. Hill climbing does not see the whole landscape; it can only look right next to where it stands.
Look at the two neighbours
The step size is d = 0.50. The left neighbour is x = 2.50, with fitness 0.19; the right neighbour is x = 3.50, with fitness 0.33. The red dot is the higher neighbour; the blue dots are lower ones.
Move to the higher neighbour
The ball moved to the higher neighbour: now x = 3.50, fitness 0.33. The same question is asked again: is one of the new point's neighbours higher?
Step 2
The ball climbed again: x = 4, fitness 0.58. Each step makes only two measurements, which is why hill climbing is very cheap.
Step 3
The ball climbed again: x = 4.50, fitness 0.70. Each step makes only two measurements, which is why hill climbing is very cheap.
Stuck on a local peak
Both neighbours are lower, so the climb stops. But the fitness at x = 4.50 is 0.70, and the global peak at the flag is higher. Hill climbing never accepts going down, so it cannot cross the valley between two peaks.
Random restarts
The simplest fix: climb separately from 5 random points and keep the highest. Red dots are runs that stopped on the global peak, blue dots runs that stopped on a local peak. 3 of the 5 runs stopped on the global peak; the chosen result is x = 8.18, fitness 0.98.