publier les mots entiers en ligne et colonne

This commit is contained in:
Adrien MALINGREY 2025-05-01 14:23:27 +02:00
parent c8ecb504ef
commit 351e8387bb
2 changed files with 14 additions and 7 deletions

View File

@ -20,13 +20,16 @@ class Grille implements Iterator, ArrayAccess {
private $lettres_suivantes; private $lettres_suivantes;
private $positions; private $positions;
private $nb_positions; private $nb_positions;
public $mots_utilises; public $lignes;
public $colonnes;
public function __construct($hauteur, $largeur, $id = "") public function __construct($hauteur, $largeur, $id = "")
{ {
$this->hauteur = $hauteur; $this->hauteur = $hauteur;
$this->largeur = $largeur; $this->largeur = $largeur;
$this->grille = array_fill(0, $hauteur, array_fill(0, $largeur, '')); $this->grille = array_fill(0, $hauteur, array_fill(0, $largeur, ''));
$this->lignes = [];
$this->colonnes = [];
$this->lettres_suivantes = []; $this->lettres_suivantes = [];
foreach ($hauteur == $largeur ? [$hauteur] : [$hauteur, $largeur] as $longueur) { foreach ($hauteur == $largeur ? [$hauteur] : [$hauteur, $largeur] as $longueur) {
@ -53,7 +56,6 @@ class Grille implements Iterator, ArrayAccess {
$this->nb_positions = count($this->positions); $this->nb_positions = count($this->positions);
mt_srand($id == "" ? null : crc32($id)); mt_srand($id == "" ? null : crc32($id));
$this->mots_utilises = [];
$this->grilles = $this->generateur(); $this->grilles = $this->generateur();
} }
@ -101,14 +103,19 @@ class Grille implements Iterator, ArrayAccess {
$this->grille[$y][$x] = $lettre; $this->grille[$y][$x] = $lettre;
if ($x == $this->largeur - 1) { if ($x == $this->largeur - 1) {
$this->mots_utilises[$y] = $this->get_ligne($y, $x); $this->lignes[$y] = $this->get_ligne($y, $this->largeur);
} else { } else {
unset($this->mots_utilises[$y]); unset($this->lignes[$y]);
} }
if ($y == $this->hauteur - 1) { if ($y == $this->hauteur - 1) {
if (in_array($this->get_colonne($x, $y), $this->mots_utilises)) { $colonne = $this->get_colonne($x, $this->hauteur);
if (in_array($this->get_colonne($x, $y), $this->lignes)) {
continue; continue;
} else {
$this->colonnes[$x] = $colonne;
} }
} else {
unset($this->colonnes[$x]);
} }
if ($i < $this->nb_positions) { if ($i < $this->nb_positions) {

View File

@ -42,10 +42,10 @@ $definitions = [
"colonnes" => [] "colonnes" => []
]; ];
for ($y = 0; $y < $hauteur; $y++) { for ($y = 0; $y < $hauteur; $y++) {
$definitions["lignes"][$y] = $dico[$grille->get_ligne($y, $largeur)]; $definitions["lignes"][$y] = $dico[$grille->lignes[$y]];
} }
for ($x = 0; $x < $largeur; $x++) { for ($x = 0; $x < $largeur; $x++) {
$definitions["colonnes"][$x] = $dico[$grille->get_colonne($x, $hauteur)]; $definitions["colonnes"][$x] = $dico[$grille->colonnes[$x]];
} }
?> ?>