A Python project for solving 8 queens problem and visualizing it using OpenCV library.
Here is the Wikipedia explanation at this link for the 8 queens problem:
The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other; thus, a solution requires that no two queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general n queens problem of placing n non-attacking queens on an n×n chessboard, for which solutions exist for all natural numbers n with the exception of n = 2 and n = 3.
This problem can also be solved with brute force (by trying all possibilities). If we wanted to solve this problem with brute force on an 8x8 chessboard, the cost of trying all combinations would be:
Instead of trying all (4,426,165,368) possibilities with the solution in this repository; It is calculated by reducing the 2-dimensional chessboard to one dimension and using column indexes over one dimension. Cost after this reduction for 8x8 chessboard:
Python 3.7 or higher is required to run the project.
Also OpenCV library is required for visualization. You can build OpenCV from source code or install it using PyPI as described in the Installation section.
Clone the project with:
git clone https://github.com/YusufBerki/PyEightQueen.git
To install the required libraries, go to project directory and run the following code:
pip install -r requirements.txt
Run the following code to see the solutions for the 8x8 chessboard:
python main.py
Can change this line to see the results on different sizes of chessboard.
See MIT License