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

An implementation of the N-Queens problem using the Backfish backtracking library.

The N-Queens problem involves placing N chess queens on an NxN chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal.

Summary

Functions

Returns the initial state of the N-Queens problem.

Checks if the given state is a goal state.

Generates the next possible states from the given state.

Functions

Returns the initial state of the N-Queens problem.

Parameters

  • args: A keyword list of arguments. Expects :size which represents the size of the board (default is 8).

Returns

  • A map representing the initial state, including an empty board and the board size.

Checks if the given state is a goal state.

Parameters

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

Returns

  • true if the number of queens on the board equals the size of the board, 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 board size.

Returns

  • A list of the next possible states, each including the new board configuration with one additional queen placed.