diff --git a/Grille.php b/Grille.php index 5845dab..7be368b 100644 --- a/Grille.php +++ b/Grille.php @@ -2,6 +2,9 @@ include_once "dico.php"; +const ECART_TYPE_ALEA = 5; + + $randmax = mt_getrandmax() + 1; function gaussienne($moyenne = 0, $ecartType = 1.0): float { global $randmax; @@ -82,7 +85,7 @@ class Grille implements ArrayAccess $lettres_colonne->branches ); foreach ($lettres_communes as $lettre => $_) { - $lettres_communes[$lettre] = count($lettres_ligne->branches[$lettre]) * count($lettres_colonne->branches[$lettre]) * gaussienne(1, 5); + $lettres_communes[$lettre] = count($lettres_ligne->branches[$lettre]) * count($lettres_colonne->branches[$lettre]) * gaussienne(1, ECART_TYPE_ALEA); } uksort($lettres_communes, function($a, $b) use ($lettres_communes) { return $lettres_communes[$b] <=> $lettres_communes[$a]; diff --git a/dico.php b/dico.php index a5bf012..a396648 100644 --- a/dico.php +++ b/dico.php @@ -6,14 +6,13 @@ const MIN_PREMIER_MOT = 1; const MIN_MOTS_SUIVANTS = 1; -$nb_mots = 0; - function dico($longueur_max) { - global $nb_mots; - $transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD); $dico = [[""]]; + for ($longueur = 0; $longueur <= $longueur_max; $longueur++) { + $dico[] = new Trie(); + } if (($lecteur = fopen("dico.csv", "r")) !== FALSE) { $entete = fgetcsv($lecteur, 0, "\t"); while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) { @@ -40,16 +39,16 @@ function dico($longueur_max) { $mot = $ligne[0]; $definitions = array_slice($ligne, 1); + $mot = str_replace("-", " ", $mot); $mot = $transliterator->transliterate($mot); if (strpos($mot, " ") !== false) { $mots = explode(" ", $mot); - $nb_mot = count($mots); + $nb_mots = count($mots); $mot = implode("", $mots); - $definition .= " ($nb_mot mots)"; + $definition .= " ($nb_mots mots)"; } $longueur = strlen($mot); - if (!isset($dico[$longueur])) $dico[$longueur] = new Trie(); if (!isset($dico[$longueur][$mot])) $dico[$longueur][$mot] = []; if (strlen($definition)) $dico[$longueur][$mot][] = $definition; } @@ -60,8 +59,6 @@ function dico($longueur_max) { } function mots_espaces($longueur_max) { - global $nb_mots; - $dico = dico($longueur_max); for ($longueur = 1; $longueur <= $longueur_max; $longueur++) { for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {