This commit is contained in:
2026-01-10 21:53:14 +01:00
parent f473cc24eb
commit 02f17f78bf
2 changed files with 17 additions and 15 deletions

View File

@@ -104,11 +104,16 @@ class Grille implements ArrayAccess
$this->definitions["horizontales"][$y] = []; $this->definitions["horizontales"][$y] = [];
foreach($mots as $mot) { foreach($mots as $mot) {
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]]; $definitions = $this->dico[$mot["longueur"]][$mot["mot"]];
var_dump($definitions);
if (count($definitions)) { if (count($definitions)) {
$definition = $definitions[mt_rand(0, count($definitions) - 1)]; $definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (isset($definition["definition"])) $mot["definition"] = $definition["definition"]; if (is_array($definition)) {
if (isset($definition["auteur"])) $mot["auteur"] = $definition["auteur"]; foreach ($definition as $auteur => $def) {
$mot["definition"] = $def;
$mot["auteur"] = $auteur;
}
} else if (is_string($definition)) {
$mot["definition"] = $definition;
}
} }
if (isset($definitions["nb_mots"])) { if (isset($definitions["nb_mots"])) {
$mot["nb_mots"] = $definitions["nb_mots"]; $mot["nb_mots"] = $definitions["nb_mots"];
@@ -124,8 +129,14 @@ class Grille implements ArrayAccess
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]]; $definitions = $this->dico[$mot["longueur"]][$mot["mot"]];
if (count($definitions)) { if (count($definitions)) {
$definition = $definitions[mt_rand(0, count($definitions) - 1)]; $definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (isset($definition["definition"])) $mot["definition"] = $definition["definition"]; if (is_array($definition)) {
if (isset($definition["auteur"])) $mot["auteur"] = $definition["auteur"]; foreach ($definition as $auteur => $def) {
$mot["definition"] = $def;
$mot["auteur"] = $auteur;
}
} else if (is_string($definition)) {
$mot["definition"] = $definition;
}
} }
if (isset($definitions["nb_mots"])) { if (isset($definitions["nb_mots"])) {
$mot["nb_mots"] = $definitions["nb_mots"]; $mot["nb_mots"] = $definitions["nb_mots"];

View File

@@ -30,17 +30,8 @@ function dico($longueur_max) {
if (strlen($mot) > $longueur_max) continue; if (strlen($mot) > $longueur_max) continue;
$dico[strlen($mot)][$mot] = []; $dico[strlen($mot)][$mot] = $definitions;
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots; if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
foreach ($definitions as $definition) {
if (is_array($definition)) {
foreach ($definition as $auteur => $def) {
$dico[strlen($mot)][$mot][] = ["auteur" => $auteur, "definition" => $def];
}
} else if (is_string($definition)) {
$dico[strlen($mot)][$mot][] = ["definition" => $definition];
}
}
} }
return $dico; return $dico;