From 2445bfcf54818654d2be5f4f65295a6abdc60d68 Mon Sep 17 00:00:00 2001 From: adrien <adrien@malingrey.fr> Date: Mon, 28 Apr 2025 18:33:14 +0200 Subject: [PATCH] =?UTF-8?q?gestion=20probl=C3=A8me=20de=20g=C3=A9n=C3=A9ra?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Grille.php | 9 +++- dico.php | 16 +++---- favicon.ico | Bin 518 -> 518 bytes index.php | 122 +++++++++++++++++++++++++++------------------------- style.css | 4 ++ 5 files changed, 84 insertions(+), 67 deletions(-) diff --git a/Grille.php b/Grille.php index 5a2e70e..5b91e28 100644 --- a/Grille.php +++ b/Grille.php @@ -38,7 +38,6 @@ class Grille { mt_srand(); $this->grilles = $this->generateur(); - $this->grilles->current(); } public function get_ligne($l, $largeur) { @@ -133,6 +132,14 @@ class Grille { } } + public function current() { + return $this->grilles->current(); + } + + public function valid() { + return $this->grilles->valid(); + } + public function hash() { $string = ""; foreach ($this->grille as $ligne) { diff --git a/dico.php b/dico.php index 4f18a6b..25ae938 100644 --- a/dico.php +++ b/dico.php @@ -3,7 +3,7 @@ const MIN_LETTRES_MOT_1 = 2; const MIN_LETTRES_MOT_2 = 0; -const MAX_MOTS = 100000; +// const MAX_MOTS = 100000; $dico = []; @@ -59,9 +59,9 @@ function mots_espaces($longueur) fisherYatesShuffle($mots_de_n_lettres[$longueur]); foreach ($mots_de_n_lettres[$longueur] as $mot) { yield $mot; - if (++$nb_mots > MAX_MOTS) { - return; - } + // if (++$nb_mots > MAX_MOTS) { + // return; + // } } for ($i = MIN_LETTRES_MOT_1; $longueur - $i - 1 >= MIN_LETTRES_MOT_2; $i++) { foreach ($mots_de_n_lettres[$i] as $mot1) { @@ -71,10 +71,10 @@ function mots_espaces($longueur) yield "$mot1 $mot2"; $dico["$mot2 $mot1"] = array_merge($dico[$mot2], $dico[$mot1]); yield "$mot2 $mot1"; - $nb_mots += 2; - if ($nb_mots > MAX_MOTS) { - return; - } + // $nb_mots += 2; + // if ($nb_mots > MAX_MOTS) { + // return; + // } } } } diff --git a/favicon.ico b/favicon.ico index a892187749812d463563597350b09a23bbaa09eb..a19eb3cad356c158f853b11def6479c162780e7c 100644 GIT binary patch literal 518 zcmZQzU}RuoP*7k3(u@oSj0_BF3=9kc0ucTNAUg~wrU9fCfY<?uLF({<|NsA^O54}{ zVZergs^s_AVZ~qru;~Gbf%P%`k>8Jr!TJUP0SYexAXWfkV#BNY00RRu25MzszK4oI OV%0z~WDF9c6aWBUjXrDu literal 518 zcmZQzU}RuoP*7k3(u@oSj0_BF3=9kc0ucTNAUg~wrU9fCfY<?uLF({<|NsA^NZZ%_ zVZesLit7IUV8DiflGyZs#6ZBF;qMP@7%Vvm2vB$l0I>oP6B}O4_ZS$EF;FW*^#N22 O76YoQM#3O5N&x_^X-5(O diff --git a/index.php b/index.php index de0d66a..36997f0 100644 --- a/index.php +++ b/index.php @@ -36,6 +36,8 @@ $largeur = filter_input(INPUT_GET, 'colonnes', FILTER_VALIDATE_INT, [ ]); $grille = new Grille($hauteur, $largeur, $id); +$grille->current(); + ?> <!DOCTYPE HTML> @@ -78,69 +80,73 @@ $grille = new Grille($hauteur, $largeur, $id); </tbody> </table> </h1> - <table class="grille"> - <tr> - <th></th> - <?php for ($c = 0; $c < $largeur; $c++): ?> - <th><?= chr($c + 65) ?></th> - <?php endfor; ?> - <th></th> - </tr> - <?php for ($l = 0; $l < $hauteur; $l++): ?> + <?php if ($grille->valid()): ?> + <table class="grille"> <tr> - <th><?= $l + 1 ?></th> + <th></th> <?php for ($c = 0; $c < $largeur; $c++): ?> - <td class="case <?= $grille->grille[$l][$c] == " " ? "noire" : "blanche" ?>"> - <?php if ($grille->grille[$l][$c] == " "): ?> - <input type="text" maxlength="1" size="1" value=" " disabled /> - <?php else: ?> - <input type="text" maxlength="1" size="1" pattern="[A-Z]" /> - <?php endif; ?> - </td> + <th><?= chr($c + 65) ?></th> <?php endfor; ?> + <th></th> </tr> - <?php endfor; ?> - </table> - <div class="definitions"> - <div class="horizontales"> - <h2>Horizontalement</h2> - <ol> - <?php for ($l = 0; $l < $hauteur; $l++): ?> - <li> - <?php $definitions = $dico[$grille->get_ligne($l, $largeur)] ?> - <?php if (count($definitions) == 1): ?> - <?= $definitions[0] ?> - <?php else: ?> - <ol> - <?php foreach ($dico[$grille->get_ligne($l, $largeur)] as $definition) : ?> - <li><?= $definition ?></li> - <?php endforeach ?> - </ol> - <?php endif ?> - </li> - <?php endfor; ?> - </ol> + <?php for ($l = 0; $l < $hauteur; $l++): ?> + <tr> + <th><?= $l + 1 ?></th> + <?php for ($c = 0; $c < $largeur; $c++): ?> + <td class="case <?= $grille->grille[$l][$c] == " " ? "noire" : "blanche" ?>"> + <?php if ($grille->grille[$l][$c] == " "): ?> + <input type="text" maxlength="1" size="1" value=" " disabled /> + <?php else: ?> + <input type="text" maxlength="1" size="1" pattern="[A-Z]" /> + <?php endif; ?> + </td> + <?php endfor; ?> + </tr> + <?php endfor; ?> + </table> + <div class="definitions"> + <div class="horizontales"> + <h2>Horizontalement</h2> + <ol> + <?php for ($l = 0; $l < $hauteur; $l++): ?> + <li> + <?php $definitions = $dico[$grille->get_ligne($l, $largeur)] ?> + <?php if (count($definitions) == 1): ?> + <?= $definitions[0] ?> + <?php else: ?> + <ol> + <?php foreach ($dico[$grille->get_ligne($l, $largeur)] as $definition) : ?> + <li><?= $definition ?></li> + <?php endforeach ?> + </ol> + <?php endif ?> + </li> + <?php endfor; ?> + </ol> + </div> + <div class="verticales"> + <h2>Verticalement</h2> + <ol type="A"> + <?php for ($c = 0; $c < $largeur; $c++): ?> + <li> + <?php $definitions = $dico[$grille->get_colonne($c, $hauteur)] ?> + <?php if (count($definitions) == 1): ?> + <?= $definitions[0] ?> + <?php else: ?> + <ol> + <?php foreach ($dico[$grille->get_colonne($c, $hauteur)] as $definition) : ?> + <li><?= $definition ?></li> + <?php endforeach ?> + </ol> + <?php endif ?> + </li> + <?php endfor; ?> + </ol> + </div> </div> - <div class="verticales"> - <h2>Verticalement</h2> - <ol type="A"> - <?php for ($c = 0; $c < $largeur; $c++): ?> - <li> - <?php $definitions = $dico[$grille->get_colonne($c, $hauteur)] ?> - <?php if (count($definitions) == 1): ?> - <?= $definitions[0] ?> - <?php else: ?> - <ol> - <?php foreach ($dico[$grille->get_colonne($c, $hauteur)] as $definition) : ?> - <li><?= $definition ?></li> - <?php endforeach ?> - </ol> - <?php endif ?> - </li> - <?php endfor; ?> - </ol> - </div> - </div> + <?php else: ?> + <h3 class="erreur">Erreur de génération de la grille</h3> + <?php endif ?> <input type="hidden" id="lignes" <?php if (isset($_GET["lignes"])): ?>name="lignes" <?php endif ?>value="<?= $hauteur ?>" /> <input type="hidden" id="colonnes" <?php if (isset($_GET["colonnes"])): ?>name="colonnes" <?php endif ?>value="<?= $largeur ?>" /> diff --git a/style.css b/style.css index 1e32290..22d4e88 100644 --- a/style.css +++ b/style.css @@ -130,6 +130,10 @@ table.grille { text-wrap: nowrap; } +.erreur { + text-align: center; +} + button[type='submit'] { width: fit-content; margin: 0 auto;