CASE_NOIRE
This commit is contained in:
parent
2e93e2c878
commit
a42f8a5f18
18
Grille.php
18
Grille.php
@ -96,18 +96,18 @@ class Grille implements ArrayAccess
|
||||
$this->grille[$y][$x] = $lettre;
|
||||
|
||||
// Omission des lettres isolées
|
||||
if ($lettre == " "
|
||||
&& ($y - 2 < 0 || $this->grille[$y - 2][$x] == " ")
|
||||
&& ($y - 1 < 0 || $x - 1 < 0 || $this->grille[$y - 1][$x - 1] == " ")
|
||||
&& ($y - 1 < 0 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == " ")
|
||||
if ($lettre == CASE_NOIRE
|
||||
&& ($y - 2 < 0 || $this->grille[$y - 2][$x] == CASE_NOIRE)
|
||||
&& ($y - 1 < 0 || $x - 1 < 0 || $this->grille[$y - 1][$x - 1] == CASE_NOIRE)
|
||||
&& ($y - 1 < 0 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == CASE_NOIRE)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Omission des doublons
|
||||
$mots = [];
|
||||
if ($x == $this->largeur - 1) $mots = explode(" ", $this->get_ligne($y, $this->largeur));
|
||||
else if ($lettre == " ") $mots = explode(" ", $this->get_ligne($y, $x));
|
||||
if ($x == $this->largeur - 1) $mots = explode(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
|
||||
else if ($lettre == CASE_NOIRE) $mots = explode(CASE_NOIRE, $this->get_ligne($y, $x));
|
||||
else $mots = [];
|
||||
$this->lignes[$y] = array_filter($mots, function ($mot) {
|
||||
return strlen($mot) >= 2;
|
||||
@ -119,7 +119,7 @@ class Grille implements ArrayAccess
|
||||
}
|
||||
|
||||
if ($y == $this->hauteur - 1) {
|
||||
$mots = explode(" ", $this->get_colonne($x, $this->hauteur));
|
||||
$mots = explode(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
|
||||
foreach ($mots as $rang => $mot) {
|
||||
if (strlen($mot) < 2) continue;
|
||||
if (strlen($mot > 2) && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2;
|
||||
@ -192,14 +192,14 @@ class Grille implements ArrayAccess
|
||||
}
|
||||
|
||||
for ($y = 0; $y < $this->hauteur; $y++) {
|
||||
$mots = explode(" ", $this->get_ligne($y, $this->largeur));
|
||||
$mots = explode(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
|
||||
$this->lignes[$y] = array_filter($mots, function ($mot) {
|
||||
return strlen($mot) >= 2;
|
||||
});
|
||||
}
|
||||
|
||||
for ($x = 0; $x < $this->largeur; $x++) {
|
||||
$mots = explode(" ", $this->get_colonne($x, $this->hauteur));
|
||||
$mots = explode(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
|
||||
$this->colonnes[$x] = array_filter($mots, function ($mot) {
|
||||
return strlen($mot) >= 2;
|
||||
});
|
||||
|
9
dico.php
9
dico.php
@ -2,6 +2,7 @@
|
||||
include_once "Trie.php";
|
||||
|
||||
|
||||
const CASE_NOIRE = " ";
|
||||
const MIN_PREMIER_MOT = 1;
|
||||
const MIN_MOTS_SUIVANTS = 1;
|
||||
|
||||
@ -32,10 +33,10 @@ function dico($longueur_max) {
|
||||
}
|
||||
}
|
||||
|
||||
$mot = str_replace("-", " ", $mot);
|
||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
||||
$mot = $transliterator->transliterate($mot);
|
||||
if (strpos($mot, " ") !== false) {
|
||||
$mots = explode(" ", $mot);
|
||||
if (strpos($mot, CASE_NOIRE) !== false) {
|
||||
$mots = explode(CASE_NOIRE, $mot);
|
||||
$nb_mots = count($mots);
|
||||
$mot = implode("", $mots);
|
||||
$definition .= " <small>($nb_mots mots)</small>";
|
||||
@ -55,7 +56,7 @@ function mots_espaces($longueur_max) {
|
||||
for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {
|
||||
$mots_suivants = $dico[$longueur - $position_espace - 1];
|
||||
foreach ($dico[$position_espace]->arrayIterator() as $premier_mot => $definition) {
|
||||
$premier_mot[] = " ";
|
||||
$premier_mot[] = CASE_NOIRE;
|
||||
$dico[$longueur]->arraySet($premier_mot, $mots_suivants);
|
||||
}
|
||||
}
|
||||
|
@ -122,9 +122,9 @@ if ($grille_valide) {
|
||||
<tr>
|
||||
<th><?= $y + 1 ?></th>
|
||||
<?php for ($x = 0; $x < $largeur; $x++): ?>
|
||||
<?php if ($grille[$y][$x] == " "): ?>
|
||||
<?php if ($grille[$y][$x] == CASE_NOIRE): ?>
|
||||
<td class="case noire">
|
||||
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value=" " disabled />
|
||||
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value=CASE_NOIRE disabled />
|
||||
</td>
|
||||
<?php else: ?>
|
||||
<td class="case blanche">
|
||||
|
Loading…
x
Reference in New Issue
Block a user