return true; } if (isset($_POST['process']) && isset($_POST['boardX'])) { //Within here is the code that needs to be run if process is clicked. //First I need to create the different possible rows for ($x = 0; $x < $boardX; ++$x) { $row[$x] = 1 << $x; } //Now I need to create all the possible orders of rows, will be equal to [boardY]! $solcount = 0; $solutions = array(); while ($row != false) { if (checkBoard($row, $boardX)) { if (!in_array($row, $solutions)) { $solutions[] = $row; renderBoard($row, $boardX); $solutions = findRotation($row, $boardX, $solutions); ++$solcount; } } $row = pc_next_permutation($row); } echo "<br><br>    Rows/Columns: " . $boardX . "<br>    Unique Solutions: " . $solcount . "<br>    Total Solutions: " . count($solutions) . " - Note: This includes symmetrical solutions<br>"; //print_r($solutions); } //This code collects the starting parameters echo <<<_END <form name="input" action="queens.php" method="post">     Number of columns/rows <select name="boardX" /> <option value="1">One</option> <option value="2">Two</option>
print '</pre><br /><hr />Method 1: PHP Code:<br />'; print '<div style="border:1px solid black;padding:10px;height:300px;overflow:auto;">'; highlight_file(__DIR__ . '/../solve/solve8queens.php'); print '</div>'; print '<a name="2"></a>'; print '<br /><br /> <br /> <b>Method 2</b>: Find all solutions, using bitwise math for board checks, <br /> first finds the 12 fundamental solutions, then the <a href="../92/">92</a> based on rotations/reflections. <hr /> Method 2 Test run: '; $start = startTimer(); $s = solve8queens2(); $end = end_timer(); print '<br /> Time: ' . $end . ' seconds'; $sols = array(); foreach ($s as $sol) { $b = renderBoard($sol, 8); $sols[] = '<a target="_sol" href="../?b=' . urlencode($b) . '">' . $b . '</a>'; } sort($sols); print '<br /> Results: ' . sizeof($sols) . ' unique solutions found. (Click to view on chess board)<br /><pre>'; print '<div style="border:1px solid black;padding:10px;height:200px;overflow:auto;">'; foreach ($sols as $b) { print $b . '<br />'; } print '</div>'; print '</pre><br /><hr />Method 2: PHP Code:<br />'; print '<div style="border:1px solid black;padding:10px;height:300px;overflow:auto;">'; highlight_file(__DIR__ . '/../solve/solve8queens_2.php'); print '</div>'; print '<a name="3"></a> <br /> <b>Method 3</b>: Hard code!