From a42f8a5f18992ced65c99bdd5297f29b45c71feb Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 8 May 2025 05:24:21 +0200 Subject: [PATCH] CASE_NOIRE --- Grille.php | 18 +++++++++--------- dico.php | 9 +++++---- index.php | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Grille.php b/Grille.php index 7be368b..93d3e08 100644 --- a/Grille.php +++ b/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; }); diff --git a/dico.php b/dico.php index dd47326..4d1b8ed 100644 --- a/dico.php +++ b/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 .= " ($nb_mots mots)"; @@ -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); } } diff --git a/index.php b/index.php index e570c88..94a1cd8 100644 --- a/index.php +++ b/index.php @@ -122,9 +122,9 @@ if ($grille_valide) { - + - +