moins de comparaisons

This commit is contained in:
Adrien MALINGREY 2025-05-03 02:36:46 +02:00
parent 0dd9881f6d
commit 168fc5f7a2
2 changed files with 14 additions and 15 deletions

View File

@ -99,22 +99,21 @@ class Grille implements Iterator, ArrayAccess {
$this->grille[$y][$x] = $lettre; $this->grille[$y][$x] = $lettre;
$this->lignes[$y] = []; $this->lignes[$y] = [];
$mots = []; if ($x == $this->largeur - 1) $this->lignes[$y] = explode(" ", $this->get_ligne($y, $this->largeur));
if ($x == $this->largeur - 1) $mots = explode(" ", $this->get_ligne($y, $this->largeur)); else if ($lettre == " ") $this->lignes[$y] = explode(" ", $this->get_ligne($y, $x));
else if ($lettre == " ") $mots = explode(" ", $this->get_ligne($y, $x)); if (count($this->lignes[$y])) {
foreach ($mots as $rang => $mot) { $mot = array_pop($this->lignes[$y]);
if (strlen($mot) <= 1) continue; if (strlen($mot) >= 1 && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue;
if (in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2; $this->lignes[$y][] = $mot;
$this->lignes[$y][$rang] = $mot;
} }
$this->colonnes[$x] = []; $this->colonnes[$x] = [];
$mots = []; if ($y == $this->hauteur - 1) $this->colonnes[$x] = explode(" ", $this->get_colonne($x, $this->hauteur));
if ($y == $this->hauteur - 1) $mots = explode(" ", $this->get_colonne($x, $this->hauteur)); else if ($lettre == " ") $this->colonnes[$x] = explode(" ", $this->get_colonne($x, $y));
else if ($lettre == " ") $mots = explode(" ", $this->get_colonne($x, $y)); if (count($this->colonnes[$x])) {
foreach ($mots as $rang => $mot) { $mot = array_pop($this->colonnes[$x]);
if (strlen($mot) == 1) continue; if (strlen($mot) >= 1 && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue;
if (in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2; $this->colonnes[$x][] = $mot;
$this->colonnes[$x][$rang] = $mot;
} }
if ($i < $this->nb_positions) { if ($i < $this->nb_positions) {

View File

@ -65,7 +65,7 @@ if ($grille->valid()) {
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>MOTSCROISÉS</title> <title>MOTS CROISÉS</title>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link rel="icon" href="favicon.svg"> <link rel="icon" href="favicon.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">