Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

8queensGIT

8-Queens Problem

This program solves the famous 8-Queens Problem and will print a random solution out of the total 92 solutions on an 8x8 formatted chessboard. The 8-Queens Problem is a classic chess problem where the main goal is to place eight queens on a standard 8x8 chessboard in a way that no queen threatenes another. This means that no two queens can be on the same row, column, or diagonal. It uses a backtracking algorithm to place the queens on the board and will check that no other queen is in the same row or diagonal.

The code solves and stores all possible solutions to the problem by calling the 'solve_and_store()' function. It then randomly chooses one of the solutions by creating a random number and then compares itself to the total number of solution. The program then prints out one random solution out of the 92 solutions and generates an image based on the solution using cairo graphics and save it on your desktop for you to view. To verify the printed board use the following website: http://www.datagenetics.com/blog/august42012/index.html

Test cases

Screenshot 2023-05-05 165535_1

solution

Installation

This program might ask you to install some librarires so if it does just run the following command:

sudo apt-get install libcairo2-dev libcairo-gobject2

To see if it is installed:

dpkg -l | grep -E 'libcairo2-dev|libcairo-gobject2'

Compilation

Make sure you are running it on a working version of ubuntu. To compile it run this command on terminal:

gcc -o queens queens.c $(pkg-config --cflags --libs cairo)

If everything is done correctly then it will compile and you can run the program using: ./queens

About

This program solves the 8-Queens Problem and prints a random solution on an 8x8 board. The program uses a backtracking algorithm to place the queens on the board then checks if it is safe to place each queen in its column by verifying that no other queen is in the same row or diagonal.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages