Compare commits

..

No commits in common. "21e8f4134f8d429ef95e1f52d06495d00d9e0f55" and "ed5795a6ccb183d323c44030165aa81cd1bb15c0" have entirely different histories.

4 changed files with 15 additions and 24 deletions

View File

@ -6,9 +6,6 @@
<title>Requête incorrecte</title>
</head>
<body>
<nav class="navbar mb-4">
<h1 class="display-4 text-center m-auto">Sudoku</h1>
</nav>
<main class="container my-4">
<header>
<h1 class="mb-4">Requête incorrecte</h1>

View File

@ -48,7 +48,7 @@
}
class Grid {
function __construct($gridStr="") {
function __construct() {
$this->boxes = array();
$this->rows = array_fill(0, 9, array());
$this->columns = array_fill(0, 9, array());
@ -74,12 +74,6 @@
if ($box != $neighbour && !in_array($neighbour, $box->neighbourhood))
$box->neighbourhood[] = $neighbour;
}
if ($gridStr) {
$this->import($gridStr);
} else {
$this->generate();
}
}
function import($gridStr) {

View File

@ -1,19 +1,18 @@
<?php
require("classes.php");
global $sudokuGridSolutions;
if (!isset($sudokuGridSolutions)) $sudokuGridSolutions = array();
session_start();
$fullUrl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"];
$dirUrl = dirname($fullUrl);
$currentGrid = strip_tags($_SERVER['QUERY_STRING']);
if (preg_match("/^[1-9.]{81}$/", $currentGrid)) {
if (!array_key_exists($currentGrid, $sudokuGridSolutions)) {
$grid = new Grid($currentGrid);
$sudokuGridSolutions[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
if (!array_key_exists($currentGrid, $_SESSION)) {
$grid = new Grid();
$grid->import($currentGrid);
$_SESSION[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
}
switch($sudokuGridSolutions[$currentGrid]) {
switch($_SESSION[$currentGrid]) {
case -1:
$warning = "Cette grille contient des doublons.";
break;
@ -28,9 +27,10 @@
require("sudoku.php");
} else {
$grid = new Grid();
$grid->generate();
$gridAsString = $grid->toString();
$newGridUrl = "$dirUrl/?$gridAsString";
$sudokuGridSolutions[$gridAsString] = 1;
$_SESSION[$gridAsString] = 1;
if ($currentGrid) {
require("400.php");
} else {

View File

@ -35,12 +35,12 @@ window.onload = function() {
for (let box of row.getElementsByTagName('input')) {
let regionId = rowId - rowId % 3 + Math.floor(columnId / 3)
if (!box.disabled) {
box.onfocus = onfocus
box.oninput = oninput
box.onblur = onblur
box.onclick = onclick
box.onmouseenter = onmouseenter
box.onmouseleave = onmouseleave
box.onfocus = onfocus
box.oninput = oninput
box.onblur = onblur
box.onclick = onclick
box.onmouseenter = onmouseenter
box.onmouseleave = onmouseleave
}
box.oncontextmenu = oncontextmenu
box.rowId = rowId