Eviter les doublons lorsqu'il y a plusieurs mots en ligne
This commit is contained in:
parent
b042fcd77a
commit
38344a315c
13
Grille.php
13
Grille.php
@ -103,17 +103,18 @@ 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->lignes[$y] = $this->get_ligne($y, $this->largeur);
|
$this->lignes[$y] = explode(" ", $this->get_ligne($y, $this->largeur));
|
||||||
} else {
|
} else {
|
||||||
unset($this->lignes[$y]);
|
unset($this->lignes[$y]);
|
||||||
}
|
}
|
||||||
if ($y == $this->hauteur - 1) {
|
if ($y == $this->hauteur - 1) {
|
||||||
$colonne = $this->get_colonne($x, $this->hauteur);
|
$mots_colonne = explode(" ", $this->get_colonne($x, $this->hauteur));
|
||||||
if (in_array($this->get_colonne($x, $y), $this->lignes)) {
|
foreach ($mots_colonne as $mot_colonne) {
|
||||||
continue;
|
if (in_array($mot_colonne, array_merge(...$this->lignes))) {
|
||||||
} else {
|
continue 2;
|
||||||
$this->colonnes[$x] = $colonne;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$this->colonnes[$x] = $mots_colonne;
|
||||||
} else {
|
} else {
|
||||||
unset($this->colonnes[$x]);
|
unset($this->colonnes[$x]);
|
||||||
}
|
}
|
||||||
|
4
dico.php
4
dico.php
@ -9,7 +9,7 @@ $dico = [[]];
|
|||||||
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||||
$header = fgetcsv($lecteur, 0, "\t");
|
$header = fgetcsv($lecteur, 0, "\t");
|
||||||
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||||
if ($ligne[0] != NULL && substr($ligne[0], 0, 1) == "#") {
|
if ($ligne[0] == NULL || substr($ligne[0], 0, 1) == "#") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch(count($ligne)) {
|
switch(count($ligne)) {
|
||||||
@ -33,8 +33,10 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
|||||||
if (!isset($dico[$longueur][$mot])) {
|
if (!isset($dico[$longueur][$mot])) {
|
||||||
$dico[$longueur][$mot] = [];
|
$dico[$longueur][$mot] = [];
|
||||||
}
|
}
|
||||||
|
if (strlen($definition)) {
|
||||||
$dico[$longueur][$mot][] = $definition;
|
$dico[$longueur][$mot][] = $definition;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fclose($lecteur);
|
fclose($lecteur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
index.php
14
index.php
@ -43,21 +43,19 @@ $definitions = [
|
|||||||
];
|
];
|
||||||
foreach ($grille->lignes as $y => $mots) {
|
foreach ($grille->lignes as $y => $mots) {
|
||||||
$definitions["lignes"][$y] = [];
|
$definitions["lignes"][$y] = [];
|
||||||
foreach (explode(" ", $mots) as $mot) {
|
foreach ($mots as $mot) {
|
||||||
$definitions_lignes = $dico[strlen($mot)][$mot];
|
$definitions_lignes = $dico[strlen($mot)][$mot];
|
||||||
$definition = $definitions_lignes[array_rand($definitions_lignes)];
|
if (count($definitions_lignes)) {
|
||||||
if (strlen($definition)) {
|
$definitions["lignes"][$y][] = $definitions_lignes[array_rand($definitions_lignes)];
|
||||||
$definitions["lignes"][$y][] = $definition;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($grille->colonnes as $x => $mots) {
|
foreach ($grille->colonnes as $x => $mots) {
|
||||||
$definitions["colonnes"][$y] = [];
|
$definitions["colonnes"][$y] = [];
|
||||||
foreach (explode(" ", $mots) as $mot) {
|
foreach ($mots as $mot) {
|
||||||
$definitions_colonnes = $dico[strlen($mot)][$mot];
|
$definitions_colonnes = $dico[strlen($mot)][$mot];
|
||||||
$definition = $definitions_colonnes[array_rand($definitions_colonnes)];
|
if (count($definitions_colonnes)) {
|
||||||
if (strlen($definition)) {
|
$definitions["colonnes"][$x][] = $definitions_colonnes[array_rand($definitions_colonnes)];
|
||||||
$definitions["colonnes"][$x][] = $definition;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user