A demonstration of simple hill-climbing.
In this demonstration, values of an objective function h are non-negative integers which are translated into brightness values for grid cells. Each cell of the grid has a [row, column] position; the top left cell has position [0,0]. Lighter cells are "better" (have higher objective function value) than darker cells. A random grid cell is selected as the starting point. The objective of hill climbing is to get to a cell with the highest value of the objective function (shown in green). Approximately 30 percent of the cells are black; they have a value of 0.
Hill climbing operates in steps. In each step, there is a "current" cell (current state, shown here in yellow). The neigbors (N,NE,E,SE,S,SW,W,NW) of the current state are generated, each having a coresponding value according to the objective function. If the value of the best neighbor is higher than that of the current state, then then this best neighbor is selected to be the new current state (ties among best neighbors are broken by a random choice between them). In the grid below, neighbors which are better than the current state are shown in light blue. Hill climbing stops if all of the neighbors of the current state have worse/lower values than the current state.
There is no guarantee that simple Hill Climbing will be able to reach an optimal state for a given grid and initial state. Sometimes it just gets stuck in a location where all of the neighbors are worse than the current position.