View Source Backfish.Examples.EightPuzzle (Backfish v0.1.0)

An implementation of the 8-puzzle problem using the Backfish backtracking library.

The 8-puzzle consists of a 3x3 grid with 8 numbered tiles and one empty space. The goal is to move the tiles around to achieve a specific end configuration.

Summary

Functions

Returns the initial state of the 8-puzzle problem.

Checks if the given state is the goal state.

Generates the next possible states from the given state.

Functions

Returns the initial state of the 8-puzzle problem.

Parameters

  • args: A keyword list of arguments. Expects :board which is a 2D list representing the initial board configuration.

Returns

  • A map representing the initial state, including the board and a set of visited states.

Checks if the given state is the goal state.

Parameters

  • state: The current state of the problem, which includes the board configuration.

Returns

  • true if the board is in the goal configuration, false otherwise.

Generates the next possible states from the given state.

Parameters

  • state: The current state of the problem, which includes the board configuration and the set of visited states.

Returns

  • A list of the next possible states, each including the new board configuration and updated visited states.