From 1987905eb9d6502cd1e0966c575882388bb6eb7e Mon Sep 17 00:00:00 2001 From: adrien Date: Fri, 2 May 2025 04:08:38 +0200 Subject: [PATCH] annulation de l'autorisation des doublons --- Grille.php | 7 +------ index.php | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Grille.php b/Grille.php index 7ca1159..d04e4ba 100644 --- a/Grille.php +++ b/Grille.php @@ -101,12 +101,7 @@ class Grille implements Iterator, ArrayAccess { if ($x == $this->largeur - 1) { foreach (explode(" ", $this->get_ligne($y, $this->largeur)) as $rang => $mot) { if (strlen($mot) == 1) continue; - $nb_definitions = count($dico[strlen($mot)][$mot]); - $occurences = 1; - foreach (array_merge(...$this->lignes, ...$this->colonnes) as $mot2) { - if ($mot != $mot2) continue; - if (++$occurences >= $nb_definitions) continue 3; - } + if (in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2; $this->lignes[$y][$rang] = $mot; } } else { diff --git a/index.php b/index.php index 3124b11..c9ac7af 100644 --- a/index.php +++ b/index.php @@ -51,7 +51,7 @@ foreach ($grille->lignes as $y => $mots) { foreach ($mots as $mot) { $definitions = $dico[strlen($mot)][$mot]; if (count($definitions)) { - $definitions_horizontales[$y][] = array_pop($definitions); + $definitions_horizontales[$y][] = $definitions[mt_rand(0, count($definitions) - 1)]; } } } @@ -61,7 +61,7 @@ foreach ($grille->colonnes as $x => $mots) { foreach ($mots as $mot) { $definitions = $dico[strlen($mot)][$mot]; if (count($definitions)) { - $definitions_verticales[$x][] = array_pop($definitions); + $definitions_verticales[$x][] = $definitions[mt_rand(0, count($definitions) - 1)]; } } }