change unknow char

This commit is contained in:
Adrien MALINGREY 2020-10-09 03:02:48 +02:00
parent d376e7fc50
commit 48ebd92b84
2 changed files with 13 additions and 9 deletions

View File

@ -1,7 +1,9 @@
<?php
const UNKOWN = ".";
$gridStr = basename(strip_tags($_SERVER["REQUEST_URI"]));
// URL contains grid
if (preg_match("#^[1-9?]{81}$#", $gridStr)) {
if (preg_match("#^[1-9.]{81}$#", $gridStr)) {
?>
<!DOCTYPE html>
<html lang="fr">
@ -27,7 +29,7 @@
<?php
for ($column = 0; $column < 9; $column++) {
$value = $gridStr[9*$row+$column];
if ($value == "?") {
if ($value == UNKOWN) {
$value = "";
$disabled = "";
} else {

View File

@ -1,11 +1,13 @@
<?php
const UNKOWN = ".";
function isKnown($box) {
return $box->value != "?";
return $box->value != UNKOWN;
}
function isUnknown($box) {
return $box->value == "?";
return $box->value == UNKOWN;
}
function easyFirst($box1, $box2) {
@ -26,7 +28,7 @@
public $values = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
function __construct($rowId, $columnId, $regionId) {
$this->value = "?";
$this->value = UNKOWN;
$this->rowId = $rowId;
$this->columnId = $columnId;
$this->regionId = $regionId;
@ -38,7 +40,7 @@
function searchAllowedValues() {
$this->allowedValues = $this->values;
forEach($this->neighbourhood as $neighbour) {
if ($neighbour->value != "?")
if ($neighbour->value != UNKOWN)
array_unset_value($neighbour->value, $this->allowedValues);
}
}
@ -101,7 +103,7 @@
$erasedValues = array();
forEach($testBoxes as $testBox) {
$erasedValues[] = $testBox->value;
$testBox->value = "?";
$testBox->value = UNKOWN;
forEach($testBox->neighbourhood as $neighbour)
$neighbour->searchAllowedValues();
}
@ -160,7 +162,7 @@
$neighbour->allowedValues[] = $testBox->value;
if ($stop) break;
}
$testBox->value = "?";
$testBox->value = UNKOWN;
} else {
yield $this->toString();
}
@ -170,7 +172,7 @@
$str = "";
foreach($this->rows as $row) {
forEach($row as $box) {
$str .= ($box->value? $box->value : "?");
$str .= ($box->value? $box->value : UNKOWN);
}
}
return $str;