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

View File

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