fix false grids
This commit is contained in:
parent
a0af1272cf
commit
dc6146d498
17
game.php
17
game.php
@ -4,13 +4,13 @@
|
|||||||
if (preg_match("#^[1-9?]{81}$#", $gridStr)) {
|
if (preg_match("#^[1-9?]{81}$#", $gridStr)) {
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>Sudoku</title>
|
<title>Sudoku</title>
|
||||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||||
<script type="text/javascript" src="sudoku.js"></script>
|
<script src="sudoku.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
@ -19,6 +19,7 @@
|
|||||||
<form id="sudokuForm">
|
<form id="sudokuForm">
|
||||||
<div>
|
<div>
|
||||||
<table id="grid">
|
<table id="grid">
|
||||||
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
for ($row = 0; $row < 9; $row++) {
|
for ($row = 0; $row < 9; $row++) {
|
||||||
?>
|
?>
|
||||||
@ -38,25 +39,27 @@
|
|||||||
$value = $gridStr[9*$row+$column];
|
$value = $gridStr[9*$row+$column];
|
||||||
if ($value == "?") {
|
if ($value == "?") {
|
||||||
$value = "";
|
$value = "";
|
||||||
$readonly = "";
|
$disabled = "";
|
||||||
} else {
|
} else {
|
||||||
$readonly = "readonly='true'";
|
$disabled = " disabled";
|
||||||
}
|
}
|
||||||
echo " <td class='$classRegionRow $classRegionColumn'><input type='text' inputmode='numeric' minlength=0 maxlength=1 value='$value' $readonly /></td>";
|
echo " <td class='$classRegionRow $classRegionColumn'><input type='text' inputmode='numeric' minlength=0 maxlength=1 value='$value'$disabled/></td>\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div id="buttons">
|
<div id="buttons" class="buttons">
|
||||||
<?php
|
<?php
|
||||||
for($value=1; $value<=9; $value++) {
|
for($value=1; $value<=9; $value++) {
|
||||||
echo "<button type='button' onclick='showValue(this)'>$value</button>";
|
echo " <button type='button' onclick='showValue(this.textContent)'>$value</button>\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
<input id='colorPicker' type="color" value='#00008b'/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button type="reset">Tout effacer</button>
|
<button type="reset">Tout effacer</button>
|
||||||
|
@ -98,9 +98,7 @@
|
|||||||
forEach($testBox->neighbourhood as $neighbour)
|
forEach($testBox->neighbourhood as $neighbour)
|
||||||
$neighbour->searchAllowedValues();
|
$neighbour->searchAllowedValues();
|
||||||
}
|
}
|
||||||
$solutions = array();
|
if (count(iterator_to_array($this->findSolutions(false, 2, 4), true)) == 1) {
|
||||||
forEach($this->findSolutions(false, 2, 4) as $solution) $solutions[$solution] = true;
|
|
||||||
if (count($solutions) == 1) {
|
|
||||||
$nbClues -= count($testBoxes);
|
$nbClues -= count($testBoxes);
|
||||||
forEach($testBoxes as $testBox) array_unset_value($testBox, $untestedBoxes);
|
forEach($testBoxes as $testBox) array_unset_value($testBox, $untestedBoxes);
|
||||||
} else {
|
} else {
|
||||||
|
73
style.css
73
style.css
@ -1,5 +1,5 @@
|
|||||||
* {
|
body {
|
||||||
font-family: sans;
|
font-family: sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@ -9,61 +9,67 @@ h1 {
|
|||||||
div {
|
div {
|
||||||
display: flex;
|
display: flex;
|
||||||
column-gap: 0.5em;
|
column-gap: 0.5em;
|
||||||
row-gap: 0.5em;
|
|
||||||
margin: 1em auto;
|
margin: 1em auto;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid {
|
table {
|
||||||
border-spacing: 0;
|
border-spacing: 0;
|
||||||
border-radius: 6px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
td {
|
td, tr {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr:first-child td:first-child
|
table tr:first-child td:first-child {
|
||||||
{
|
|
||||||
border-top-left-radius: 6px;
|
border-top-left-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr:first-child td
|
table tr:first-child td:first-child > input {
|
||||||
{
|
border-top-left-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:first-child td {
|
||||||
border-top: 2px solid black;
|
border-top: 2px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr:first-child td:last-child
|
table tr:first-child td:last-child {
|
||||||
{
|
|
||||||
border-top-right-radius: 6px;
|
border-top-right-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr td:first-child
|
table tr:first-child td:last-child > input {
|
||||||
{
|
border-top-right-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr td:first-child {
|
||||||
border-left: 2px solid black;
|
border-left: 2px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr td:last-child
|
table tr td:last-child {
|
||||||
{
|
|
||||||
border-right: 2px solid black;
|
border-right: 2px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr:last-child td:first-child
|
table tr:last-child td:first-child {
|
||||||
{
|
|
||||||
border-bottom-left-radius: 6px;
|
border-bottom-left-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr:last-child td
|
table tr:last-child td:first-child > input {
|
||||||
{
|
border-bottom-left-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:last-child td {
|
||||||
border-bottom: 2px solid black;
|
border-bottom: 2px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
#grid tr:last-child td:last-child
|
table tr:last-child td:last-child {
|
||||||
{
|
|
||||||
border-bottom-right-radius: 6px;
|
border-bottom-right-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table tr:last-child td:last-child > input {
|
||||||
|
border-bottom-right-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.regionTop {
|
.regionTop {
|
||||||
border-top: 1px solid black;
|
border-top: 1px solid black;
|
||||||
}
|
}
|
||||||
@ -100,36 +106,39 @@ input {
|
|||||||
transition: 0.3s;
|
transition: 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:read-write {
|
input:enabled {
|
||||||
color: darkblue;
|
color: darkblue;
|
||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
input:read-only {
|
input:disabled {
|
||||||
color: black;
|
color: white;
|
||||||
background: #6666ff;
|
background: #6666ff;
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input.same-value:read-write {
|
.same-value:enabled {
|
||||||
color: #009973;
|
color: #009973;
|
||||||
background: #66ffd9;
|
background: #66ffd9;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.forbidden-value:read-write {
|
.forbidden-value:enabled {
|
||||||
background: #ccffe6;
|
background: #b3ffda;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.same-value:read-only {
|
.same-value:disabled {
|
||||||
color: #00664d;
|
color: white;
|
||||||
background: #00e6ac;
|
background: #00e6ac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.forbidden-value:disabled {
|
||||||
|
background: #6288ea;
|
||||||
|
}
|
||||||
|
|
||||||
input::placeholder {
|
input::placeholder {
|
||||||
color: #888;
|
color: #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
#buttons {
|
.buttons {
|
||||||
column-gap: 0.2em;
|
column-gap: 0.2em;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
10
sudoku.js
10
sudoku.js
@ -13,7 +13,7 @@ window.onload = function() {
|
|||||||
let columnId = 0
|
let columnId = 0
|
||||||
for (box of row.getElementsByTagName('input')) {
|
for (box of row.getElementsByTagName('input')) {
|
||||||
let regionId = rowId - rowId%3 + Math.floor(columnId/3)
|
let regionId = rowId - rowId%3 + Math.floor(columnId/3)
|
||||||
if (!box.readOnly) box.select
|
if (!box.readOnly) box.onfocus = box.select
|
||||||
box.oninput = oninput
|
box.oninput = oninput
|
||||||
box.oninvalid = oninvalid
|
box.oninvalid = oninvalid
|
||||||
box.onkeydown = keyboardBrowse
|
box.onkeydown = keyboardBrowse
|
||||||
@ -63,6 +63,8 @@ function showAllowedValuesOn(box) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function oninput() {
|
function oninput() {
|
||||||
|
this.style.color = colorPicker.value
|
||||||
|
|
||||||
this.neighbourhood.concat([this]).forEach(box => {
|
this.neighbourhood.concat([this]).forEach(box => {
|
||||||
box.setCustomValidity("")
|
box.setCustomValidity("")
|
||||||
searchAllowedValuesOf(box)
|
searchAllowedValuesOf(box)
|
||||||
@ -148,11 +150,11 @@ function moveOn(area, position, direction) {
|
|||||||
area[position].focus()
|
area[position].focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
function showValue(button) {
|
function showValue(value) {
|
||||||
if (button.textContent == highlightedValue) {
|
if (value == highlightedValue) {
|
||||||
highlightedValue = ""
|
highlightedValue = ""
|
||||||
} else {
|
} else {
|
||||||
highlightedValue = button.textContent
|
highlightedValue = value
|
||||||
}
|
}
|
||||||
refreshShowValue()
|
refreshShowValue()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user