
Program: 8queens.htm
Author: Ron Winter
The code may be Javascript, but it sure looks like `C' to me! Especially the algorithm to find the solutions. All the rest of the code is just html trickery to make things work and look reasonable! I will describe all of this (and more!) at the C meeting. Ron W.
The Eight Queens Problem
//____________________________________________________________________
var
chess_files = new Array( "a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x",
"y", "z"
),
queen_gif = "queen.gif",
blank_gif = "blank.gif",
attack_gif = "attack.gif",
show_attack = false,
image_size = 45,
square_size = 45; // limited to 24 by alphabet above
var
board_size;
if( -1 != window.location.search.indexOf( "=" ) )
{
board_size =
window.location.search.substring( location.search.indexOf( "=" ) + 1,
location.search.length );
if( board_size > 14 )
board_size = 14;
if( board_size < 1 )
board_size = 1;
}
else
board_size = 8;
if( /* ( board_size > 8 ) || */ ( board_size < 8 ) )
{
image_size = parseInt( 360 / board_size );
square_size = image_size;
}
var
number_of_columns = board_size,
number_of_rows = board_size,
squares_array = new Array( number_of_rows ),
chess_board = new Array( number_of_rows ),
number_of_queens = 0,
temp_array = new Array( number_of_rows ),
solutions_array,
current_displayed_solution = 0,
number_of_solutions = 0,
row,
col,
count,
junk;