Compare commits

..

1 Commits

Author SHA1 Message Date
13fcdf05fb grand dico 2025-05-08 01:47:58 +02:00
19 changed files with 973667 additions and 2987 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
__pycache__/
test*.*
*.py
*.py
dico2.csv
wiktionaryXfr2010.7z

View File

@ -2,9 +2,6 @@
include_once "dico.php";
const ECART_TYPE_ALEA = 5;
$randmax = mt_getrandmax() + 1;
function gaussienne($moyenne = 0, $ecartType = 1.0): float {
global $randmax;
@ -85,7 +82,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, ECART_TYPE_ALEA);
$lettres_communes[$lettre] = count($lettres_ligne->branches[$lettre]) * count($lettres_colonne->branches[$lettre]) * gaussienne(1, 5);
}
uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
return $lettres_communes[$b] <=> $lettres_communes[$a];
@ -96,18 +93,18 @@ class Grille implements ArrayAccess
$this->grille[$y][$x] = $lettre;
// Omission des lettres isolées
if ($lettre == CASE_NOIRE
&& ($y - 2 < 0 || $this->grille[$y - 2][$x] == CASE_NOIRE)
&& ($y - 1 < 0 || $x - 1 < 0 || $this->grille[$y - 1][$x - 1] == CASE_NOIRE)
&& ($y - 1 < 0 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == CASE_NOIRE)
if ($lettre == " "
&& ($y - 2 < 0 || $this->grille[$y - 2][$x] == " ")
&& ($y - 1 < 0 || $x - 1 < 0 || $this->grille[$y - 1][$x - 1] == " ")
&& ($y - 1 < 0 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == " ")
) {
continue;
}
// Omission des doublons
$mots = [];
if ($x == $this->largeur - 1) $mots = explode(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
else if ($lettre == CASE_NOIRE) $mots = explode(CASE_NOIRE, $this->get_ligne($y, $x));
if ($x == $this->largeur - 1) $mots = explode(" ", $this->get_ligne($y, $this->largeur));
else if ($lettre == " ") $mots = explode(" ", $this->get_ligne($y, $x));
else $mots = [];
$this->lignes[$y] = array_filter($mots, function ($mot) {
return strlen($mot) >= 2;
@ -119,7 +116,7 @@ class Grille implements ArrayAccess
}
if ($y == $this->hauteur - 1) {
$mots = explode(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
$mots = explode(" ", $this->get_colonne($x, $this->hauteur));
foreach ($mots as $rang => $mot) {
if (strlen($mot) < 2) continue;
if (strlen($mot > 2) && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2;
@ -160,9 +157,13 @@ class Grille implements ArrayAccess
return hash('sha256', $string);
}
public function __toString() {
return implode(
PHP_EOL,
public function save($id)
{
session_id($id);
session_start(["use_cookies" => false]);
$_SESSION["$this->largeur,$this->hauteur"] = implode(
"",
array_map(
function ($ligne) {
return implode("", $ligne);
@ -172,42 +173,30 @@ class Grille implements ArrayAccess
);
}
public function save($id)
{
if (session_status() === PHP_SESSION_ACTIVE) {
session_write_close();
}
session_id("$this->largeur,$this->hauteur,$id");
session_start(["use_cookies" => false]);
$_SESSION["grille"] = (string)$this;
}
public function load($id)
{
session_id("$this->largeur,$this->hauteur,$id");
session_id($id);
session_start(["use_cookies" => false]);
if (!isset($_SESSION["grille"])) {
if (!isset($_SESSION["$this->largeur,$this->hauteur"])) {
return false;
}
foreach (explode(PHP_EOL, $_SESSION["grille"]) as $y => $ligne) {
foreach (str_split($_SESSION["$this->largeur,$this->hauteur"], $this->largeur) as $y => $ligne) {
foreach (str_split($ligne) as $x => $lettre) {
$this->grille[$y][$x] = $lettre;
}
}
for ($y = 0; $y < $this->hauteur; $y++) {
$mots = explode(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
$mots = explode(" ", $this->get_ligne($y, $this->largeur));
$this->lignes[$y] = array_filter($mots, function ($mot) {
return strlen($mot) >= 2;
});
}
for ($x = 0; $x < $this->largeur; $x++) {
$mots = explode(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
$mots = explode(" ", $this->get_colonne($x, $this->hauteur));
$this->colonnes[$x] = array_filter($mots, function ($mot) {
return strlen($mot) >= 2;
});

View File

@ -6,8 +6,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
private $nb_branches = 0;
public function arraySet($cles, $valeur) {
$cle = $cles[0];
$this->nb_branches++;
$cle = $cles[0];
$cles = array_slice($cles, 1);
if ($cles == []) {
$this->branches[$cle] = $valeur;

976394
dico.csv

File diff suppressed because one or more lines are too long

View File

@ -2,13 +2,18 @@
include_once "Trie.php";
const CASE_NOIRE = " ";
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 = [[new Trie()]];
$dico = [[""]];
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
$dico[] = new Trie();
}
@ -23,19 +28,20 @@ function dico($longueur_max) {
$mot = $ligne[0];
$definitions = array_slice($ligne, 1);
$mot = str_replace("-", CASE_NOIRE, $mot);
$mot = str_replace("-", " ", $mot);
$mot = $transliterator->transliterate($mot);
if (strpos($mot, CASE_NOIRE) !== false) {
$mots = explode(CASE_NOIRE, $mot);
if (strpos($mot, " ") !== false) {
$mots = explode(" ", $mot);
$nb_mots = count($mots);
$mot = implode("", $mots);
foreach($definitions as $i => $definition) {
$definitions[$i] = "$definition#$nb_mots";
$definitions[$i] .= " ($nb_mots mots)";
}
}
$dico[strlen($mot)][$mot] = $definitions;
$longueur = strlen($mot);
$dico[$longueur][$mot] = $definitions;
}
fclose($lecteur);
}
@ -44,12 +50,14 @@ 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 = 1; $position_espace + 1 < $longueur; $position_espace++) {
for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {
$mots_suivants = $dico[$longueur - $position_espace - 1];
foreach ($dico[$position_espace]->arrayIterator() as $premier_mot => $definition) {
$premier_mot[] = CASE_NOIRE;
$premier_mot[] = " ";
$dico[$longueur]->arraySet($premier_mot, $mots_suivants);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 518 B

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@ -26,48 +26,21 @@ $largeur = filter_input(INPUT_GET, 'colonnes', FILTER_VALIDATE_INT, [
]
]);
$grille_valide = false;
$grille = new Grille($hauteur, $largeur);
$basedir = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].dirname($_SERVER["DOCUMENT_URI"]);
if (isset($_GET["grille"]) || $_GET["grille"] == "") {
$id = htmlspecialchars($_GET["grille"]);
} else {
if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
do {
$id = uniqid();
} while (!$grille->genere($id));
$grille_valide = true;
$_GET["grille"] = $id;
header("Location: $basedir/?" . http_build_query($_GET));
header("Location: " . dirname($_SERVER['DOCUMENT_URI']) . "?" . http_build_query($_GET));
exit;
}
?>
<!DOCTYPE HTML>
<html lang="fr-FR" dir="ltr" prefix="og: https://ogp.me/ns#">
<head>
<meta charset="utf-8">
<title>🄼🄾🅃🅂▣🄲🅁🄾🄸🅂🄴🅂</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" type="image/svg+xml" href="favicons/favicon.svg">
<link rel="icon" type="image/png" href="favicons/favicon-96x96.png" sizes="96x96" />
<link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-title" content="🄼🄾🅃🅂 🄲🅁🄾🄸🅂🄴🅂" />
<link rel="manifest" href="site.webmanifest" />
<meta property="og:title" content="🄼🄾🅃🅂▣🄲🅁🄾🄸🅂🄴🅂"/>
<meta property="og:type" content="game"/>
<meta property="og:url" content="<?=$basedir?>"/>
<meta property="og:image" content="<?=$basedir?>/thumbnail.php?grille=<?=$id?>&lignes=<?=$hauteur?>&colonnes=<?=$largeur?>&largeur=1200&hauteur=630"/>
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="630"/>
<meta property="og:locale" content="fr_FR"/>
<meta property="og:site_name" content="<?=$_SERVER["HTTP_HOST"]?>"/>
</head>
$id = htmlspecialchars($_GET["grille"]);
<?php
$grille_valide = $grille_valide || $grille->load($id) || $grille->genere($id);
$grille_valide = $grille->load($id) || $grille->genere($id);
mt_srand(crc32($id));
if ($grille_valide) {
@ -77,20 +50,7 @@ if ($grille_valide) {
foreach ($grille->lignes[$y] as $mot) {
$definitions = $grille->dico[strlen($mot)][$mot];
if (count($definitions)) {
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (strpos($definition, "#") !== false) {
[$definition, $nb_mots] = explode("#", $definition);
$nb_mots = " <small>($nb_mots mots)</small>";
} else {
$nb_mots = "";
}
if (strpos($definition, "@") !== false) {
[$definition, $auteur] = explode("@", $definition);
$auteur = " <small><em>$auteur</em></small>";
} else {
$auteur = "";
}
$definitions_horizontales[$y][] = $definition;
$definitions_horizontales[$y][] = $definitions[mt_rand(0, count($definitions) - 1)];
}
}
}
@ -100,25 +60,22 @@ if ($grille_valide) {
foreach ($grille->colonnes[$x] as $mot) {
$definitions = $grille->dico[strlen($mot)][$mot];
if (count($definitions)) {
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (strpos($definition, "#") !== false) {
[$definition, $nb_mots] = explode("#", $definition);
$nb_mots = " <small>($nb_mots mots)</small>";
} else {
$nb_mots = "";
}
if (strpos($definition, "@") !== false) {
[$definition, $auteur] = explode("@", $definition);
$auteur = " <small><em>$auteur</em></small>";
} else {
$auteur = "";
}
$definitions_verticales[$x][] = $definition . $nb_mots . $auteur;
$definitions_verticales[$x][] = $definitions[mt_rand(0, count($definitions) - 1)];
}
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>MOTS■CROISES</title>
<link rel="stylesheet" href="style.css">
<link rel="icon" href="favicon.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form id="grilleForm" method="get" location=".">
@ -165,9 +122,9 @@ if ($grille_valide) {
<tr>
<th><?= $y + 1 ?></th>
<?php for ($x = 0; $x < $largeur; $x++): ?>
<?php if ($grille[$y][$x] == CASE_NOIRE): ?>
<?php if ($grille[$y][$x] == " "): ?>
<td class="case noire">
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value="<?= CASE_NOIRE ?>" disabled />
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value=" " disabled />
</td>
<?php else: ?>
<td class="case blanche">
@ -220,19 +177,18 @@ if ($grille_valide) {
<?php endforeach; ?>
</ol>
</div>
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
<?php else: http_response_code(500); ?>
<h3 class="erreur">Erreur de génération de la grille</h3>
<?php endif ?>
</div>
<div class="nouvelle-grille">
<img src="favicons/favicon.svg" width="16" height="16">
<img src="favicon.svg" width="16" height="16">
<button type="submit">Nouvelle grille</button>
de
<input type="number" id="lignes"<?= isset($_GET["lignes"])? ' name="lignes"': "" ?> value="<?= $hauteur ?>" min="<?=HAUTEUR_MIN?>" max="<?=HAUTEUR_MAX?>"/>
<input type="number" id="lignes"<?= isset($_GET["lignes"])? 'name="lignes"': "" ?> value="<?= $hauteur ?>" min="<?=HAUTEUR_MIN?>" max="<?=HAUTEUR_MAX?>"/>
lignes et
<input type="number" id="colonnes"<?= isset($_GET["colonnes"])? ' name="colonnes"': "" ?> value="<?= $largeur ?>" min="<?=LARGEUR_MIN?>" max="<?=LARGEUR_MAX?>"/>
<input type="number" id="colonnes"<?= isset($_GET["colonnes"])? 'name="colonnes"': "" ?> value="<?= $largeur ?>" min="<?=LARGEUR_MIN?>" max="<?=LARGEUR_MAX?>"/>
colonnes
</div>
</form>

View File

@ -6,7 +6,7 @@ async function sha256(text) {
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
}
let inputs = Array.from(grilleForm.querySelectorAll(".grille input"));
let inputs = grilleForm.querySelectorAll(".grille input");
let largeur = Number(colonnes.value);
let nb_cases = inputs.length;
let index = 0;

View File

@ -1,21 +0,0 @@
{
"name": "🄼🄾🅃🅂 🄲🅁🄾🄸🅂🄴🅂",
"short_name": "🄼🄾🅃🅂 🄲🅁🄾🄸🅂🄴🅂",
"icons": [
{
"src": "favicons/web-app-manifest-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "favicons/web-app-manifest-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}

View File

@ -108,7 +108,6 @@ h2 {
}
.grille input[disabled] {
color: black;
background-color: black;
}

View File

@ -1,63 +0,0 @@
<?php
// Paramètres de largeur, hauteur, lignes et colonnes
$largeur = isset($_GET['largeur']) ? (int)$_GET['largeur'] : 200; // Valeur par défaut : 200
$hauteur = isset($_GET['hauteur']) ? (int)$_GET['hauteur'] : 200; // Valeur par défaut : 200
$lignes = isset($_GET['lignes']) ? (int)$_GET['lignes'] : 8; // Valeur par défaut : 4
$colonnes = isset($_GET['colonnes']) ? (int)$_GET['colonnes'] : 8; // Valeur par défaut : 4
$bordure = 6;
// Créer une image vide
$image = imagecreate($largeur, $hauteur);
// Couleurs
$blanc = imagecolorallocate($image, 255, 255, 255);
$noir = imagecolorallocate($image, 0, 0, 0);
// Remplir l'image avec un fond blanc
imagefill($image, 0, 0, $blanc);
// Calculer la taille et la position des cases
$cote = (int)min(($largeur - 2 * $bordure) / $colonnes, ($hauteur - 2 * $bordure) / $lignes);
$haut = (int)(($hauteur - $lignes * $cote - 2 * $bordure) / 2) + $bordure;
$gauche = (int)(($largeur - $colonnes * $cote - 2 * $bordure) / 2) + $bordure;
$bas = $haut + $lignes * $cote;
$droite = $gauche + $colonnes * $cote;
// Dessiner les bordures extérieures (3 pixels d'épaisseur)
imagesetthickness($image, $bordure);
imagerectangle($image, $gauche, $haut, $droite, $bas, $noir);
// Dessiner les lignes et colonnes internes (1 pixel d'épaisseur)
imagesetthickness($image, 2);
for ($x = $gauche; $x <= $droite; $x += $cote) {
imageline($image, $x, $haut, $x, $bas, $noir); // Lignes verticales
}
for ($y = $haut; $y <= $bas; $y += $cote) {
imageline($image, $gauche, $y, $droite, $y, $noir); // Lignes horizontales
}
// Noicir les cases
if (isset($_GET["grille"])) {
include_once "Grille.php";
$grille = new Grille($lignes, $colonnes);
$id = htmlspecialchars($_GET["grille"]);
$grille->load($id) || $grille->genere($id);
for ($y = 0; $y < $lignes; $y++) {
for ($x = 0; $x < $colonnes; $x++) {
if ($grille[$y][$x] == CASE_NOIRE) {
imagefilledrectangle($image, $gauche + $x * $cote, $haut + $y * $cote, $gauche + ($x + 1) * $cote, $haut + ($y + 1) * $cote, $noir);
}
}
}
}
// Envoyer l'image au navigateur
header('Content-Type: image/png');
imagepng($image);
// Libérer la mémoire
imagedestroy($image);
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB