The 8-Queens
Problem is a problem of placing eight queens on an 8x8 chess board so that no queen
attacks another queen.
This algorithm goes through every combination and finds all possible
solutions. There are 92 solutions for the 8x8 board of an 8-queens problem. The program
will first go 'quickly' through all the solutions (delaying only about 2/1000
of a second between different combinations; hey, I want the search to actually be visible!
If you can't wait, download the source, remove the Thread.sleep() calls out of find8queens()
method, and recompile), Once it finds all the solutions, it will suspend the
searching thread. The user at any time can stop or continue the
searching thread. The user can also click on any of the solutions, and then on the 'view'
button to view that solution in the 'view' area. Once all the solutions have been
found, the program will sleep for 15/1000 of a second between possible combinations (so
that you can actually see what's going on).
Problem: The applet seems to flicker quite a bit when running. I can't
figure out why, or how to eliminate it. I have the update() and paint() methods
overloaded, and still, it flickers. If you have a solution, please let me know.
There are many other solutions to this problem. Some do it row order,
and not column order (as this one does).
NOTE: Unfortunately, this applet only works on newer
browsers which support JDK 1.1, and will not work on browsers such as Netscape 3.0 (at
least not on the UNIX version I've tested), however, it does work perfectly under Netscape
4.0 (again, UNIX version), and under Internet Explorer 4.
You can download this applet (and/or the source for it here) License
Agreement is in the source file.
[queens.java][queens.class][queensCanvas.class]
|
© 1996-2024 by End of the World Production, LLC. |
|