Skip to content

This code solves the 8 Queen Problem in Chess using backtracking.

Notifications You must be signed in to change notification settings

dodyeid/Eight-Queen-Problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

Eight Queen Problem

The python file solves the 8 queen problem in chess, explained here: https://en.wikipedia.org/wiki/Eight_queens_puzzle

Method

I save the diagonals of the chess board into two dictionaries. I then write a function that takes some chess position as an input and outputs all the "attacked" ranges. I can then check if n positions/pieces attack each other. Finally, I build a nested-for-loop backtracking algorithm that places queens on the board one at a time, each in its own column. When 8 pieces do not attack each other, I print the result. 92 distinct solutions are found and printed!

In Progress

I am currently working on avoiding the nested for-loop by using recursion.

About

This code solves the 8 Queen Problem in Chess using backtracking.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages