MManoah / NQueens-OptimalPathAlg

Solves the NQueens problem using Uniform Cost Search or A* Search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NQueens-OptimalPathAlg

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 Two Algorithms

A*

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)

Uniform-Cost

The Uniform-Cost algorithm uses the path cost in order to find an optimal solution.

f(n) = g(n) where:

g(n) = path cost

Example

Here is a solution for the 8-Queens problem using the two algorithms

Here would be the board configuration for A*

Built With

  • Python

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Solves the NQueens problem using Uniform Cost Search or A* Search

License:MIT License


Languages

Language:Python 100.0%