Compare commits
11 Commits
ed5795a6cc
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c477355fe9 | |||
| f52c970bef | |||
| cf0a5a465e | |||
| 310a1883d2 | |||
| 4b92464c94 | |||
| c09ed80a52 | |||
| b145ae566a | |||
| 21e8f4134f | |||
| 31a40a7e93 | |||
| ad3992ac30 | |||
| 5feaa65955 |
5
400.php
Normal file → Executable file
5
400.php
Normal file → Executable file
@ -6,6 +6,9 @@
|
||||
<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>
|
||||
@ -15,7 +18,7 @@
|
||||
<em>grille</em> étant une suite de 81 caractères représentant la grille de gauche à droite puis de haut en bas, soit :
|
||||
<ul>
|
||||
<li>un chiffre entre 1 et 9 pour les cases connues</li>
|
||||
<li>un point pour les case vides</li>
|
||||
<li>un tiret (-) pour les case vides</li>
|
||||
</ul>
|
||||
Exemple :<br/>
|
||||
<a href='<?=$newGridUrl?>'><?=$newGridUrl?></a>
|
||||
|
||||
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Sudoku
|
||||
|
||||
Web sudoku assistant
|
||||
|
||||

|
||||
29
classes.php
Normal file → Executable file
29
classes.php
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
const UNKNOWN = ".";
|
||||
const UNKNOWN = "-";
|
||||
|
||||
$validGrids = array();
|
||||
|
||||
@ -27,15 +27,19 @@
|
||||
|
||||
class Box {
|
||||
public $values = array('1', '2', '3', '4', '5', '6', '7', '8', '9');
|
||||
|
||||
public $value = UNKNOWN;
|
||||
public $rowId;
|
||||
public $columnId;
|
||||
public $regionId;
|
||||
public $candidates;
|
||||
public $candidateRemoved = array();
|
||||
public $neighbourhood = array();
|
||||
|
||||
function __construct($rowId, $columnId, $regionId) {
|
||||
$this->value = UNKNOWN;
|
||||
$this->rowId = $rowId;
|
||||
$this->columnId = $columnId;
|
||||
$this->regionId = $regionId;
|
||||
$this->candidates = $this->values;
|
||||
$this->candidateRemoved = array();
|
||||
$this->neighbourhood = array();
|
||||
}
|
||||
|
||||
function searchCandidates() {
|
||||
@ -48,8 +52,13 @@
|
||||
}
|
||||
|
||||
class Grid {
|
||||
function __construct() {
|
||||
$this->boxes = array();
|
||||
|
||||
private $boxes = array();
|
||||
private $rows;
|
||||
private $columns;
|
||||
private $regions;
|
||||
|
||||
function __construct($gridStr="") {
|
||||
$this->rows = array_fill(0, 9, array());
|
||||
$this->columns = array_fill(0, 9, array());
|
||||
$this->regions = array_fill(0, 9, array());
|
||||
@ -74,6 +83,12 @@
|
||||
if ($box != $neighbour && !in_array($neighbour, $box->neighbourhood))
|
||||
$box->neighbourhood[] = $neighbour;
|
||||
}
|
||||
|
||||
if ($gridStr) {
|
||||
$this->import($gridStr);
|
||||
} else {
|
||||
$this->generate();
|
||||
}
|
||||
}
|
||||
|
||||
function import($gridStr) {
|
||||
|
||||
0
favicon.png
Normal file → Executable file
0
favicon.png
Normal file → Executable file
|
Before Width: | Height: | Size: 542 B After Width: | Height: | Size: 542 B |
22
head.php
Normal file → Executable file
22
head.php
Normal file → Executable file
@ -1,5 +1,15 @@
|
||||
<meta charset="utf-8" />
|
||||
<title>Sudoku</title>
|
||||
<title>Sudoku</title><meta property="og:title" content="Sudoku" />
|
||||
<meta property="og:type" content="game" />
|
||||
<meta name="description" property="og:description" content="Remplissez la grille de sorte que chaque ligne, colonne et région (carré de 3×3 cases) contienne tous les chiffres de 1 à 9." />
|
||||
<link rel="canonical" href="<?=$_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].dirname($_SERVER["DOCUMENT_URI"])?>" />
|
||||
<meta property="og:url" content="<?=$_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"]?>" />
|
||||
<meta property="og:image" content="<?=$_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].dirname($_SERVER["DOCUMENT_URI"])?>/thumbnail.php?size=200&grid=<?=$currentGrid?>" />
|
||||
<meta property="og:image:width" content="200" />
|
||||
<meta property="og:image:height" content="200" />
|
||||
<meta name="Language" CONTENT="fr" /><meta property="og:locale" content="fr_FR" />
|
||||
<meta property="og:site_name" content="<?=$_SERVER["HTTP_HOST"]?>" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-dark.min.css" rel="stylesheet">
|
||||
@ -20,13 +30,3 @@
|
||||
<link href="thumbnail.php?grid=<?=$currentGrid?>&size=60" sizes="60x60" rel="apple-touch-icon">
|
||||
<link href="thumbnail.php?grid=<?=$currentGrid?>&size=76" sizes="76x76" rel="apple-touch-icon">
|
||||
<link href="manifest.php?grid=<?=$currentGrid?>" rel="manifest">
|
||||
|
||||
<meta property="og:title" content="Sudoku" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="<?=$_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].$_SERVER["DOCUMENT_URI"]?>" />
|
||||
<meta property="og:image" content="<?=$_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].dirname($_SERVER["DOCUMENT_URI"])?>/thumbnail.php?size=200&grid=<?=$currentGrid?>" />
|
||||
<meta property="og:image:width" content="200" />
|
||||
<meta property="og:image:height" content="200" />
|
||||
<meta property="og:description" content="Remplissez la grille de sorte que chaque ligne, colonne et région (carré de 3×3 cases) contienne tous les chiffres de 1 à 9." />
|
||||
<meta property="og:locale" content="fr_FR" />
|
||||
<meta property="og:site_name" content="<?=$_SERVER["HTTP_HOST"]?>" />
|
||||
|
||||
29
index.php
Normal file → Executable file
29
index.php
Normal file → Executable file
@ -1,18 +1,19 @@
|
||||
<?php
|
||||
require("classes.php");
|
||||
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, $_SESSION)) {
|
||||
$grid = new Grid();
|
||||
$grid->import($currentGrid);
|
||||
$_SESSION[$currentGrid] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
|
||||
if (preg_match("/^[1-9-]{81}$/", $currentGrid)) {
|
||||
session_id($currentGrid);
|
||||
session_start(["use_cookies" => false]);
|
||||
|
||||
if (!array_key_exists("nbSolutions", $_SESSION)) {
|
||||
$grid = new Grid($currentGrid);
|
||||
$_SESSION["nbSolutions"] = $grid->containsDuplicates() ? -1 : $grid->countSolutions(2);
|
||||
}
|
||||
switch($_SESSION[$currentGrid]) {
|
||||
switch($_SESSION["nbSolutions"]) {
|
||||
case -1:
|
||||
$warning = "Cette grille contient des doublons.";
|
||||
break;
|
||||
@ -26,14 +27,18 @@
|
||||
}
|
||||
require("sudoku.php");
|
||||
} else {
|
||||
$grid = new Grid();
|
||||
$grid->generate();
|
||||
$gridAsString = $grid->toString();
|
||||
$newGridUrl = "$dirUrl/?$gridAsString";
|
||||
$_SESSION[$gridAsString] = 1;
|
||||
if ($currentGrid) {
|
||||
require("400.php");
|
||||
} else {
|
||||
$grid = new Grid();
|
||||
$gridAsString = $grid->toString();
|
||||
$newGridUrl = "$dirUrl/?$gridAsString";
|
||||
|
||||
session_id($gridAsString);
|
||||
session_start(["use_cookies" => false]);
|
||||
|
||||
$_SESSION["nbSolutions"] = 1;
|
||||
|
||||
header("Location: $newGridUrl");
|
||||
}
|
||||
}
|
||||
|
||||
0
manifest.php
Normal file → Executable file
0
manifest.php
Normal file → Executable file
0
service-worker.js
Normal file → Executable file
0
service-worker.js
Normal file → Executable file
6
style.css
Normal file → Executable file
6
style.css
Normal file → Executable file
@ -20,7 +20,7 @@ table input {
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
text-align: center;
|
||||
-moz-appearance: textfield !important;
|
||||
appearance: textfield !important;
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
|
||||
@ -33,6 +33,10 @@ table input:not([disabled]) {
|
||||
color: inherit !important;
|
||||
}
|
||||
|
||||
table input:not([disabled]):hover {
|
||||
background: #9fb9b945 !important;
|
||||
}
|
||||
|
||||
table input:disabled {
|
||||
background-position: center !important;
|
||||
}
|
||||
|
||||
16
sudoku.js
16
sudoku.js
@ -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
|
||||
@ -82,10 +82,6 @@ window.onload = function() {
|
||||
}
|
||||
|
||||
loadGame(history.state)
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.register(`service-worker.js`)
|
||||
}
|
||||
}
|
||||
|
||||
window.onpopstate = (event) => loadGame(event.state)
|
||||
|
||||
65
sudoku.php
65
sudoku.php
@ -36,54 +36,44 @@
|
||||
<form id='sudokuForm' class='needs-validation' novalidate>
|
||||
<table id='grid' class='table mb-2'>
|
||||
<tbody>
|
||||
<?php
|
||||
for ($row = 0; $row < 81; $row += 9) {
|
||||
?>
|
||||
<?php for ($row = 0; $row < 81; $row += 9): ?>
|
||||
<tr class="input-group d-inline-block w-auto">
|
||||
<?php
|
||||
for ($column = 0; $column < 9; $column++) {
|
||||
$value = $currentGrid[$row+$column];
|
||||
if ($value == UNKNOWN) {
|
||||
?>
|
||||
<?php for ($column = 0; $column < 9; $column++): $value = $currentGrid[$row+$column]; ?>
|
||||
<?php if ($value == UNKNOWN): ?>
|
||||
<td><input type='number' min='1' max='9' step='1' value='' class='form-control' /></td>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<?php else: ?>
|
||||
<td><input type='number' min='1' max='9' step='1' value='<?=$value?>' class='form-control' disabled /></td>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<div class='d-flex mb-4'>
|
||||
<div id='insertRadioGroup' class='radioGroup btn-group flex-fill'>
|
||||
<input type='radio' class='btn-check' id='insertRadio0' value='' name='insertRadioGroup' onclick='insert(this)' accesskey='0' checked /><label for='insertRadio0' class='btn btn-primary' title='Clavier'><i class="ri-input-cursor-move"></i></label>
|
||||
<?php
|
||||
for($value=1; $value<=9; $value++) {
|
||||
echo " <input type='radio' class='btn-check' id='insertRadio$value' value='$value' name='insertRadioGroup' onclick='insert(this)' accesskey='$value' disabled /><label for='insertRadio$value' class='btn btn-primary' title='Insérer un $value'>$value</label>\n";
|
||||
}
|
||||
?>
|
||||
<?php endif ?>
|
||||
<?php endfor?>
|
||||
</tr>
|
||||
<?php endfor?>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<div class='d-flex mb-4'>
|
||||
<div id='insertRadioGroup' class='radioGroup btn-group flex-fill'>
|
||||
<input type='radio' class='btn-check' id='insertRadio0' value='' name='insertRadioGroup' onclick='insert(this)' accesskey='0' checked /><label for='insertRadio0' class='btn btn-primary' title='Clavier'><i class="ri-input-cursor-move"></i></label>
|
||||
<?php for($value=1; $value<=9; $value++): ?>
|
||||
<input type='radio' class='btn-check' id='insertRadio<?=$value?>' value='<?=$value?>' name='insertRadioGroup' onclick='insert(this)' accesskey='<?=$value?>' disabled />
|
||||
<label for='insertRadio<?=$value?>' class='btn btn-primary' title='Insérer un <?=$value?>'><?=$value?></label>
|
||||
<?php endfor ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class='mb-3'>
|
||||
<?php if (isset($warning)): ?>
|
||||
<strong>⚠️ <?=$warning?> ⚠️</strong><br/>
|
||||
<?php else: ?>
|
||||
Remplissez la grille de sorte que chaque ligne, colonne et région (carré de 3×3 cases) contienne tous les chiffres de 1 à 9.
|
||||
<?php endif?>
|
||||
</div>
|
||||
</div>
|
||||
<div class='mb-3'><?php
|
||||
if (isset($warning))
|
||||
echo("<strong>⚠️ $warning ⚠️</strong><br/>");
|
||||
else
|
||||
echo("Remplissez la grille de sorte que chaque ligne, colonne et région (carré de 3×3 cases) contienne tous les chiffres de 1 à 9.")
|
||||
?></div>
|
||||
</main>
|
||||
<aside class="col-md-3 text-center text-md-start">
|
||||
<div class="d-flex flex-column flex-shrink-0 p-3">
|
||||
<ul class="nav nav-pills flex-column">
|
||||
<li><a href="." class="nav-link link-body-emphasis">Nouvelle grille</a></li>
|
||||
<li><a href="" class="nav-link link-body-emphasis">Lien vers cette grille</a></li>
|
||||
<li><a href="?................................................................................." class="nav-link link-body-emphasis">Grille vierge</a></li>
|
||||
<li><a href="?---------------------------------------------------------------------------------" class="nav-link link-body-emphasis">Grille vierge</a></li>
|
||||
<li><a id="fixGridLink" href="" class="nav-link link-body-emphasis">Figer la grille</a></li>
|
||||
<li><a href="https://git.malingrey.fr/adrien/Sudoku" class="nav-link link-body-emphasis">Code source</a></li>
|
||||
<li><a href=".." class="nav-link link-body-emphasis">Autres jeux</a></li>
|
||||
@ -94,6 +84,7 @@
|
||||
<ul id='contextMenu' class='context-menu modal-content shadow list-group w-auto position-absolute'></ul>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
|
||||
<script src='sudoku.js' defer></script>
|
||||
<script>navigator?.serviceWorker.register('service-worker.js')</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
4
thumbnail.php
Normal file → Executable file
4
thumbnail.php
Normal file → Executable file
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
require("classes.php");
|
||||
if (isset($_GET["grid"]) && preg_match("/^[1-9.]{81}$/", $_GET["grid"]))
|
||||
if (isset($_GET["grid"]) && preg_match("/^[1-9-]{81}$/", $_GET["grid"]))
|
||||
$currentGrid = $_GET["grid"];
|
||||
else
|
||||
$currentGrid = ".528.3....4.9.1...39.562......73.129...1.64.7...42.3656.13.5...28.6.4...4.5287...";
|
||||
$currentGrid = "-528-3----4-9-1---39-562------73-129---1-64-7---42-3656-13-5---28-6-4---4-5287---";
|
||||
header ("Content-type: image/png");
|
||||
if (isset($_GET['size']))
|
||||
$size = (int) $_GET['size'];
|
||||
|
||||
0
thumbnail.png
Normal file → Executable file
0
thumbnail.png
Normal file → Executable file
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user