nom de variable

This commit is contained in:
Adrien MALINGREY 2025-04-28 00:38:44 +02:00
parent b3ad38815f
commit 856825a5e4

View File

@ -8,7 +8,7 @@ class Grille {
public $hauteur; public $hauteur;
public $largeur; public $largeur;
private $grilles; private $grilles;
private $mots_commencant_par; private $debuts;
private $mots_utilises = []; private $mots_utilises = [];
public function __construct($hauteur, $largeur, $id="") { public function __construct($hauteur, $largeur, $id="") {
@ -21,17 +21,17 @@ class Grille {
} else { } else {
mt_srand(crc32($id)); mt_srand(crc32($id));
} }
$this->mots_commencant_par = []; $this->debuts = [];
foreach ($hauteur == $largeur? [$hauteur]: [$hauteur, $largeur] as $longueur) { foreach ($hauteur == $largeur? [$hauteur]: [$hauteur, $largeur] as $longueur) {
$this->mots_commencant_par[$longueur] = []; $this->debuts[$longueur] = [];
$nb_mots = 0; $nb_mots = 0;
foreach(mots_espaces($longueur) as $mot) { foreach(mots_espaces($longueur) as $mot) {
for ($i = 0; $i <= $longueur; $i++) { for ($i = 0; $i <= $longueur; $i++) {
$debut = substr($mot, 0, $i); $debut = substr($mot, 0, $i);
if (!isset($this->mots_commencant_par[$longueur][$debut])) { if (!isset($this->debuts[$longueur][$debut])) {
$this->mots_commencant_par[$longueur][$debut] = []; $this->debuts[$longueur][$debut] = [];
} }
$this->mots_commencant_par[$longueur][$debut][] = $mot; $this->debuts[$longueur][$debut][] = $mot;
} }
} }
} }
@ -78,11 +78,11 @@ class Grille {
global $mots_de_n_lettres; global $mots_de_n_lettres;
$largeur = min($l, $this->largeur); $largeur = min($l, $this->largeur);
$hauteur = min($l + 1, $this->hauteur); $hauteur = min($l + 1, $this->hauteur);
foreach ($this->mots_commencant_par[$this->largeur][$this->get_ligne($l, $largeur)] as $mot_lig) { foreach ($this->debuts[$this->largeur][$this->get_ligne($l, $largeur)] as $mot_lig) {
$this->set_ligne($l, $mot_lig); $this->set_ligne($l, $mot_lig);
$ok = true; $ok = true;
for ($c = $l; $c < $this->largeur; $c++) { for ($c = $l; $c < $this->largeur; $c++) {
if (!isset($this->mots_commencant_par[$this->hauteur][$this->get_colonne($c, $hauteur)])) { if (!isset($this->debuts[$this->hauteur][$this->get_colonne($c, $hauteur)])) {
$ok = false; $ok = false;
break; break;
} }
@ -106,14 +106,14 @@ class Grille {
global $mots_de_n_lettres; global $mots_de_n_lettres;
$hauteur = min($c + 1, $this->hauteur); $hauteur = min($c + 1, $this->hauteur);
$largeur = min($c + 1, $this->largeur); $largeur = min($c + 1, $this->largeur);
foreach ($this->mots_commencant_par[$this->hauteur][$this->get_colonne($c, $hauteur)] as $mot_col) { foreach ($this->debuts[$this->hauteur][$this->get_colonne($c, $hauteur)] as $mot_col) {
if (isset($this->mots_utilises[$mot_col])) { if (isset($this->mots_utilises[$mot_col])) {
continue; continue;
} }
$this->set_colonne($c, $mot_col); $this->set_colonne($c, $mot_col);
$ok = true; $ok = true;
for ($l = $c; $l < $this->hauteur; $l++) { for ($l = $c; $l < $this->hauteur; $l++) {
if (!isset($this->mots_commencant_par[$this->largeur][$this->get_ligne($l, $largeur)])) { if (!isset($this->debuts[$this->largeur][$this->get_ligne($l, $largeur)])) {
$ok = false; $ok = false;
break; break;
} }