diff --git a/classes.php b/classes.php index 3d3fc6a..0e7e4cb 100644 --- a/classes.php +++ b/classes.php @@ -83,20 +83,6 @@ array_unset_value($box->value, $neighbour->candidates); } } - - function containsDuplicates() { - foreach(array_merge($this->rows, $this->columns, $this->regions) as $area) { - $knownBoxes = array_filter($area, "isKnown"); - foreach($knownBoxes as $box1) { - foreach($knownBoxes as $box2) { - if (($box1 != $box2) && ($box1->value == $box2->value)) { - return true; - } - } - } - } - return false; - } function generate() { // Init with a shuffle row @@ -139,10 +125,22 @@ } } } + + function containsDuplicates() { + foreach(array_merge($this->rows, $this->columns, $this->regions) as $area) { + $knownBoxes = array_filter($area, "isKnown"); + foreach($knownBoxes as $box1) { + foreach($knownBoxes as $box2) { + if (($box1 != $box2) && ($box1->value == $box2->value)) { + return true; + } + } + } + } + return false; + } function countSolutions($max=2) { - if ($this->containsDuplicates()) - return 0; $solutions = $this->solutionsGenerator(false); $solutionsWithoutDuplicates = array(); $nbSolutions = 0; diff --git a/style.css b/style.css index 54deeb0..91fd283 100644 --- a/style.css +++ b/style.css @@ -112,16 +112,16 @@ input[type="number"]::-webkit-calendar-picker-indicator { .grid input:disabled { color: white; background: #6666ff; -} -.grid input:disabled, -.grid input.forbidden { cursor: not-allowed !important; } +.grid input:disabled, .grid input.forbidden:enabled { background: #ffffaa; + cursor: not-allowed !important; } .grid input.same-value:enabled { background: #ffff33; + cursor: not-allowed !important; } .grid input.forbidden:disabled { color: #ffffaa; diff --git a/sudoku.js b/sudoku.js index 51f11b0..6d096ca 100644 --- a/sudoku.js +++ b/sudoku.js @@ -114,9 +114,8 @@ function onclick() { if (this.value == "" && this.candidates.size == 1) { valueToInsert = this.candidates.values().next().value document.getElementById("insertRadio" + valueToInsert).checked = true - this.value = valueToInsert - this.oninput() - } else if (inkPenRadio.checked) { + } + if (inkPenRadio.checked) { if (valueToInsert) { this.value = valueToInsert this.oninput() @@ -216,41 +215,26 @@ function refreshUI() { } function highlight() { - if (valueToInsert) { - if (highlighterCheckbox.checked) { - boxes.forEach(box => { - if (box.value == valueToInsert) { - box.classList.add("same-value") - box.tabIndex = -1 - } - else { - box.classList.remove("same-value") - if (box.candidates.has(valueToInsert) && !box.disabled) { - box.classList.remove("forbidden") - box.tabIndex = 0 - } else { - box.classList.add("forbidden") - box.tabIndex = -1 - } - } - }) + boxes.forEach(box => { + if (valueToInsert && box.value == valueToInsert) { + box.classList.add("same-value") + box.tabIndex = -1 } else { - boxes.forEach(box => { - box.classList.remove("same-value") - if (box.disabled) { + box.classList.remove("same-value") + if (box.disabled) { + box.classList.add("forbidden") + } else { + if (valueToInsert && highlighterCheckbox.checked && !box.candidates.has(valueToInsert)) { box.classList.add("forbidden") + box.tabIndex = -1 } else { box.classList.remove("forbidden") + box.tabIndex = 0 } - box.tabIndex = 0 - }) + } } - } else { - boxes.forEach(box => { - box.classList.remove("same-value", "forbidden") - box.tabIndex = 0 - }) - } + }) + highlighterCheckbox.nextElementSibling.title = "Surligner les lignes, colonnes et régions contenant déjà " + (valueToInsert? "un " + valueToInsert: "le chiffre sélectionné") } function onblur() { diff --git a/sudoku.php b/sudoku.php index 8342a7e..8d94f0f 100644 --- a/sudoku.php +++ b/sudoku.php @@ -97,11 +97,11 @@