Eight Queens Example

A standard introductory programming exercise, given a new look.

Applet should appear here but you don't have Java enabled in your browser.

The code

The code for this example is partially taken from Larry Paulson's book ML for the Working Programmer (Second Edition), published by Cambridge University Press, 1996. Those parts are subject to the following copyright notice and disclaimer of warranty.

The structure AQueens computes a circular lazy stream of solutions to the problem using a general depth-first search. For each adjacent pair of solutions, another search enumerates the legal ways of moving the queens from one solution to the next and picks an `interesting' one (in this case, the one with the most diagonal moves, but that's easily tweaked).

The second part of the applet is the structure AQueensApplet which declares the applet and sets up a concurrent thread which actually does the animation. This is fairly imperative code and makes heavy use of MLj's Java extensions -- it was based on an MLj transcription of some code from Java in a Nutshell by David Flanagan.

MLj home Comments to: mlj@dcs.ed.ac.uk