Compare commits
3 Commits
ab7694a55b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
b08e89490f
|
|||
|
02f17f78bf
|
|||
|
f473cc24eb
|
30
Grille.php
30
Grille.php
@@ -103,34 +103,20 @@ class Grille implements ArrayAccess
|
||||
$mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
|
||||
$this->definitions["horizontales"][$y] = [];
|
||||
foreach($mots as $mot) {
|
||||
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
if (count($definitions)) {
|
||||
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||
if (isset($definition[DEFINITION])) $mot["definition"] = $definition[DEFINITION];
|
||||
if (isset($definition[AUTEUR])) $mot["auteur"] = $definition[AUTEUR];
|
||||
}
|
||||
if (isset($definitions["nb_mots"])) {
|
||||
$mot["nb_mots"] = $definitions["nb_mots"];
|
||||
}
|
||||
unset($mot["mot"]);
|
||||
$this->definitions["horizontales"][$y][] = $mot;
|
||||
$definition = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
$definition["debut"] = $mot["debut"];
|
||||
$definition["fin"] = $mot["fin"];
|
||||
$this->definitions["horizontales"][$y][] = $definition;
|
||||
}
|
||||
}
|
||||
for ($x = 0; $x < $this->largeur; $x++) {
|
||||
$mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
|
||||
$this->definitions["verticales"][$x] = [];
|
||||
foreach($mots as $mot) {
|
||||
$definitions = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
if (count($definitions)) {
|
||||
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||
if (isset($definition[DEFINITION])) $mot["definition"] = $definition[DEFINITION];
|
||||
if (isset($definition[AUTEUR])) $mot["auteur"] = $definition[AUTEUR];
|
||||
}
|
||||
if (isset($definitions["nb_mots"])) {
|
||||
$mot["nb_mots"] = $definitions["nb_mots"];
|
||||
}
|
||||
unset($mot["mot"]);
|
||||
$this->definitions["verticales"][$x][] = $mot;
|
||||
$definition = $this->dico[$mot["longueur"]][$mot["mot"]];
|
||||
$definition["debut"] = $mot["debut"];
|
||||
$definition["fin"] = $mot["fin"];
|
||||
$this->definitions["verticales"][$x][] = $definition;
|
||||
}
|
||||
}
|
||||
$this->save($id);
|
||||
|
||||
38
dico.php
38
dico.php
@@ -4,8 +4,6 @@ include_once "Trie.php";
|
||||
|
||||
|
||||
const CASE_NOIRE = " ";
|
||||
const DEFINITION = 0;
|
||||
const AUTEUR = 1;
|
||||
|
||||
|
||||
function dico($longueur_max) {
|
||||
@@ -15,18 +13,11 @@ function dico($longueur_max) {
|
||||
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
||||
$dico[] = new Trie();
|
||||
}
|
||||
if (($lecteur = fopen("dico.tsv", "r")) !== FALSE) {
|
||||
$entete = fgetcsv($lecteur, 0, "\t");
|
||||
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||
if (
|
||||
$ligne[0] == NULL
|
||||
|| substr($ligne[0], 0, 1) == "#"
|
||||
|| strlen($ligne[0]) > $longueur_max
|
||||
) continue;
|
||||
|
||||
$mot = $ligne[0];
|
||||
$definition = array_slice($ligne, 1);
|
||||
foreach (str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZ") as $lettre) {
|
||||
$dico[1][$lettre] = [];
|
||||
}
|
||||
|
||||
foreach (yaml_parse_file('dico.yaml') as $mot => $definitions) {
|
||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
||||
$mot = $transliterator->transliterate($mot);
|
||||
if (strpos($mot, CASE_NOIRE) !== false) {
|
||||
@@ -37,15 +28,22 @@ function dico($longueur_max) {
|
||||
$nb_mots = 1;
|
||||
}
|
||||
|
||||
if (array_key_exists($mot, $dico)) {
|
||||
$dico[strlen($mot)][$mot][] = $definition;
|
||||
} else {
|
||||
$dico[strlen($mot)][$mot] = [$definition];
|
||||
if (strlen($mot) > $longueur_max) continue;
|
||||
|
||||
$dico[strlen($mot)][$mot] = [];
|
||||
if (count($definitions)) {
|
||||
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||
if (is_array($definition)) {
|
||||
foreach ($definition as $auteur => $def) {
|
||||
$dico[strlen($mot)][$mot]["definition"] = $def;
|
||||
$dico[strlen($mot)][$mot]["auteur"] = $auteur;
|
||||
}
|
||||
} else if (is_string($definition)) {
|
||||
$dico[strlen($mot)][$mot]["definition"] = $definition;
|
||||
}
|
||||
}
|
||||
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
|
||||
}
|
||||
}
|
||||
fclose($lecteur);
|
||||
}
|
||||
|
||||
return $dico;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user