Compare commits

...

22 Commits

Author SHA1 Message Date
4a51ed72eb n'afficher que le mot courant dans l'infobulle 2025-12-04 18:09:01 +01:00
329d207930 petits changements 2025-12-04 15:32:59 +01:00
cac6b19ed9 Nettoyage du dictionnaire 2025-12-03 18:41:03 +01:00
5148e5f2d2 espace insécable pour les doubles ponctuations 2025-12-03 18:18:57 +01:00
1b95ef9cee moins de cases noires ? 2025-12-03 18:11:45 +01:00
9587f1e57f supression du debug 2025-12-03 17:26:59 +01:00
563ba7ed0a rechangement de format du dictionnaire 2025-12-03 17:26:36 +01:00
974e2c203c truc inutile 2025-12-03 11:26:55 +01:00
00547c2c00 ajout définition dentiste 2025-11-29 03:38:48 +01:00
95d21a22c9 Ajout Desproges 2025-10-19 15:46:29 +02:00
822d353775 Nouvelles définitions
Signed-off-by: adrien <adrien@malingrey.fr>
2025-10-11 11:49:36 +02:00
e754e6e44b ommission des lettres isolées sur la dernière ligne 2025-08-22 13:09:00 +02:00
8287699a4b méthodes magiques 2025-08-22 11:04:42 +02:00
d3b11df015 méthodes magiques 2025-08-22 10:56:06 +02:00
6635adf26a la navigation au clavier saute les cases noires 2025-08-19 17:57:02 +02:00
c2e4b8ae53 plus rapide 2025-08-19 16:54:06 +02:00
5aa5da8c53 correction formattage définitions 2025-08-19 16:53:49 +02:00
d862dc572d corrections 2025-08-19 16:48:52 +02:00
c3986e70a3 ajustements 2025-08-01 23:57:29 +02:00
e19bb9d2dc ajout d'une définition 2025-07-23 18:10:59 +02:00
468a6a9231 Merge remote-tracking branch 'origin/HEAD' 2025-07-23 18:01:53 +02:00
c62afa80cc 7 2025-05-23 20:32:54 +02:00
8 changed files with 4214 additions and 2947 deletions

View File

@@ -2,16 +2,13 @@
include_once "dico.php";
const ECART_TYPE_ALEA = 5;
const ECART_TYPE = 5.0;
$randmax = mt_getrandmax() + 1;
function gaussienne($moyenne = 0, $ecartType = 1.0): float {
global $randmax;
$u = 0;
$v = 0;
$u = (mt_rand() + 1) / $randmax;
$v = (mt_rand() + 1) / $randmax;
@@ -19,6 +16,26 @@ function gaussienne($moyenne = 0, $ecartType = 1.0): float {
return $z * $ecartType + $moyenne;
}
function explode_pos(string $separator, string $string): array {
$mots = [];
$mot = "";
$longueur = strlen($string);
for ($i = 0; $i < $longueur; $i++) {
$lettre = $string[$i];
if ($lettre == $separator) {
$mots[$i] = $mot;
$mot = "";
} else {
$mot .= $lettre;
}
}
$mots[$i] = $mot;
return $mots;
}
class Grille implements ArrayAccess
{
@@ -83,19 +100,27 @@ class Grille implements ArrayAccess
];
foreach($this->lignes as $y => $mots) {
$this->definitions["horizontales"][$y] = [];
foreach($mots as $mot) {
foreach($mots as $fin => $mot) {
$definitions = $this->dico[strlen($mot)][$mot];
if (count($definitions)) {
$this->definitions["horizontales"][$y][] = $definitions[mt_rand(0, count($definitions) - 1)];
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (isset($definitions["nb_mots"])) {
$definition["nb_mots"] = $definitions["nb_mots"];
}
$this->definitions["horizontales"][$y][$fin] = $definition;
}
}
}
foreach($this->colonnes as $x => $mots) {
$this->definitions["verticales"][$x] = [];
foreach($mots as $mot) {
foreach($mots as $fin => $mot) {
$definitions = $this->dico[strlen($mot)][$mot];
if (count($definitions)) {
$this->definitions["verticales"][$x][] = $definitions[mt_rand(0, count($definitions) - 1)];
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
if (isset($definitions["nb_mots"])) {
$definition["nb_mots"] = $definitions["nb_mots"];
}
$this->definitions["verticales"][$x][$fin] = $definition;
}
}
}
@@ -126,29 +151,38 @@ 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] = log(count($lettres_ligne->branches[$lettre])) * count($lettres_colonne->branches[$lettre]) * gaussienne(ECART_TYPE, ECART_TYPE);
}
uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
return $lettres_communes[$b] <=> $lettres_communes[$a];
});
$lettres_communes = array_slice($lettres_communes, 0, 3);
uksort($lettres_communes, function($a, $b) {
return ($a == CASE_NOIRE)? 1 : -1;
});
$lettres_communes = array_slice($lettres_communes, 0, 2);
foreach ($lettres_communes as $lettre => $_) {
$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)
) {
continue;
}
if ($lettre == CASE_NOIRE) {
if (($y < 2 || $this->grille[$y - 2][$x] == CASE_NOIRE)
&& ($y < 1 || $x == 0 || $this->grille[$y - 1][$x - 1] == CASE_NOIRE)
&& ($y < 1 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == CASE_NOIRE)
) continue;
if ($y == $this->hauteur - 1
&& ($x < 2 || $this[$y][$x - 2] == CASE_NOIRE)
&& ($x < 1 || $this[$y - 1][$x - 1] == CASE_NOIRE)
) continue;
} else if ($x == $this->largeur - 1 && $y == $this->hauteur - 1
&& $this[$y][$x - 1] == CASE_NOIRE
&& $this[$y-1][$x] == CASE_NOIRE
) 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_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
else if ($lettre == CASE_NOIRE) $mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $x));
else $mots = [];
$this->lignes[$y] = array_filter($mots, function ($mot) {
return strlen($mot) >= 2;
@@ -160,7 +194,7 @@ class Grille implements ArrayAccess
}
if ($y == $this->hauteur - 1) {
$mots = explode(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
$mots = explode_pos(CASE_NOIRE, $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;

View File

@@ -1,23 +1,27 @@
<?php
class Trie implements ArrayAccess, IteratorAggregate, Countable {
class Trie implements ArrayAccess, IteratorAggregate, Countable
{
public array $branches = [];
private $nb_branches = 0;
public function arraySet($cles, $valeur) {
public function arraySet($cles, $valeur)
{
$cle = $cles[0];
$this->nb_branches++;
$cles = array_slice($cles, 1);
if ($cles == []) {
$this->branches[$cle] = $valeur;
} else {
if (!isset($this->branches[$cle])) $this->branches[$cle] = new Trie();
if (!isset($this->branches[$cle]))
$this->branches[$cle] = new Trie();
$this->branches[$cle]->arraySet($cles, $valeur);
}
}
public function arrayExists($cles) {
public function arrayExists($cles)
{
$cle = $cles[0];
$cles = array_slice($cles, 1);
if ($cles == []) {
@@ -27,7 +31,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
}
}
public function &arrayGet($cles) {
public function &arrayGet($cles)
{
$cle = $cles[0];
$cles = array_slice($cles, 1);
if ($cles == []) {
@@ -37,7 +42,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
}
}
public function arrayUnset($cles) {
public function arrayUnset($cles)
{
$cle = $cles[0];
$cles = array_slice($cles, 1);
if ($cles == []) {
@@ -52,10 +58,45 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
}
}
public function arrayIterator() {
// ArrayAccess
public function offsetSet($array, $valeur): void
{
if (is_string($array)) {
$array = str_split($array);
}
$this->arraySet($array, $valeur);
}
public function offsetExists($array): bool
{
if (is_string($array)) {
$array = str_split($array);
}
return $this->arrayExists($array);
}
public function &offsetGet($array): mixed
{
if (is_string($array)) {
$array = str_split($array);
}
return $this->arrayGet($array);
}
public function offsetUnset($array): void
{
if (is_string($array)) {
$array = str_split($array);
}
$this->arrayUnset($array);
}
// IteratorAggregate
public function getIterator(): Traversable
{
foreach ($this->branches as $cle => $branche) {
if ($branche instanceof Trie) {
foreach($branche->arrayIterator() as $sous_cles => $feuille) {
foreach ($branche->getIterator() as $sous_cles => $feuille) {
yield array_merge([$cle], $sous_cles) => $feuille;
}
} else {
@@ -64,32 +105,9 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable {
}
}
// ArrayAccess
public function offsetSet($string, $valeur): void {
$this->arraySet(str_split($string), $valeur);
}
public function offsetExists($string): bool {
return $this->arrayExists(str_split($string));
}
public function &offsetGet($string): mixed {
return $this->arrayGet(str_split($string));
}
public function offsetUnset($string): void {
$this->arrayUnset(str_split($string));
}
// IteratorAggregate
public function getIterator(): Traversable {
foreach($this->arrayIterator() as $array => $valeur) {
yield implode("", $array) => $valeur;
}
}
// Countable
public function count(): int {
public function count(): int
{
return $this->nb_branches;
}
}

2818
dico.csv

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,21 @@
<?php
include_once "Trie.php";
const CASE_NOIRE = " ";
const DEFINITION = 0;
const AUTEUR = 1;
function dico($longueur_max) {
$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();
}
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
if (($lecteur = fopen("dico.tsv", "r")) !== FALSE) {
$entete = fgetcsv($lecteur, 0, "\t");
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
if (
@@ -22,7 +25,7 @@ function dico($longueur_max) {
) continue;
$mot = $ligne[0];
$definitions = array_slice($ligne, 1);
$definition = array_slice($ligne, 1);
$mot = str_replace("-", CASE_NOIRE, $mot);
$mot = $transliterator->transliterate($mot);
@@ -30,12 +33,16 @@ function dico($longueur_max) {
$mots = explode(CASE_NOIRE, $mot);
$nb_mots = count($mots);
$mot = implode("", $mots);
foreach($definitions as $i => $definition) {
$definitions[$i] = "$definition#$nb_mots";
}
} else {
$nb_mots = 1;
}
$dico[strlen($mot)][$mot] = $definitions;
if (array_key_exists($mot, $dico)) {
$dico[strlen($mot)][$mot][] = $definition;
} else {
$dico[strlen($mot)][$mot] = [$definition];
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
}
}
fclose($lecteur);
}
@@ -43,14 +50,14 @@ function dico($longueur_max) {
return $dico;
}
function mots_espaces($longueur_max) {
function mots_espaces($longueur_max, $longueur_min=1) {
$dico = dico($longueur_max);
for ($longueur = 1; $longueur <= $longueur_max; $longueur++) {
for ($position_espace = 1; $position_espace + 1 < $longueur; $position_espace++) {
for ($longueur = $longueur_max; $longueur >= $longueur_min + 1; $longueur--) {
for ($position_espace = $longueur - $longueur_min - 1; $position_espace >= $longueur_min; $position_espace--) {
$mots_suivants = $dico[$longueur - $position_espace - 1];
foreach ($dico[$position_espace]->arrayIterator() as $premier_mot => $definition) {
foreach ($dico[$position_espace] as $premier_mot => $definition) {
$premier_mot[] = CASE_NOIRE;
$dico[$longueur]->arraySet($premier_mot, $mots_suivants);
$dico[$longueur][$premier_mot] = $mots_suivants;
}
}
}

3995
dico.tsv Normal file

File diff suppressed because it is too large Load Diff

109
index.php
View File

@@ -1,13 +1,15 @@
<?php
include_once "Grille.php";
const HAUTEUR_DEFAUT = 8;
const HAUTEUR_MIN = 2;
const HAUTEUR_MAX = 10;
const LARGEUR_DEFAUT = 8;
const LARGEUR_MIN = 2;
const LARGEUR_MAX = 10;
const HAUTEUR_DEFAUT = 7;
const HAUTEUR_MIN = 2;
const HAUTEUR_MAX = 10;
const LARGEUR_DEFAUT = 7;
const LARGEUR_MIN = 2;
const LARGEUR_MAX = 10;
$hauteur = filter_input(INPUT_GET, 'lignes', FILTER_VALIDATE_INT, [
@@ -43,19 +45,26 @@ if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
}
function formatter_definition($definition) {
if (strpos($definition, "#") !== false) {
[$definition, $nb_mots] = explode("#", $definition);
if (isset($definition["nb_mots"]) && $definition["nb_mots"] > 1){
$nb_mots = $definition["nb_mots"];
$nb_mots = " <small>($nb_mots mots)</small>";
} else {
$nb_mots = "";
}
if (strpos($definition, "@") !== false) {
[$definition, $auteur] = explode("@", $definition);
if (array_key_exists(AUTEUR, $definition)) {
$auteur = $definition[AUTEUR];
$auteur = " <small><em>$auteur</em></small>";
} else {
$auteur = "";
}
return $definition;
return ucfirst($definition[DEFINITION]) . $nb_mots . $auteur;
}
function mot_courant($mots, $position) {
foreach ($mots as $fin => $mot) {
if ($position <= $fin) return $mot;
}
return [];
}
?>
<!DOCTYPE HTML>
@@ -85,33 +94,35 @@ function formatter_definition($definition) {
<body>
<form id="grilleForm" method="get" location=".">
<h1 class="large width">
<table>
<tbody>
<tr>
<td colspan="2"></td>
<td>M</td>
</tr>
<tr>
<td>c</td>
<td>r</td>
<td>o</td>
<td>i</td>
<td>s</td>
<td>é</td>
<td>s</td>
</tr>
<tr>
<td colspan="2"></td>
<td>t</td>
</tr>
<tr>
<td colspan="2"></td>
<td>s</td>
</tr>
</tbody>
</table>
<a href=".">
<table>
<tbody>
<tr>
<td colspan="2"></td>
<td>M</td>
</tr>
<tr>
<td>c</td>
<td>r</td>
<td>o</td>
<td>i</td>
<td>s</td>
<td>é</td>
<td>s</td>
</tr>
<tr>
<td colspan="2"></td>
<td>t</td>
</tr>
<tr>
<td colspan="2"></td>
<td>s</td>
</tr>
</tbody>
</table>
</a>
</h1>
<h1 class="small width">Mots■croisés</h1>
<h1 class="small width"><a href=".">Mots■croisés</a></h1>
<div class="grille-et-definitions">
<?php if ($grille_valide): ?>
<div class="grille">
@@ -133,8 +144,18 @@ function formatter_definition($definition) {
</td>
<?php else: ?>
<td class="case blanche">
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" pattern="[A-Z]" placeholder="<?= $grille[$y][$x] ?>"
title="<?= strip_tags("→ " . implode("\n→ ", array_map("formatter_definition", $grille->definitions["horizontales"][$y] ?? [])) . "\n↓ " . implode("\n↓ ", array_map("formatter_definition", $grille->definitions["verticales"][$x] ?? []))) ?>" />
<?php
$title = "";
$definition_horizontale = mot_courant($grille->definitions["horizontales"][$y], $x);
$definition_verticale = mot_courant($grille->definitions["verticales"][$x], $y);
if (isset($definition_horizontale[0])) $title .= "→ " . $definition_horizontale[0];
if (isset($definition_horizontale[1])) $title .= " (" . $definition_horizontale[1] . ")";
if (isset($definition_verticale[0])) $title .= "\n ↓ " . $definition_verticale[0];
if (isset($definition_verticale[1])) $title .= " (" . $definition_verticale[1] . ")";
$title = htmlspecialchars($title);
?>
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" pattern="[A-Z]"
title="<?=$title?>" />
</td>
<?php endif; ?>
<?php endfor; ?>
@@ -149,12 +170,12 @@ function formatter_definition($definition) {
<li>
<?php if (count($definitions)): ?>
<?php if (count($definitions) == 1): ?>
<?= formatter_definition($definitions[0]) ?>
<?= formatter_definition(reset($definitions)) ?>
<?php else: ?>
<ol>
<?php foreach ($definitions as $definition) : ?>
<li><?= formatter_definition($definition) ?></li>
<?php endforeach ?>
<?php foreach ($definitions as $definition) : ?>
<li><?= formatter_definition($definition) ?></li>
<?php endforeach ?>
</ol>
<?php endif ?>
<?php endif ?>
@@ -169,7 +190,7 @@ function formatter_definition($definition) {
<li>
<?php if (count($definitions)): ?>
<?php if (count($definitions) == 1): ?>
<?= formatter_definition($definitions[0]) ?>
<?= formatter_definition(reset($definitions)) ?>
<?php else: ?>
<ol>
<?php foreach ($definitions as $definition) : ?>

View File

@@ -35,26 +35,28 @@ for (let input of inputs) {
};
input.onkeydown = function (event) {
next_input = null;
switch (event.key) {
case "ArrowUp":
next_input = inputs[(input.index - largeur + nb_cases) % nb_cases];
break;
case "ArrowDown":
next_input = inputs[(input.index + largeur) % nb_cases];
break;
case "ArrowLeft":
next_input = inputs[(input.index - 1 + nb_cases) % nb_cases];
break;
case "ArrowRight":
next_input = inputs[(input.index + 1) % nb_cases];
break;
}
if (next_input) {
next_input.focus();
next_input.select();
event.preventDefault();
}
next_input = input;
do {
switch (event.key) {
case "ArrowUp":
next_input = inputs[(next_input.index - largeur + nb_cases) % nb_cases];
break;
case "ArrowDown":
next_input = inputs[(next_input.index + largeur) % nb_cases];
break;
case "ArrowLeft":
next_input = inputs[(next_input.index - 1 + nb_cases) % nb_cases];
break;
case "ArrowRight":
next_input = inputs[(next_input.index + 1) % nb_cases];
break;
default:
return;
}
} while (next_input.disabled)
event.preventDefault();
next_input.focus();
next_input.select();
};
input.oninput = function (event) {

View File

@@ -18,6 +18,12 @@ h1 {
letter-spacing: 0.2em;
}
h1 a {
width: 100%;
text-decoration: none;
color: inherit;
}
h1.large.width {
display: inherit;
padding-top: 1rem;
@@ -199,6 +205,7 @@ h2 {
text-decoration: underline;
}
h1 a:hover,
.nouvelle-grille button:hover {
color: #2a6496;
}
@@ -315,6 +322,7 @@ h2 {
background-color: #edeeee;
}
h1 a:hover,
.nouvelle-grille button:hover {
color: #479fec;
}