Compare commits

..

5 Commits

Author SHA1 Message Date
856825a5e4 nom de variable 2025-04-28 00:38:44 +02:00
b3ad38815f nombre de mots 2025-04-28 00:38:15 +02:00
e04b6f0b91 accents 2025-04-28 00:38:07 +02:00
92dcf21297 nettoyage 2025-04-26 08:35:20 +02:00
ac778222e1 séparation de l'auteur 2025-04-25 20:55:01 +02:00
4 changed files with 3755 additions and 3736 deletions

View File

@ -8,7 +8,7 @@ class Grille {
public $hauteur; public $hauteur;
public $largeur; public $largeur;
private $grilles; private $grilles;
private $mots_commencant_par; private $debuts;
private $mots_utilises = []; private $mots_utilises = [];
public function __construct($hauteur, $largeur, $id="") { public function __construct($hauteur, $largeur, $id="") {
@ -21,17 +21,17 @@ class Grille {
} else { } else {
mt_srand(crc32($id)); mt_srand(crc32($id));
} }
$this->mots_commencant_par = []; $this->debuts = [];
foreach ($hauteur == $largeur? [$hauteur]: [$hauteur, $largeur] as $longueur) { foreach ($hauteur == $largeur? [$hauteur]: [$hauteur, $largeur] as $longueur) {
$this->mots_commencant_par[$longueur] = []; $this->debuts[$longueur] = [];
$nb_mots = 0; $nb_mots = 0;
foreach(mots_espaces($longueur) as $mot) { foreach(mots_espaces($longueur) as $mot) {
for ($i = 0; $i <= $longueur; $i++) { for ($i = 0; $i <= $longueur; $i++) {
$debut = substr($mot, 0, $i); $debut = substr($mot, 0, $i);
if (!isset($this->mots_commencant_par[$longueur][$debut])) { if (!isset($this->debuts[$longueur][$debut])) {
$this->mots_commencant_par[$longueur][$debut] = []; $this->debuts[$longueur][$debut] = [];
} }
$this->mots_commencant_par[$longueur][$debut][] = $mot; $this->debuts[$longueur][$debut][] = $mot;
} }
} }
} }
@ -78,11 +78,11 @@ class Grille {
global $mots_de_n_lettres; global $mots_de_n_lettres;
$largeur = min($l, $this->largeur); $largeur = min($l, $this->largeur);
$hauteur = min($l + 1, $this->hauteur); $hauteur = min($l + 1, $this->hauteur);
foreach ($this->mots_commencant_par[$this->largeur][$this->get_ligne($l, $largeur)] as $mot_lig) { foreach ($this->debuts[$this->largeur][$this->get_ligne($l, $largeur)] as $mot_lig) {
$this->set_ligne($l, $mot_lig); $this->set_ligne($l, $mot_lig);
$ok = true; $ok = true;
for ($c = $l; $c < $this->largeur; $c++) { for ($c = $l; $c < $this->largeur; $c++) {
if (!isset($this->mots_commencant_par[$this->hauteur][$this->get_colonne($c, $hauteur)])) { if (!isset($this->debuts[$this->hauteur][$this->get_colonne($c, $hauteur)])) {
$ok = false; $ok = false;
break; break;
} }
@ -106,14 +106,14 @@ class Grille {
global $mots_de_n_lettres; global $mots_de_n_lettres;
$hauteur = min($c + 1, $this->hauteur); $hauteur = min($c + 1, $this->hauteur);
$largeur = min($c + 1, $this->largeur); $largeur = min($c + 1, $this->largeur);
foreach ($this->mots_commencant_par[$this->hauteur][$this->get_colonne($c, $hauteur)] as $mot_col) { foreach ($this->debuts[$this->hauteur][$this->get_colonne($c, $hauteur)] as $mot_col) {
if (isset($this->mots_utilises[$mot_col])) { if (isset($this->mots_utilises[$mot_col])) {
continue; continue;
} }
$this->set_colonne($c, $mot_col); $this->set_colonne($c, $mot_col);
$ok = true; $ok = true;
for ($l = $c; $l < $this->hauteur; $l++) { for ($l = $c; $l < $this->hauteur; $l++) {
if (!isset($this->mots_commencant_par[$this->largeur][$this->get_ligne($l, $largeur)])) { if (!isset($this->debuts[$this->largeur][$this->get_ligne($l, $largeur)])) {
$ok = false; $ok = false;
break; break;
} }

7418
dico.csv

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,29 @@
<?php <?php
const MIN_LETTRES = 0; const MIN_LETTRES_MOT_1 = 2;
const MIN_LETTRES_MOT_2 = 0;
const MAX_MOTS = 100000; const MAX_MOTS = 100000;
$dico = []; $dico = [];
if (($handle = fopen("dico.csv", "r")) !== FALSE) { if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
$header = fgetcsv($handle, 0, "\t"); $header = fgetcsv($lecteur, 0, "\t");
while (($ligne = fgetcsv($handle, 0, "\t")) !== FALSE) { while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
if (count($ligne) >= 2) { if (substr($ligne[0], 0, 1) != "#" && count($ligne) >= 3) {
$mot = $ligne[0]; [$mot, $definition, $auteur] = $ligne;
$definition = $ligne[1]; if ($auteur) {
$dico[$mot] = $definition; $dico[strtoupper($mot)] = "$definition <small><em>$auteur</em></small>";
} else {
$dico[strtoupper($mot)] = $definition;
}
$nb_espaces = substr_count($mot, ' ');
if ($nb_espaces > 0) {
$dico[$mot] .= " <small>(" . ($nb_espaces + 1) . " mots)</small>";
}
} }
} }
fclose($handle); fclose($lecteur);
} }
$mots_de_n_lettres = []; $mots_de_n_lettres = [];
@ -37,25 +45,26 @@ function fisherYatesShuffle(&$items)
} }
} }
function mots_espaces($longueur) { function mots_espaces($longueur)
{
global $mots_de_n_lettres; global $mots_de_n_lettres;
global $dico; global $dico;
$nb_mots = 0; $nb_mots = 0;
fisherYatesShuffle($mots_de_n_lettres[$longueur]); fisherYatesShuffle($mots_de_n_lettres[$longueur]);
foreach($mots_de_n_lettres[$longueur] as $mot) { foreach ($mots_de_n_lettres[$longueur] as $mot) {
yield $mot; yield $mot;
if (++$nb_mots > MAX_MOTS) { if (++$nb_mots > MAX_MOTS) {
return; return;
} }
} }
for ($i = 2; $longueur - $i - 1 >= MIN_LETTRES; $i++) { for ($i = MIN_LETTRES_MOT_1; $longueur - $i - 1 >= MIN_LETTRES_MOT_2; $i++) {
foreach ($mots_de_n_lettres[$i] as $mot1) { foreach ($mots_de_n_lettres[$i] as $mot1) {
foreach (mots_espaces($longueur - $i - 1) as $mot2) { foreach (mots_espaces($longueur - $i - 1) as $mot2) {
if ($mot1 != $mot2) { if ($mot1 != $mot2) {
$dico["$mot1 $mot2"] = $dico[$mot1] && $dico[$mot2] ? "{$dico[$mot1]}<br/>{$dico[$mot2]}." : $dico[$mot1] . $dico[$mot2]; $dico["$mot1 $mot2"] = $dico[$mot1] && $dico[$mot2] ? "<ol><li>{$dico[$mot1]}</li><li>{$dico[$mot2]}</li></ol>" : $dico[$mot1] . $dico[$mot2];
yield "$mot1 $mot2"; yield "$mot1 $mot2";
$dico["$mot2 $mot1"] = $dico[$mot2] && $dico[$mot1] ? "{$dico[$mot2]}<br/>{$dico[$mot1]}." : $dico[$mot2] . $dico[$mot1]; $dico["$mot2 $mot1"] = $dico[$mot2] && $dico[$mot1] ? "<ol><li>{$dico[$mot2]}</li><li>{$dico[$mot1]}</li></ol>" : $dico[$mot2] . $dico[$mot1];
yield "$mot2 $mot1"; yield "$mot2 $mot1";
$nb_mots += 2; $nb_mots += 2;
if ($nb_mots > MAX_MOTS) { if ($nb_mots > MAX_MOTS) {
@ -65,4 +74,4 @@ function mots_espaces($longueur) {
} }
} }
} }
} }

View File

@ -95,10 +95,22 @@ table.grille {
width: 45%; width: 45%;
} }
.definitions li::marker { .definitions ol {
padding-left: 2em;
}
.definitions > div > ol > li::marker {
font-weight: bold; font-weight: bold;
} }
.definitions li ol {
padding-left: 1em;
}
.definitions li li::marker {
font-size: small;
}
button[type='submit'] { button[type='submit'] {
width: fit-content; width: fit-content;
margin: 0 auto; margin: 0 auto;