A Simple Windows®-based
To Solve The "N-Queens on an N x N Board" Puzzle
For WqGStep2.exe Version 188.8.131.52
WqGStep2.exe is a Windows®-based
program that finds
solutions to the "N-Queens
on an N by N chess board" puzzle, for board sizes from 1 square by 1
square (a hypothetical board of course!) up to 32 squares by
32 squares. It shows a simple graphical board
and gives plain-English descriptions of some of the results of its
from the program.
On the left, it's
nearly half way through its discovery
of all 15 x 15 solutions.
On the right, it
has found the first-possible
solution for the 32 x 32
Click the pictures to see full-sized versions
This simple demo
program has a maximum
of 32 x 32 squares.
specific aim of the
program is to accompany my related entries
in the On-Line Encyclopedia of Integer Sequences
(OEIS). The two OEIS sequences ( A140450
and A141843 ) show respectively
how many tentative Queen
placements are needed to find the first puzzle-solution
board sizes, and the list of First Solutions I've discovered
This is a lightweight program, with no bells or whistles, and it has
not been optimised for speed or for a great User
experience! In the 10 years or so since it was written it has
spawned many more sophisticated later versions, but this 'minimalist'
version contains enough functionality to illustrate some
aspects of my Queens solution-seeking
The "tentative Queen
placement" algorithm employed by the program is explained on my Queen-placement
As soon as the program is started it begins seeking the FIRST solution
to the "N-Queens" puzzle for the size of board that was set the last
time the program was executed. When it is run for the first
time, the board size will be the familiar 8 squares by 8 squares.
The program has a 'Tick box' option so the User can choose either -
There are buttons to do the following -
- To stop seeking solutions as soon as the first possible
(This is the
default option when the program is first launched)
- To continue seeking all solutions for the current board
For example, there are 92 possible solutions for an 8 x 8 board.
to seek ALL solutions is now only available for boards of
15 x 15 or
Whenever an "Up" or "Down" button is clicked, the program immediately
starts seeking solutions for that new board size. Those "Up" and "Down"
effectively include a built-in "Restart" command.
Restarts a search for solutions for the
current board size.
Stops seeking solutions!
An option whether or
not to "Stop on First Solution Found".
Reduce the size of the 'board' (The minimum size is an
infeasible 1 x 1).
Increase the size of the
'board' (The maximum size is 32 x 32 squares).
Note: (A minor oddity) - The "Up" and
buttons can be clicked even while the program is
busy, but occasionally this may cause the program to lose track of what
you want and it will simply "Stop" instead! So please pause
briefly between each click on those buttons, and allow the program to
keep up with your wishes.
WqGStep2's Default Starting State
When WqGStep2 starts for the first time, it uses the following settings:
WqGStep2 can remember its position each time it is
started, it will deliberately ignore (whenever it is RE-started) any
set to less than 610 pixels or any window height set to less than 590
- The program window opens near top-left of the
- The window size is set to 610 pixels
wide by 590 pixels high.
- The Board size is set to 8 squares by 8
- The option to "Stop on First Solution
Found" is set to ON.
The Results Of Solution-Searches
The progress of the search and the results so far are shown in plain
the upper part of the program's window. Any line of text that
has nothing significant to report is coloured grey. A graphical display
of the board is shown at the bottom of the window,
and little "Queens" will appear on the board (really just asterisks)
whenever a solution is discovered.
If the User has chosen NOT to "Stop on First Solution Found", then the
Queens will be seen 'moving' progressively across the board in
one-second snapshots as the program continues to seek ALL
possible solutions. In this case, once the last solution is
discovered and counted, the Queens will remain visible on the board in
that last-solved pattern. (Note that the last-solved
pattern is always just a mirror image of the first possible solution!)
If the board size is increased to the point where it would clash with
the text lines above, then the board turns a subdued grey colour as a
warning that all Rows of the board may NOT now be visible.
This will not affect the search for solutions. The full
coloured board will re-appear if the window size is increased to
accommodate the larger board.
This version of the program has no way of saving its results
disk. I repeat that WqGStep2 is intended only to show a
all the possible data that could be gleaned during searches for
solutions to this puzzle, while using one specific search algorithm.
The mathematics library with which I compiled this program has an
internal storage limit for unsigned integers,
of 32-bits. When working on board sizes of
larger, an overflow error would occur as the program
accumulated its count of the "number of Queens placed",
because the counter would exceed the value of
which is the limit for
a 32-bit unsigned integer. To avoid this overflow, I
program so that a search for ALL solutions for a board size is
only possible for sizes 15 x 15 or smaller.
The size of the
board can still be
increased up to 32 x 32, but sizes of 16 x 16 and
larger will now
always stop on the first solution found.
is a standalone program which needs no installation.
After you've extracted it from the downloaded .ZIP file
it can be
and executed from any folder on your PC. It contains
no banners, no malware and no viruses. It has been checked
Antivirus for Windows). The
program is not capable of connecting to the Internet.
In order to
remember some User preferences, the program will try to write only to
.ini file (see Operating
System Compatibility below), but it does not modify any other
part of your PC. It does not write to your PC's Registry and
it does not read
from your PC's Registry.
Oct 2008, 04:59
in the .zip file)
Oct 2008, 03:34
|ReadMe for WqGStep_exe 2_2_0_1.txt
in the .zip file)
Oct 2008, 04:20
The ReadMe for WqGStep_exe 2_2_0_1.txt
file is a plain-text
version of the information on this
WqGStep2.exe is compiled as a WIN32s®-based
program and is compatible with all versions of
Windows 2000 and Windows XP. It
will run happily on Windows Vista and on Windows 7, but see
the following paragraphs about how WqGStep2 remembers
its settings and your User preferences.
Due to its earlier code base, this program maintains its
settings such as window
position and size, plus the last-searched board size, not in the
computer's Registry, but instead in a .ini file called
This .ini file is created (when possible) the first time the program is
it is stored in the "\Windows" folder on the PC on which
it is run. If the currently logged in User does not have
file-write permissions to
"\Windows" folder then the program will still function happily, but it
be able to remember your preferences. Windows Vista
and Windows 7 will (usually) prevent any program
writing directly to the "\Windows" folder, so in these cases
too, WqGStep2 will always start with
its programmed-default settings.
The program automatically
learns where the "\Windows" folder
is on any version of Microsoft Windows®
by using a standard Windows Application Programming Interface (API)
call to look at the PC's
Environment variable called %WINDIR%. We don't need
to tell it where to find "\Windows" on your PC.
program is not
covered by the Creative Commons Licence that
applies to all other parts of this web site. But
otherwise, WqGStep2.exe is a FREE program. You can
distributed it freely, but only in an unmodified form and provided that
it is accompanied by the notes
which are included in the ZIP file as downloaded from this site.
The C++ code is not available for distribution and I have
no plans at present for any further support or development of the
As the author of this
program I believe it to be safe and free of serious bugs. By
downloading and unzipping this program you expressly agree that you
accept it "AS IS" and that you will use it entirely at your own risk.
You further agree that you understand and accept the following
conditions for its use: I do not warrant the suitability of
this program for any purpose and I disclaim any
liability to any third party anywhere in the world
for any injury, loss or damage, direct or
indirect, or for any other loss suffered as a result
of its use or storage on your computer, to
the maximum extent permitted by law. Colin S
27th October 2008
Win32s, Windows 95, Windows 2000,
Windows XP, Windows Vista and Windows
are either registered trademarks or
trademarks of Microsoft Corporation in the United States and/or other
to return to this site's Home page.
updated on 13th November 2010 -
to update links to new OEIS site