Compare commits

..

No commits in common. "856825a5e4b81073e00840f8a1985a8f6ac8d81b" and "cfa03c1927a67a7e2c20dd39f1c984d84d2a6fd6" have entirely different histories.

4 changed files with 3736 additions and 3755 deletions

View File

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

7418
dico.csv

File diff suppressed because it is too large Load Diff

View File

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

View File

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