The N-queens puzzle is the problem of placing N queens on an N x N chessboard such that no two queens attack each other. This finds a solution to an N-Queens problem using either Uniform-Cost search or A* search.
The indexes of the list will represent columns on a chessboard (0 -> N-1) while the numbers in each index will represent the row of the queen location in that column (0 -> N-1).
The A* algorithm uses a combination of heuristic values and the path cost in order to find an optimal solution. This algorithm is significantly faster than Uniform-Cost.
f(n) = g(n) + h(n) where:
g(n) = path cost
h(n) = heuristic (estimated cost to the goal)
The Uniform-Cost algorithm uses the path cost in order to find an optimal solution.
f(n) = g(n) where:
g(n) = path cost
Here is a solution for the 8-Queens problem using the two algorithms
Here would be the board configuration for A*
- Python
This project is licensed under the MIT License - see the LICENSE file for details