Example #1
0
  jQuery.ajax({
    url: "status/",
    data: "b="+b,
    error: function(xhr) { alert("ERROR: status:" +xhr.status+' '+xhr.statusText); },
    success: function(result) { jQuery("#status").html(result); }
  });
};

var cfg = {
 draggable: true,
 dropOffBoard: 'trash',
 sparePieces: true,
<?php 
if (isset($_GET['solve'])) {
    include_once __DIR__ . '/../solve/solve8queens.php';
    print ' position: ' . solve8queens() . ",\n";
} elseif (isset($_GET['b'])) {
    print ' position: ' . $this->webDisplay($this->request->query->get('b')) . ",\n";
}
?>
 onChange: onChange,
};
var board1 = new ChessBoard('board1', cfg);

<?php 
if (isset($_GET['b'])) {
    print 'onChange( board1.position(), board1.position() );';
}
if (isset($_GET['solve'])) {
    print "jQuery('#status').html('<ul>" . "<li><span style=\"color:green;\"><b>RANDOM SOLUTION FOUND!</b></span></li>" . "<li>8 Queens on board</li>" . "<li>0 Queens under attack<li>" . "</ul>');";
}
Example #2
0
<li><a href="#2">Method 2 - Bitwise math, 12 fundamentals + rotation/reflection</a>
<li><a href="#3">Method 3 - Hard code!</a>

<p><hr/></p>

<a name="1"></a>
<br /> <b>Method 1</b>: Be lazy and use brute force.
<br /> Constrain the starting board positions to only those with 1 queen per each row and column.
<br /> Slow but workable for 8x8 boards.
<?php 
$s = array();
$n = 3;
print '<hr /> Method 1 Test run: ' . $n . ' runs, each run testing up to 1000 permutations.';
$start = startTimer();
for ($i = 0; $i < $n; $i++) {
    $solution = solve8queens();
    if ($solution) {
        $s[] = $solution;
    }
}
$end = end_timer();
$s = array_unique($s);
sort($s);
print '<br /> Time: ' . $end . ' seconds';
print '<br /> Results: ' . sizeof($s) . ' unique solutions found. (Click to view on chess board)<br /><pre>';
print '<div style="border:1px solid black;padding:10px;height:70px;overflow:auto;">';
foreach ($s as $sol) {
    print '<a target="_sol" href="../?b=' . urlencode($sol) . '">' . $sol . '</a><br />';
}
print '</div>';
print '</pre><br /><hr />Method 1: PHP Code:<br />';