Skip to content

taylor-meyer/N-Queens-Problem-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

N-Queens Problem Solver

The N-Queens Problem involves placing N queens on a NxN chessboard. This program will take two inputs:

  1. N queens to solve for.
  2. k states for use with a genetic algorithm.

The program generates k random states of the chessboard. We know how many non-attacking pairs we need for a solution e.g. n=8, there need to be 28 non-attacking pairs.

We check each of the randomely generated states for how many non-attacking pairs they have. We take the two highest scoring states accprding to a fitness function and "splice" them by swapping half of the two states with each other. The states are then tested again. When we calculate the correct amount of non-attacking pairs, we print the solution to the console.

n=8 (real chessboard) can be solved in less than one second. It can solve for n=50 in two to four minutes.

Written in Python.

Images

Console output

About

Prints solution for N-Queens Problem with user given N

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages