Compare commits
16 Commits
vercel
...
563ba7ed0a
| Author | SHA1 | Date | |
|---|---|---|---|
|
563ba7ed0a
|
|||
|
974e2c203c
|
|||
|
00547c2c00
|
|||
|
95d21a22c9
|
|||
|
822d353775
|
|||
| e754e6e44b | |||
| 8287699a4b | |||
| d3b11df015 | |||
| 6635adf26a | |||
| c2e4b8ae53 | |||
| 5aa5da8c53 | |||
| d862dc572d | |||
| c3986e70a3 | |||
| e19bb9d2dc | |||
| 468a6a9231 | |||
| c62afa80cc |
39
Grille.php
39
Grille.php
@@ -2,15 +2,12 @@
|
||||
include_once "dico.php";
|
||||
|
||||
|
||||
const ECART_TYPE_ALEA = 5;
|
||||
const ECART_TYPE = 5;
|
||||
|
||||
|
||||
$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;
|
||||
@@ -86,7 +83,11 @@ class Grille implements ArrayAccess
|
||||
foreach($mots as $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][] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +96,11 @@ class Grille implements ArrayAccess
|
||||
foreach($mots as $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][] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +131,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, ECART_TYPE);
|
||||
}
|
||||
uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
|
||||
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
||||
@@ -137,13 +142,19 @@ 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)
|
||||
) {
|
||||
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 = [];
|
||||
|
||||
58
Trie.php
58
Trie.php
@@ -52,10 +52,40 @@ 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,30 +94,6 @@ 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 {
|
||||
return $this->nb_branches;
|
||||
|
||||
30
dico.php
30
dico.php
@@ -1,18 +1,22 @@
|
||||
<?php
|
||||
|
||||
include_once "Trie.php";
|
||||
|
||||
|
||||
const CASE_NOIRE = " ";
|
||||
const DEFINITION = 0;
|
||||
const AUTEUR = 1;
|
||||
const NB_MOTS = 2;
|
||||
|
||||
|
||||
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 +26,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 +34,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);
|
||||
}
|
||||
@@ -45,12 +53,12 @@ function dico($longueur_max) {
|
||||
|
||||
function mots_espaces($longueur_max) {
|
||||
$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 >= 2; $longueur--) {
|
||||
for ($position_espace = $longueur - 2; $position_espace >= 1; $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
81
index.php
81
index.php
@@ -1,11 +1,16 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include_once "Grille.php";
|
||||
|
||||
|
||||
const HAUTEUR_DEFAUT = 8;
|
||||
const HAUTEUR_DEFAUT = 7;
|
||||
const HAUTEUR_MIN = 2;
|
||||
const HAUTEUR_MAX = 10;
|
||||
const LARGEUR_DEFAUT = 8;
|
||||
const LARGEUR_DEFAUT = 7;
|
||||
const LARGEUR_MIN = 2;
|
||||
const LARGEUR_MAX = 10;
|
||||
|
||||
@@ -43,19 +48,19 @@ 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 $definition[DEFINITION] . $nb_mots . $auteur;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
@@ -85,33 +90,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,7 +140,7 @@ 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] ?>"
|
||||
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" pattern="[A-Z]"
|
||||
title="<?= strip_tags("→ " . implode("\n→ ", array_map("formatter_definition", $grille->definitions["horizontales"][$y] ?? [])) . "\n↓ " . implode("\n↓ ", array_map("formatter_definition", $grille->definitions["verticales"][$x] ?? []))) ?>" />
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
@@ -152,9 +159,9 @@ function formatter_definition($definition) {
|
||||
<?= formatter_definition($definitions[0]) ?>
|
||||
<?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 ?>
|
||||
|
||||
42
script.js
42
script.js
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user