helper.js 

/**
 * Author Malte Pagel
 * Free to use for any purpose
 * Runability or usefulness is NOT guaranteed
 */


document.write("<sty" "le type='text/css'>");
document.write(".table_cell {width: 40px;height: 40px;text-align: center;color: #FF8000;}.table_cell.empty {background-color: #EEEEEE;}.table_cell.full_dark {background-color: #282828;}.table_cell.full_light {background-color: #A5A5A5;}.table_cell.grey, .table_cell.empty.grey {color: gray;font-size: 18px;}");
document.write("</style>");

function 
personal_debug (message) {
    
console.log(message);
    
//iD("instruction").innerHTML = message;
}

document.write("<center><span id='instruction'>Klicken Sie auf ein Feld, auf dem der Springer beginnen soll</span><br><br></center>");
                
var 
upper_array = [ 'A''B''C''D''E''F''G''H',
                    
'I''J''K''L''M''N''O''P'];
var 
table_cols 8;

document.write("<center><table border='1' rules='none' style='color: #FF8000; font-size: 24px; border: thin ridge #F2F2F2'>");

for ( var 
table_count 0table_count table_colstable_count++ ) {
    
document.write("<tr>");
    
document.write("<td class='table_cell' style='padding-right: 8px; color: silver; background-color: #F6F6F6'>" + (table_cols table_count) + "</td>");
    for ( var 
inner_count 0inner_count table_colsinner_count ++ ) {
        
document.write("<td id='cell_" upper_array[inner_count] + (table_cols table_count) + "' class='table_cell");
        if ( (
table_count inner_count) % != )
            
document.write(" empty");
        
document.write("' style='cursor: pointer' onclick='set_start(" inner_count ", " + (table_cols table_count 1) + ")'>");
        
document.write("</td>");
    }
    
document.write("</tr>");
}
document.write("<tr><td class='table_cell' style='padding-right: 8px; background-color: #F6F6F6'></td>");
for ( 
table_count 0table_count table_colstable_count++ ) {
    
document.write("<td class='table_cell' style='padding-top: 8px; color: silver; background-color: #F6F6F6'>");
    
document.write(upper_array[table_count]);
    
document.write("</td>");
}
document.write("</tr>");
document.write("</table></center>");
 

 example.js 

//
//  KnightPosition: example.js
//
//  Created 2013/11 by Malte Pagel
//  Copyright (c) 2013 Malte Pagel. All rights reserved.
//


var letters = [ 'A''B''C''D''E''F''G''H''I''J''K''L''M''N''O''P' ];
var 
column = -1;
var 
row = -1;
var 
cols 8;
var 
start_position null;

var 
knight_count 0;
var 
knight_number 0;
var 
memory_count 0;
var 
x_move = [ 1221, -1, -2, -2, -11221, -1, -];
var 
y_move = [ -2, -11221, -1, -2, -2, -1122];
var 
reachable_positions_offset 0;
var 
reachable_positions_offset_set 0;

var 
MEMORY_LIMIT 4096;

function 
show_cell_content (colrowcontent) {
    if ( 
content )
        
iD("cell_" letters[col] + (row 1)).innerHTML content;
    else
        
iD("cell_" letters[col] + (row 1)).innerHTML "";
}

/**
 * Pseudoclass
 */
function KnightPosition (columnrownum_colscollection) {
    
    
/**
     * Public Variables
     */
    //this.column, this.row, this.has_knight, this.center_distance;
    //this.next_position;
    
    /**
     * Private Variables
     */
    
var lower_or_equal;
    var 
previous_position;
    var 
first_collected_positionlast_collected_positionfirst_position_to_trylast_position_to_try;
    var 
myself this;
    
    
    
/**
     * Public Functions
     */
    
this.set_knight_and_start_search = function (last_position) {
        
knight_number++;
        
this.has_knight 1;
        
previous_position last_position;
        
        
show_cell_content(this.columnthis.rowknight_number);
        
        
last_position_to_try null;
        
first_position_to_try null;
        
        
order_reachable_positions();
        
        if ( !
first_position_to_try ) {
            
go_back();
            return;
        }
        
        
do_search();
    };
    
    
this.get_num_possibilities = function () {
        var 
possibilities 0;

        if ( !
first_collected_position )
            return 
0;
        
        
tmp_position first_collected_position;
        while ( 
tmp_position ) {
            if ( !
tmp_position.possible_position.has_knight )
                
possibilities++;
            
tmp_position tmp_position.basic_next;
        }

        return 
possibilities;
    };
    
    
this.another_try_from_above = function () {
        
myself.next_position.next_position null;
        
        if ( !
first_position_to_try ) {
            
show_cell_content(myself.columnmyself.row0);
            
go_back();
            return;
        }
        
        if ( 
memory_count MEMORY_LIMIT || (memory_count && knight_number == 1) ) {
            if ( 
knight_number == )
                
personal_debug"Does not seem to be solvable" );
            else
                
personal_debug"Too much recursion, I'm giving up; knights: " knight_number " / " + (cols cols) );
            return;
        }
        
        
personal_debug"I am at " letters[myself.column] + (myself.row 1) + " (try " memory_count "); "
            
letters[myself.next_position.column] + (myself.next_position.row 1) + " was bad; trying "
            
letters[first_position_to_try.possible_position.column]
            + (
first_position_to_try.possible_position.row 1) );
        
        
do_search();
    };
    
    
    
/**
     * Private Functions
     */
    
function do_search () {
        var 
position_to_try first_position_to_try;
        
        
myself.next_position position_to_try.possible_position;
        
        
first_position_to_try = (first_position_to_try.next) ? first_position_to_try.next null;
        
        if ( 
knight_number >= (cols cols 1) ) {
            
make_grey();
            
show_cell_content(myself.next_position.columnmyself.next_position.row, (cols cols));
            if ( 
memory_count )
                
personal_debug"\t* SOLVED *" );
            
show_solution(start_position);
            return;
        }
        
        
myself.next_position.set_knight_and_start_search(myself);
    }
    
    function 
order_reachable_positions () {
        var 
possibilitiessuccess;
        
        var 
tmp_position_to_addtmp_tmp_positiontmp_tmp_tmp_position;
        
        var 
tmp_position first_collected_position;
        
        while ( 
tmp_position != null ) {
            
            
possibilities tmp_position.possible_position.get_num_possibilities();
            
            if ( !
tmp_position.possible_position.has_knight ) {

                if ( !
possibilities )
                    
possibilities cols 8;

                
tmp_position_to_add tmp_position;
                
tmp_position_to_add.heuristic = (cols possibilities tmp_position.possible_position.center_distance);
                
tmp_position_to_add.next null;

                if ( !
first_position_to_try ) {
                    
first_position_to_try tmp_position_to_add;
                    
last_position_to_try first_position_to_try;
                }
                else {
                    
tmp_tmp_position first_position_to_try;
                    
success 0;
                    while ( 
tmp_tmp_position && !success ) {
                        if ( 
tmp_position_to_add.heuristic tmp_tmp_position.heuristic || (lower_or_equal && tmp_position_to_add.heuristic == tmp_tmp_position.heuristic) ) {
                            if ( 
tmp_tmp_position == first_position_to_try ) {
                                
tmp_position_to_add.next tmp_tmp_position;
                                
first_position_to_try tmp_position_to_add;
                                
success 1;
                            }
                            else {
                                
tmp_tmp_tmp_position first_position_to_try;
                                while ( 
tmp_tmp_tmp_position.next != tmp_tmp_position )
                                    
tmp_tmp_tmp_position tmp_tmp_tmp_position.next;
                                
tmp_position_to_add.next tmp_tmp_tmp_position.next;
                                
tmp_tmp_tmp_position.next tmp_position_to_add;
                                
success 1;
                            }
                        }
                        
tmp_tmp_position tmp_tmp_position.next;
                    }
                    if ( !
success ) {
                        
last_position_to_try.next tmp_position_to_add;
                        
last_position_to_try tmp_position_to_add;
                    }
                }
            }
            
            
tmp_position tmp_position.basic_next;
        }
    }
    
    function 
go_back () {
        
memory_count++;
        
knight_number--;
        
myself.has_knight 0;
        
        
setTimeout(previous_position.another_try_from_above21);
    }
    
    function 
add_to_reachable_positions (position) {
        var 
position_data = {};
        
        
position_data.possible_position position;
        
position_data.heuristic 0;
        
position_data.next null;
        
position_data.basic_next null;
        
        if ( !
first_collected_position ) {
            
first_collected_position position_data;
            
last_collected_position first_collected_position;
        }
        else {
            
last_collected_position.basic_next position_data;
            
last_collected_position position_data;
        }
    }
    
    function 
fill_reachable_positions () {
        var 
ixy;
        var 
tmp_position null;
        
        for ( 
reachable_positions_offset< (reachable_positions_offset); i++ ) {
            
column x_move[i];
            
row y_move[i];
            
            if ( 
|| > (cols 1) || || > (cols 1) )
                continue;
            if ( !
collection[x][y] ) {
                
tmp_position = new KnightPosition(xycolscollection);
                
add_to_reachable_positions(tmp_position);
            }
            else
                
add_to_reachable_positions(collection[x][y]);
        }
    }
    
    
    
/**
     * Constructor
     */
    
collection[column][row] = this;
    
    
this.column column;
    
this.row row;
    
this.has_knight 0;
    
    
this.next_position null;
    
previous_position null;
    
    
first_collected_position null;
    
last_collected_position null;
    
    
this.center_distance Math.abs((cols 1) - (column) - (row));
    
    if ( !
reachable_positions_offset_set ) {
        if ( 
column ) {
            if ( 
row )
                
reachable_positions_offset 4;
            else
                
reachable_positions_offset 6;
        }
        else
            if ( 
row )
                
reachable_positions_offset 2;
        
reachable_positions_offset_set 1;
    }
    
    
fill_reachable_positions();
    
    
knight_count++;
    
    
lower_or_equal = ( Math.floor(Math.random() * (cols cols this.center_distance knight_count)) == ) ? 0;
    
    
//personal_debug( "KnightPosition number " + knight_count + " constructed at " + letters[column] + (row + 1) );
}

/*  */

function make_grey () {
    for ( var 
0colsi++ )
        for ( var 
0colsj++ ) {
            
iD("cell_" letters[i] + (1)).style.cursor "help";
            
iD("cell_" letters[i] + (1)).className = ((j) % != 0) ? "table_cell grey" "table_cell empty grey";
        }
}

function 
show_solution (position) {
    var 
position.column;
    var 
position.row;
    
    
iD("cell_" letters[c] + (1)).className = ((r) % != 0) ? "table_cell full_light" "table_cell full_dark";
    
    if ( 
position.next_position )
        
setTimeout(show_solution333position.next_position);
    else {
        
personal_debug"\t************" );
        
personal_debug"\t* FINISHED *" );
        
personal_debug"\t************" );
        
        for ( var 
0colsi++ )
            for ( var 
0colsj++ )
                
iD("cell_" letters[i] + (1)).style.cursor "default";
    }
}

function 
quasi_main () {
    var 
ij;
    
    var 
complete_collection = [];
    for ( 
0colsi++ ) {
        
complete_collection[i] = [];
        for ( 
0colsj++ )
            
complete_collection[i][j] = null;
    }
    
    
start_position = new KnightPosition(columnrowcolscomplete_collection);
    
    
complete_collection null;
    
    
start_position.set_knight_and_start_search(null);
}

function 
set_start (cr) {
    if ( 
column >= )
        return;
    
    
column c;
    
row r;
    
    for ( var 
0colsi++ )
        for ( var 
0colsj++ )
            
iD("cell_" letters[i] + (1)).style.cursor "wait";
    
    
iD("instruction").innerHTML "";
    
    
quasi_main();
}

//set_start(Math.floor(Math.random() * cols), Math.floor(Math.random() * cols));