From b9eb5b725ffca7ebb14d99718248758bdb0afa9f Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 24 Apr 2025 18:23:57 +0200 Subject: [PATCH] identifiant unique de grille --- Grille.php | 4 ++-- dico.php | 20 +++++++++++++++++--- index.php | 23 ++++++++++++++++++----- style.css | 7 ++++--- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Grille.php b/Grille.php index 60b7625..8a7b968 100644 --- a/Grille.php +++ b/Grille.php @@ -14,7 +14,7 @@ class Grille { private $mots_commencant_par; private $mots_utilises = []; - public function __construct($hauteur, $largeur) { + public function __construct($hauteur, $largeur, $id="") { $this->hauteur = $hauteur; $this->largeur = $largeur; $this->grille = array_fill(0, $hauteur, array_fill(0, $largeur, '.')); @@ -27,7 +27,7 @@ class Grille { $this->mots_commencant_par = []; foreach ($dimensions as $longueur) { $this->mots_commencant_par[$longueur] = []; - foreach(mots_espaces($longueur, MIN_LETTRES) as $mot) { + foreach(mots_espaces($longueur, MIN_LETTRES, crc32($id)) as $mot) { for ($i = 0; $i <= $longueur; $i++) { $debut = substr($mot, 0, $i); if (!isset($this->mots_commencant_par[$longueur][$debut])) { diff --git a/dico.php b/dico.php index d849bb2..bee659c 100644 --- a/dico.php +++ b/dico.php @@ -21,14 +21,28 @@ foreach ($dico as $mot => $definition) { } $mots_de_n_lettres[$n][] = $mot; } -foreach ($mots_de_n_lettres as $n => $mots) { - shuffle($mots_de_n_lettres[$n]); + +function fisherYatesShuffle(&$items, $seed) +{ + @mt_srand($seed); + for ($i = count($items) - 1; $i > 0; $i--) + { + $j = @mt_rand(0, $i); + $tmp = $items[$i]; + $items[$i] = $items[$j]; + $items[$j] = $tmp; + } } -function mots_espaces($max, $min=0) { +function mots_espaces($max, $min=0, $seed=0) { global $mots_de_n_lettres; global $dico; + if ($seed) { + fisherYatesShuffle($mots_de_n_lettres[$max], $seed); + } else { + shuffle($mots_de_n_lettres[$max]); + } foreach($mots_de_n_lettres[$max] as $mot) { yield $mot; } diff --git a/index.php b/index.php index 0f655f0..021a5a0 100644 --- a/index.php +++ b/index.php @@ -3,28 +3,41 @@ ini_set('display_errors', 1); ini_set('html_errors', 1); ini_set('error_reporting', E_ALL); +const HAUTEUR_PAR_DEFAUT = 6; +const LARGEUR_PAR_DEFAUT = 6; + + +$id = filter_input(INPUT_GET, 'grille', FILTER_VALIDATE_REGEXP, [ + "options" => [ + "regexp" => "/^[a-f0-9]{13}$/" + ] +]); +if (!$id) { + header("Location: " . $_SERVER['PHP_SELF'] . "?grille=" . uniqid() . "&" . http_build_query($_GET)); + exit; +} + + include_once "dico.php"; include_once "Grille.php"; -const HAUTEUR_PAR_DEFAUT = 6; -const LARGEUR_PAR_DEFAUT = 6; $hauteur = filter_input(INPUT_GET, 'lignes', FILTER_VALIDATE_INT, [ "options" => [ "default" => HAUTEUR_PAR_DEFAUT, "min_range" => 2, - "max_range" => 10 + "max_range" => 30 ] ]); $largeur = filter_input(INPUT_GET, 'colonnes', FILTER_VALIDATE_INT, [ "options" => [ "default" => LARGEUR_PAR_DEFAUT, "min_range" => 2, - "max_range" => 10 + "max_range" => 30 ] ]); -$grille = new Grille($hauteur, $largeur); +$grille = new Grille($hauteur, $largeur, $id); ?> diff --git a/style.css b/style.css index 77f08c9..66d5c86 100644 --- a/style.css +++ b/style.css @@ -16,7 +16,8 @@ h1 td { width: 0.7em; } -h1, h2 { +h1, +h2 { font-variant-caps: petite-caps; text-align: center; } @@ -79,5 +80,5 @@ h1, h2 { } .definitions li::marker { - font-weight: bold; -} \ No newline at end of file + font-weight: bold; +}