Skip to content
eriksapePublic

About

Placing N chess queens on an N×N chessboard

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NQueen Problem

The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. For example, following are a solutions for 4 Queen problem.

4x4_solution_1 4x4_solution_2

These are known solutions for the NQueen problem

known_solutions

We need to generate and store most solutions in < 10 minutes

Backtraking:

Generating from 8x8 to 13x13 N size we have the next results: backtracking_8x8_to_13x13

Bitwise:

Generating from 8x8 to 15x15 N size we have the next results: bitwise_8x8_to_15x15.png

The problem here is that we have 2,279,184 solutions that we want to store in a database. With some optimizations with SQLAlchemy we can have the next results:

bitwise_8x8_to_15x15_to_database

We can see the count per record in the datase with the next query:

stored_solutions

We can see there are not solutions listed for dimension 2x2 or 3x3, that's because are not known solutions as we can see on the follow query:

query_cases

References

Extra

We can see the stored solutions in http://localhost:1001/

web_stored_solutions

To run the project we need Docker installed in your system. docker-compose up

To create the database run the script docker-compose run nqueens flask initdb

Tests

To run the tests we have some scripts:

  • This is to check from 1x1 to 12x12 docker-compose run nqueens python -m pytest app/tests/tests.py helped me with some refactors
  • This is to run from 8x8 to 15x15 docker-compose run nqueens python -m pytest app/tests/tests_solutions_not_saving.py
  • This is to run from 8x8 to 15x15 and save it into database docker-compose run nqueens python -m pytest app/tests/tests_solutions.py
  • This is to run from 8x8 to 15x15 from database docker-compose run nqueens python -m pytest app/tests/tests_solutions_stored.py

Tests are automated thanks to github actions ♥️

Here are automated test runned in this project.

About

Placing N chess queens on an N×N chessboard

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages