Skip to content

A simple Eight Queens solver built with Java for CSE 486.

Notifications You must be signed in to change notification settings

Kyle-L/Eight-Queens-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eight Queens

Run on Repl.it

Table of Contents

Overview

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 [1].

Pseudocode

function MIN-CONFLICTS(max_steps) returns a solution or failure
 for i = 1 to max_steps do
   if current is a solution, then return current as solution
   conflict-queen ← a randomly chosen conflicted queen.
   min-column ← the column that minimizes the conflicts and is different from the column the queen is currently.
   move conflict-queen to the min-column.
 return failure

Sample Input

The starting board...
Q |   |   |   |   |   |   |  
------------------------------
  |   |   |   |   |   | Q |  
------------------------------
  |   |   |   |   |   | Q |  
------------------------------
  |   |   |   |   |   | Q |  
------------------------------
  |   |   | Q |   |   |   |  
------------------------------
  |   |   |   |   |   |   | Q
------------------------------
Q |   |   |   |   |   |   |  
------------------------------
  |   |   |   |   | Q |   |  
The solved board...

  | Q |   |   |   |   |   |  
------------------------------
  |   |   |   |   |   |   | Q
------------------------------
  |   |   |   |   | Q |   |  
------------------------------
Q |   |   |   |   |   |   |  
------------------------------
  |   | Q |   |   |   |   |  
------------------------------
  |   |   |   | Q |   |   |  
------------------------------
  |   |   |   |   |   | Q |  
------------------------------
  |   |   | Q |   |   |   |

Remote Setup

If you would like to run the project, you can use the online IDE Repl.it!

Run on Repl.it

Once, it has opened, all you need do is select run!

References

[1] “Eight queens puzzle,” Wikipedia. Oct. 18, 2021. [Online]. Available: https://en.wikipedia.org/w/index.php?title=Eight_queens_puzzle&oldid=1050602922