Compare commits
1 Commits
main
...
grand-dico
| Author | SHA1 | Date | |
|---|---|---|---|
| 13fcdf05fb |
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
test*.*
|
test*.*
|
||||||
*.py
|
*.py
|
||||||
|
dico2.csv
|
||||||
|
wiktionaryXfr2010.7z
|
||||||
|
|||||||
193
Grille.php
@@ -2,13 +2,13 @@
|
|||||||
include_once "dico.php";
|
include_once "dico.php";
|
||||||
|
|
||||||
|
|
||||||
const ECART_TYPE = 5.0;
|
|
||||||
|
|
||||||
|
|
||||||
$randmax = mt_getrandmax() + 1;
|
$randmax = mt_getrandmax() + 1;
|
||||||
function gaussienne($moyenne = 0, $ecartType = 1.0): float {
|
function gaussienne($moyenne = 0, $ecartType = 1.0): float {
|
||||||
global $randmax;
|
global $randmax;
|
||||||
|
|
||||||
|
$u = 0;
|
||||||
|
$v = 0;
|
||||||
|
|
||||||
$u = (mt_rand() + 1) / $randmax;
|
$u = (mt_rand() + 1) / $randmax;
|
||||||
$v = (mt_rand() + 1) / $randmax;
|
$v = (mt_rand() + 1) / $randmax;
|
||||||
|
|
||||||
@@ -16,46 +16,34 @@ function gaussienne($moyenne = 0, $ecartType = 1.0): float {
|
|||||||
return $z * $ecartType + $moyenne;
|
return $z * $ecartType + $moyenne;
|
||||||
}
|
}
|
||||||
|
|
||||||
function explode_pos(string $separator, string $string): array {
|
|
||||||
$mots = [];
|
|
||||||
$mot = "";
|
|
||||||
$longueur = strlen($string);
|
|
||||||
$debut = 0;
|
|
||||||
|
|
||||||
for ($i = 0; $i < $longueur; $i++) {
|
|
||||||
$lettre = $string[$i];
|
|
||||||
if ($lettre == $separator) {
|
|
||||||
$mots[] = ["mot" => $mot, "debut" => $debut, "fin" => $i - 1, "longueur" => $i - $debut];
|
|
||||||
$mot = "";
|
|
||||||
$debut = $i + 1;
|
|
||||||
} else {
|
|
||||||
$mot .= $lettre;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$mots[] = ["mot" => $mot, "debut" => $debut, "fin" => $longueur - 1, "longueur" => $longueur - $debut];
|
|
||||||
return $mots;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Grille implements ArrayAccess
|
class Grille implements ArrayAccess
|
||||||
{
|
{
|
||||||
public $grille;
|
public $grille;
|
||||||
public $hauteur;
|
public $hauteur;
|
||||||
public $largeur;
|
public $largeur;
|
||||||
private $dico;
|
public $dico;
|
||||||
private $positions;
|
private $positions;
|
||||||
private $nb_positions;
|
private $nb_positions;
|
||||||
private $lignes = [];
|
public $lignes = [];
|
||||||
private $colonnes = [];
|
public $colonnes = [];
|
||||||
public $valide = false;
|
public $valide = false;
|
||||||
public $definitions = [];
|
private $id;
|
||||||
|
|
||||||
public function __construct($hauteur, $largeur)
|
public function __construct($hauteur, $largeur)
|
||||||
{
|
{
|
||||||
$this->hauteur = $hauteur;
|
$this->hauteur = $hauteur;
|
||||||
$this->largeur = $largeur;
|
$this->largeur = $largeur;
|
||||||
$this->grille = array_fill(0, $hauteur, array_fill(0, $largeur, ''));
|
$this->grille = array_fill(0, $hauteur, array_fill(0, $largeur, ''));
|
||||||
|
|
||||||
|
$this->positions = [];
|
||||||
|
for ($y = 0; $y < $hauteur; $y++) {
|
||||||
|
for ($x = 0; $x < $largeur; $x++)
|
||||||
|
$this->positions[] = [$x, $y];
|
||||||
|
}
|
||||||
|
$this->nb_positions = count($this->positions);
|
||||||
|
|
||||||
|
$this->dico = mots_espaces(max($hauteur, $largeur));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_ligne($y, $largeur)
|
public function get_ligne($y, $largeur)
|
||||||
@@ -74,58 +62,6 @@ class Grille implements ArrayAccess
|
|||||||
return $colonne;
|
return $colonne;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function genere($id)
|
|
||||||
{
|
|
||||||
mt_srand(crc32($id));
|
|
||||||
|
|
||||||
if (!isset($this->dico)) {
|
|
||||||
$this->dico = mots_espaces(max($this->hauteur, $this->largeur));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->positions)) {
|
|
||||||
$this->positions = [];
|
|
||||||
for ($y = 0; $y < $this->hauteur; $y++) {
|
|
||||||
for ($x = 0; $x < $this->largeur; $x++)
|
|
||||||
$this->positions[] = [$x, $y];
|
|
||||||
}
|
|
||||||
$this->nb_positions = count($this->positions);
|
|
||||||
}
|
|
||||||
|
|
||||||
$grilles = $this->gen_grilles();
|
|
||||||
$grilles->current();
|
|
||||||
|
|
||||||
if ($grilles->valid()) {
|
|
||||||
$this->definitions = [
|
|
||||||
"horizontales" => [],
|
|
||||||
"verticales" => []
|
|
||||||
];
|
|
||||||
for ($y = 0; $y < $this->hauteur; $y++) {
|
|
||||||
$mots = explode_pos(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
|
|
||||||
$this->definitions["horizontales"][$y] = [];
|
|
||||||
foreach($mots as $mot) {
|
|
||||||
$definition = $this->dico[$mot["longueur"]][$mot["mot"]];
|
|
||||||
$definition["debut"] = $mot["debut"];
|
|
||||||
$definition["fin"] = $mot["fin"];
|
|
||||||
$this->definitions["horizontales"][$y][] = $definition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ($x = 0; $x < $this->largeur; $x++) {
|
|
||||||
$mots = explode_pos(CASE_NOIRE, $this->get_colonne($x, $this->hauteur));
|
|
||||||
$this->definitions["verticales"][$x] = [];
|
|
||||||
foreach($mots as $mot) {
|
|
||||||
$definition = $this->dico[$mot["longueur"]][$mot["mot"]];
|
|
||||||
$definition["debut"] = $mot["debut"];
|
|
||||||
$definition["fin"] = $mot["fin"];
|
|
||||||
$this->definitions["verticales"][$x][] = $definition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->save($id);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function gen_grilles($i = 0, $lettres_ligne = NULL)
|
public function gen_grilles($i = 0, $lettres_ligne = NULL)
|
||||||
{
|
{
|
||||||
[$x, $y] = $this->positions[$i];
|
[$x, $y] = $this->positions[$i];
|
||||||
@@ -145,40 +81,30 @@ class Grille implements ArrayAccess
|
|||||||
$lettres_ligne->branches,
|
$lettres_ligne->branches,
|
||||||
$lettres_colonne->branches
|
$lettres_colonne->branches
|
||||||
);
|
);
|
||||||
// Sélection des candidats les plus fertiles
|
|
||||||
foreach ($lettres_communes as $lettre => $_) {
|
foreach ($lettres_communes as $lettre => $_) {
|
||||||
$lettres_communes[$lettre] = log(count($lettres_ligne->branches[$lettre])) * count($lettres_colonne->branches[$lettre]) * gaussienne(ECART_TYPE, ECART_TYPE);
|
$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) {
|
uksort($lettres_communes, function($a, $b) use ($lettres_communes) {
|
||||||
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
return $lettres_communes[$b] <=> $lettres_communes[$a];
|
||||||
});
|
});
|
||||||
uksort($lettres_communes, function($a, $b) {
|
$lettres_communes = array_slice($lettres_communes, 0, 3);
|
||||||
return ($a == CASE_NOIRE)? 1 : -1;
|
|
||||||
});
|
|
||||||
$lettres_communes = array_slice($lettres_communes, 0, 2);
|
|
||||||
|
|
||||||
foreach ($lettres_communes as $lettre => $_) {
|
foreach ($lettres_communes as $lettre => $_) {
|
||||||
$this->grille[$y][$x] = $lettre;
|
$this->grille[$y][$x] = $lettre;
|
||||||
|
|
||||||
// Omission des lettres isolées
|
// Omission des lettres isolées
|
||||||
if ($lettre == CASE_NOIRE) {
|
if ($lettre == " "
|
||||||
if (($y < 2 || $this->grille[$y - 2][$x] == CASE_NOIRE)
|
&& ($y - 2 < 0 || $this->grille[$y - 2][$x] == " ")
|
||||||
&& ($y < 1 || $x == 0 || $this->grille[$y - 1][$x - 1] == CASE_NOIRE)
|
&& ($y - 1 < 0 || $x - 1 < 0 || $this->grille[$y - 1][$x - 1] == " ")
|
||||||
&& ($y < 1 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == CASE_NOIRE)
|
&& ($y - 1 < 0 || $x + 1 >= $this->largeur || $this->grille[$y - 1][$x + 1] == " ")
|
||||||
) continue;
|
) {
|
||||||
if ($y == $this->hauteur - 1
|
continue;
|
||||||
&& ($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
|
// Omission des doublons
|
||||||
$mots = [];
|
$mots = [];
|
||||||
if ($x == $this->largeur - 1) $mots = explode(CASE_NOIRE, $this->get_ligne($y, $this->largeur));
|
if ($x == $this->largeur - 1) $mots = explode(" ", $this->get_ligne($y, $this->largeur));
|
||||||
else if ($lettre == CASE_NOIRE) $mots = explode(CASE_NOIRE, $this->get_ligne($y, $x));
|
else if ($lettre == " ") $mots = explode(" ", $this->get_ligne($y, $x));
|
||||||
else $mots = [];
|
else $mots = [];
|
||||||
$this->lignes[$y] = array_filter($mots, function ($mot) {
|
$this->lignes[$y] = array_filter($mots, function ($mot) {
|
||||||
return strlen($mot) >= 2;
|
return strlen($mot) >= 2;
|
||||||
@@ -190,7 +116,7 @@ class Grille implements ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($y == $this->hauteur - 1) {
|
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) {
|
foreach ($mots as $rang => $mot) {
|
||||||
if (strlen($mot) < 2) continue;
|
if (strlen($mot) < 2) continue;
|
||||||
if (strlen($mot > 2) && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2;
|
if (strlen($mot > 2) && in_array($mot, array_merge(...$this->lignes, ...$this->colonnes))) continue 2;
|
||||||
@@ -208,6 +134,21 @@ class Grille implements ArrayAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function genere($id)
|
||||||
|
{
|
||||||
|
mt_srand(crc32($id));
|
||||||
|
|
||||||
|
$grilles = $this->gen_grilles();
|
||||||
|
$grilles->current();
|
||||||
|
|
||||||
|
if ($grilles->valid()) {
|
||||||
|
$this->save($id);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function hash()
|
public function hash()
|
||||||
{
|
{
|
||||||
$string = "";
|
$string = "";
|
||||||
@@ -216,9 +157,13 @@ class Grille implements ArrayAccess
|
|||||||
return hash('sha256', $string);
|
return hash('sha256', $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString() {
|
public function save($id)
|
||||||
return implode(
|
{
|
||||||
PHP_EOL,
|
session_id($id);
|
||||||
|
session_start(["use_cookies" => false]);
|
||||||
|
|
||||||
|
$_SESSION["$this->largeur,$this->hauteur"] = implode(
|
||||||
|
"",
|
||||||
array_map(
|
array_map(
|
||||||
function ($ligne) {
|
function ($ligne) {
|
||||||
return implode("", $ligne);
|
return implode("", $ligne);
|
||||||
@@ -228,30 +173,34 @@ 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"] = $this->grille;
|
|
||||||
$_SESSION["definitions"] = $this->definitions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load($id)
|
public function load($id)
|
||||||
{
|
{
|
||||||
session_id("$this->largeur,$this->hauteur,$id");
|
session_id($id);
|
||||||
session_start(["use_cookies" => false]);
|
session_start(["use_cookies" => false]);
|
||||||
|
|
||||||
if (!isset($_SESSION)) {
|
if (!isset($_SESSION["$this->largeur,$this->hauteur"])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->grille = $_SESSION["grille"];
|
foreach (str_split($_SESSION["$this->largeur,$this->hauteur"], $this->largeur) as $y => $ligne) {
|
||||||
$this->definitions = $_SESSION["definitions"];
|
foreach (str_split($ligne) as $x => $lettre) {
|
||||||
|
$this->grille[$y][$x] = $lettre;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($y = 0; $y < $this->hauteur; $y++) {
|
||||||
|
$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(" ", $this->get_colonne($x, $this->hauteur));
|
||||||
|
$this->colonnes[$x] = array_filter($mots, function ($mot) {
|
||||||
|
return strlen($mot) >= 2;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
# Mots croisés
|
# mots-croises
|
||||||
|
|
||||||
Générateur de grille de mots croisés en PHP
|
Générateur de grille de mots croisés en PHP
|
||||||
|
|
||||||

|
|
||||||
|
|||||||
86
Trie.php
@@ -1,27 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class Trie implements ArrayAccess, IteratorAggregate, Countable
|
class Trie implements ArrayAccess, IteratorAggregate, Countable {
|
||||||
{
|
|
||||||
public array $branches = [];
|
public array $branches = [];
|
||||||
private $nb_branches = 0;
|
private $nb_branches = 0;
|
||||||
|
|
||||||
public function arraySet($cles, $valeur)
|
public function arraySet($cles, $valeur) {
|
||||||
{
|
|
||||||
$cle = $cles[0];
|
|
||||||
$this->nb_branches++;
|
$this->nb_branches++;
|
||||||
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
$this->branches[$cle] = $valeur;
|
$this->branches[$cle] = $valeur;
|
||||||
} else {
|
} else {
|
||||||
if (!isset($this->branches[$cle]))
|
if (!isset($this->branches[$cle])) $this->branches[$cle] = new Trie();
|
||||||
$this->branches[$cle] = new Trie();
|
|
||||||
$this->branches[$cle]->arraySet($cles, $valeur);
|
$this->branches[$cle]->arraySet($cles, $valeur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrayExists($cles)
|
public function arrayExists($cles) {
|
||||||
{
|
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
@@ -31,8 +27,7 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function &arrayGet($cles)
|
public function &arrayGet($cles) {
|
||||||
{
|
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
@@ -42,8 +37,7 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrayUnset($cles)
|
public function arrayUnset($cles) {
|
||||||
{
|
|
||||||
$cle = $cles[0];
|
$cle = $cles[0];
|
||||||
$cles = array_slice($cles, 1);
|
$cles = array_slice($cles, 1);
|
||||||
if ($cles == []) {
|
if ($cles == []) {
|
||||||
@@ -58,45 +52,10 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArrayAccess
|
public function arrayIterator() {
|
||||||
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) {
|
foreach ($this->branches as $cle => $branche) {
|
||||||
if ($branche instanceof Trie) {
|
if ($branche instanceof Trie) {
|
||||||
foreach ($branche->getIterator() as $sous_cles => $feuille) {
|
foreach($branche->arrayIterator() as $sous_cles => $feuille) {
|
||||||
yield array_merge([$cle], $sous_cles) => $feuille;
|
yield array_merge([$cle], $sous_cles) => $feuille;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -105,9 +64,32 @@ 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
|
// Countable
|
||||||
public function count(): int
|
public function count(): int {
|
||||||
{
|
|
||||||
return $this->nb_branches;
|
return $this->nb_branches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$largeur = isset($_GET['largeur']) ? (int)$_GET['largeur'] : 200;
|
|
||||||
$hauteur = isset($_GET['hauteur']) ? (int)$_GET['hauteur'] : 200;
|
|
||||||
$lignes = isset($_GET['lignes']) ? (int)$_GET['lignes'] : 8;
|
|
||||||
$colonnes = isset($_GET['colonnes']) ? (int)$_GET['colonnes'] : 8;
|
|
||||||
|
|
||||||
$image = imagecreatetruecolor($largeur, $hauteur);
|
|
||||||
imagesavealpha($image, true);
|
|
||||||
$blanc = imagecolorallocate($image, 255, 255, 255);
|
|
||||||
$noir = imagecolorallocate($image, 0, 0, 0);
|
|
||||||
$transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
|
|
||||||
|
|
||||||
// Calculer la taille et la position des cases
|
|
||||||
$min_dimension = min($largeur, $hauteur);
|
|
||||||
if ($min_dimension <= 16) {
|
|
||||||
$bordure_exterieure = 0;
|
|
||||||
} else if ($min_dimension < 32) {
|
|
||||||
$bordure_exterieure = 1;
|
|
||||||
} else if ($min_dimension <= 96) {
|
|
||||||
$bordure_exterieure = 2;
|
|
||||||
} else if ($min_dimension <= 600) {
|
|
||||||
$bordure_exterieure = 3;
|
|
||||||
} else {
|
|
||||||
$bordure_exterieure = 6;
|
|
||||||
}
|
|
||||||
$cote = (int)min(($largeur - 2 * $bordure_exterieure) / $colonnes, ($hauteur - 2 * $bordure_exterieure) / $lignes);
|
|
||||||
if ($cote < 3) {
|
|
||||||
$bordure_interieure = 0;
|
|
||||||
} else if ($min_dimension < 600) {
|
|
||||||
$bordure_interieure = 1;
|
|
||||||
} else {
|
|
||||||
$bordure_interieure = 2;
|
|
||||||
}
|
|
||||||
$haut = (int)(($hauteur - $lignes * $cote - 2 * $bordure_exterieure) / 2) + (int)$bordure_exterieure;
|
|
||||||
$gauche = (int)(($largeur - $colonnes * $cote - 2 * $bordure_exterieure) / 2) + $bordure_exterieure;
|
|
||||||
$bas = $haut + $lignes * $cote - $bordure_interieure;
|
|
||||||
$droite = $gauche + $colonnes * $cote - $bordure_interieure;
|
|
||||||
|
|
||||||
// Remplir l'image avec un fond transparent
|
|
||||||
imagefill($image, 0, 0, $transparent);
|
|
||||||
|
|
||||||
// Dessiner les bordures extérieures (3 pixels d'épaisseur)
|
|
||||||
$marge1 = ceil($bordure_exterieure / 2);
|
|
||||||
$marge2 = floor($bordure_exterieure / 2);
|
|
||||||
imagesetthickness($image, $bordure_exterieure);
|
|
||||||
imagerectangle($image, $gauche - $marge1, $haut - $marge1, $droite + $marge2 - 1, $bas + $marge2 - 1, $noir);
|
|
||||||
imagefilledrectangle($image, $gauche, $haut, $droite - 1, $bas - 1, $blanc);
|
|
||||||
|
|
||||||
// Dessiner les lignes et colonnes internes (1 pixel d'épaisseur)
|
|
||||||
if ($bordure_interieure >= 1) {
|
|
||||||
imagesetthickness($image, $bordure_interieure);
|
|
||||||
for ($x = $gauche + $cote - ceil($bordure_interieure / 2); $x < $droite; $x += $cote) {
|
|
||||||
imageline($image, $x, $haut, $x, $bas, $noir); // Lignes verticales
|
|
||||||
}
|
|
||||||
for ($y = $haut + $cote - ceil($bordure_interieure / 2); $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 - 1, $haut + ($y + 1) * $cote - 1, $noir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Envoyer l'image au navigateur
|
|
||||||
header('Content-Type: image/png');
|
|
||||||
imagepng($image);
|
|
||||||
|
|
||||||
// Libérer la mémoire
|
|
||||||
imagedestroy($image);
|
|
||||||
?>
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$lignes = isset($_GET['lignes']) ? (int)$_GET['lignes'] : 8;
|
|
||||||
$colonnes = isset($_GET['colonnes']) ? (int)$_GET['colonnes'] : 8;
|
|
||||||
|
|
||||||
$bordure = 2;
|
|
||||||
$marge = $bordure / 2;
|
|
||||||
$cote = 20;
|
|
||||||
|
|
||||||
// Dimensions du SVG
|
|
||||||
$width = $colonnes * $cote; // Largeur proportionnelle au nombre de colonnes
|
|
||||||
$height = $lignes * $cote; // Hauteur proportionnelle au nombre de lignes
|
|
||||||
$rectRadius = 20; // Rayon des coins arrondis du rectangle
|
|
||||||
|
|
||||||
// Création du document XML
|
|
||||||
$doc = new DOMDocument('1.0', 'UTF-8');
|
|
||||||
$doc->formatOutput = true;
|
|
||||||
|
|
||||||
// Élément SVG principal
|
|
||||||
$svg = $doc->createElement('svg');
|
|
||||||
$svg->setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
||||||
$svg->setAttribute('viewBox', -$marge . " " . -$marge . " " . ($width + $bordure) . " " . ($height + $bordure));
|
|
||||||
$svg->setAttribute('width', $width + $bordure);
|
|
||||||
$svg->setAttribute('height', $height + $bordure);
|
|
||||||
$doc->appendChild($svg);
|
|
||||||
|
|
||||||
// Rectangle arrondi
|
|
||||||
$rect = $doc->createElement('rect');
|
|
||||||
$rect->setAttribute('x', 0);
|
|
||||||
$rect->setAttribute('y', 0);
|
|
||||||
$rect->setAttribute('width', $width);
|
|
||||||
$rect->setAttribute('height', $height);
|
|
||||||
$rect->setAttribute('rx', $rectRadius);
|
|
||||||
$rect->setAttribute('ry', $rectRadius);
|
|
||||||
$rect->setAttribute('fill', 'white');
|
|
||||||
$rect->setAttribute('stroke', 'black');
|
|
||||||
$rect->setAttribute('stroke-width', $bordure);
|
|
||||||
$svg->appendChild($rect);
|
|
||||||
|
|
||||||
// Lignes verticales
|
|
||||||
for ($i = 1; $i < $colonnes; $i++) {
|
|
||||||
$x = $i * $cote;
|
|
||||||
$line = $doc->createElement('line');
|
|
||||||
$line->setAttribute('x1', $x);
|
|
||||||
$line->setAttribute('y1', $marge);
|
|
||||||
$line->setAttribute('x2', $x);
|
|
||||||
$line->setAttribute('y2', $height - $marge);
|
|
||||||
$line->setAttribute('stroke', '#000');
|
|
||||||
$line->setAttribute('stroke-width', 1);
|
|
||||||
$svg->appendChild($line);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lignes horizontales
|
|
||||||
for ($i = 1; $i < $lignes; $i++) {
|
|
||||||
$y = $i * $cote;
|
|
||||||
$line = $doc->createElement('line');
|
|
||||||
$line->setAttribute('x1', $marge);
|
|
||||||
$line->setAttribute('y1', $y);
|
|
||||||
$line->setAttribute('x2', $width - $marge);
|
|
||||||
$line->setAttribute('y2', $y);
|
|
||||||
$line->setAttribute('stroke', '#000');
|
|
||||||
$line->setAttribute('stroke-width', 1);
|
|
||||||
$svg->appendChild($line);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
$rect = $doc->createElement('rect');
|
|
||||||
$rect->setAttribute('x', $x * $cote);
|
|
||||||
$rect->setAttribute('y', $y * $cote);
|
|
||||||
$rect->setAttribute('width', $cote);
|
|
||||||
$rect->setAttribute('height', $cote);
|
|
||||||
$rect->setAttribute('fill', 'black');
|
|
||||||
$svg->appendChild($rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
header('Content-Type: image/svg+xml');
|
|
||||||
echo $doc->saveXML();
|
|
||||||
67
dico.php
@@ -1,63 +1,64 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
include_once "Trie.php";
|
include_once "Trie.php";
|
||||||
|
|
||||||
|
|
||||||
const CASE_NOIRE = " ";
|
const MIN_PREMIER_MOT = 1;
|
||||||
|
const MIN_MOTS_SUIVANTS = 1;
|
||||||
|
|
||||||
|
|
||||||
|
$nb_mots = 0;
|
||||||
|
|
||||||
function dico($longueur_max) {
|
function dico($longueur_max) {
|
||||||
|
global $nb_mots;
|
||||||
|
|
||||||
$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD);
|
$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Upper(); :: NFC;', Transliterator::FORWARD);
|
||||||
|
|
||||||
$dico = [];
|
$dico = [[""]];
|
||||||
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
for ($longueur = 0; $longueur <= $longueur_max; $longueur++) {
|
||||||
$dico[] = new Trie();
|
$dico[] = new Trie();
|
||||||
}
|
}
|
||||||
foreach (str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZ") as $lettre) {
|
if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||||
$dico[1][$lettre] = [];
|
$entete = fgetcsv($lecteur, 0, "\t");
|
||||||
}
|
while (($ligne = fgetcsv($lecteur, 0, "\t")) !== FALSE) {
|
||||||
|
if (
|
||||||
|
$ligne[0] == NULL
|
||||||
|
|| substr($ligne[0], 0, 1) == "#"
|
||||||
|
|| strlen($ligne[0]) > $longueur_max
|
||||||
|
) continue;
|
||||||
|
|
||||||
|
$mot = $ligne[0];
|
||||||
|
$definitions = array_slice($ligne, 1);
|
||||||
|
$mot = str_replace("-", " ", $mot);
|
||||||
|
|
||||||
foreach (yaml_parse_file('dico.yaml') as $mot => $definitions) {
|
|
||||||
$mot = str_replace("-", CASE_NOIRE, $mot);
|
|
||||||
$mot = $transliterator->transliterate($mot);
|
$mot = $transliterator->transliterate($mot);
|
||||||
if (strpos($mot, CASE_NOIRE) !== false) {
|
if (strpos($mot, " ") !== false) {
|
||||||
$mots = explode(CASE_NOIRE, $mot);
|
$mots = explode(" ", $mot);
|
||||||
$nb_mots = count($mots);
|
$nb_mots = count($mots);
|
||||||
$mot = implode("", $mots);
|
$mot = implode("", $mots);
|
||||||
} else {
|
foreach($definitions as $i => $definition) {
|
||||||
$nb_mots = 1;
|
$definitions[$i] .= " ($nb_mots mots)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen($mot) > $longueur_max) continue;
|
$longueur = strlen($mot);
|
||||||
|
$dico[$longueur][$mot] = $definitions;
|
||||||
$dico[strlen($mot)][$mot] = [];
|
|
||||||
if (count($definitions)) {
|
|
||||||
$definition = $definitions[mt_rand(0, count($definitions) - 1)];
|
|
||||||
if (is_array($definition)) {
|
|
||||||
foreach ($definition as $auteur => $def) {
|
|
||||||
$dico[strlen($mot)][$mot]["definition"] = $def;
|
|
||||||
$dico[strlen($mot)][$mot]["auteur"] = $auteur;
|
|
||||||
}
|
}
|
||||||
} else if (is_string($definition)) {
|
fclose($lecteur);
|
||||||
$dico[strlen($mot)][$mot]["definition"] = $definition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($nb_mots > 1) $dico[strlen($mot)][$mot]["nb_mots"] = $nb_mots;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dico;
|
return $dico;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mots_espaces($longueur_max) {
|
function mots_espaces($longueur_max) {
|
||||||
$longueur_min = 1;
|
global $nb_mots;
|
||||||
|
|
||||||
$dico = dico($longueur_max);
|
$dico = dico($longueur_max);
|
||||||
for ($longueur = 3; $longueur <= $longueur_max; $longueur++) {
|
for ($longueur = 1; $longueur <= $longueur_max; $longueur++) {
|
||||||
//$longueur_min = $longueur == $longueur_max ? 1 : 2;
|
for ($position_espace = MIN_PREMIER_MOT; $position_espace + MIN_MOTS_SUIVANTS < $longueur; $position_espace++) {
|
||||||
for ($position_espace = $longueur - 2; $position_espace >= $longueur_min; $position_espace--) {
|
|
||||||
$mots_suivants = $dico[$longueur - $position_espace - 1];
|
$mots_suivants = $dico[$longueur - $position_espace - 1];
|
||||||
foreach ($dico[$position_espace] as $premier_mot => $definition) {
|
foreach ($dico[$position_espace]->arrayIterator() as $premier_mot => $definition) {
|
||||||
$premier_mot[] = CASE_NOIRE;
|
$premier_mot[] = " ";
|
||||||
$dico[$longueur][$premier_mot] = $mots_suivants;
|
$dico[$longueur]->arraySet($premier_mot, $mots_suivants);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
favicon.ico
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 518 B |
@@ -21,8 +21,8 @@
|
|||||||
inkscape:pagecheckerboard="0"
|
inkscape:pagecheckerboard="0"
|
||||||
inkscape:deskcolor="#505050"
|
inkscape:deskcolor="#505050"
|
||||||
inkscape:zoom="8.3124997"
|
inkscape:zoom="8.3124997"
|
||||||
inkscape:cx="32"
|
inkscape:cx="28.57143"
|
||||||
inkscape:cy="32"
|
inkscape:cy="30.977445"
|
||||||
inkscape:window-width="1536"
|
inkscape:window-width="1536"
|
||||||
inkscape:window-height="793"
|
inkscape:window-height="793"
|
||||||
inkscape:window-x="0"
|
inkscape:window-x="0"
|
||||||
@@ -32,19 +32,19 @@
|
|||||||
<path
|
<path
|
||||||
fill="#ffffff"
|
fill="#ffffff"
|
||||||
stroke="#000000"
|
stroke="#000000"
|
||||||
stroke-width="2"
|
stroke-width="2.03093"
|
||||||
stroke-miterlimit="10"
|
stroke-miterlimit="10"
|
||||||
d="m 63,8 v 48 a 7,7 0 0 1 -7,7 H 8 a 7,7 0 0 1 -7,-7 V 9 A 7,7 0 0 1 8,1 H 56 A 7,7 0 0 1 63,8 Z M 47,17 H 32 v 15 h 15 z"
|
d="m 62.968825,7.9076 v 48.183453 a 6.8777723,6.877772 0 0 1 -6.876426,6.87777 H 7.9089443 a 6.8777723,6.877772 0 0 1 -6.87777,-6.876424 V 7.9076 A 6.8777723,6.877772 0 0 1 7.9075973,1.0311743 H 56.092399 A 6.8777723,6.877772 0 0 1 62.968825,7.9076 Z M 46.910816,17.089183 H 31.999999 v 14.910816 h 14.910817 z"
|
||||||
id="path1" />
|
id="path1" />
|
||||||
<path
|
<path
|
||||||
d="M 47,17 H 32 v 15 h 15 z"
|
d="M 46.910816,17.089183 H 31.999999 v 14.910816 h 14.910817 z"
|
||||||
id="path2"
|
id="path2"
|
||||||
style="stroke-width:1" />
|
style="stroke-width:1.34646" />
|
||||||
<path
|
<path
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke="#000000"
|
stroke="#000000"
|
||||||
stroke-width="2"
|
stroke-width="2.06235"
|
||||||
stroke-miterlimit="10"
|
stroke-miterlimit="10"
|
||||||
d="M 47,63 V 32 m 0,-15 V 1 M 32,63 V 32 m 0,-15 V 1 m -16,0 V 63 M 47,32 h 16 m -31,0 H 1 M 63,47 H 1 M 63,16 H 1"
|
d="M 46.910816,62.968823 V 31.999999 m 0,-14.910815 V 1.0311743 M 31.999999,62.968823 V 31.999999 m 0,-14.910815 V 1.0311743 m -16.058011,0 V 62.968823 M 46.910816,31.999999 h 16.058009 m -30.968826,0 H 1.0311743 M 62.968825,46.910815 H 1.0311743 M 62.968825,15.941991 H 1.0311743"
|
||||||
id="path3" />
|
id="path3" />
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 13 KiB |
169
index.php
@@ -1,14 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
ini_set('display_errors', '1');
|
|
||||||
ini_set('display_startup_errors', '1');
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
include_once "Grille.php";
|
include_once "Grille.php";
|
||||||
|
|
||||||
|
|
||||||
const HAUTEUR_DEFAUT = 7;
|
const HAUTEUR_DEFAUT = 8;
|
||||||
const HAUTEUR_MIN = 2;
|
const HAUTEUR_MIN = 2;
|
||||||
const HAUTEUR_MAX = 10;
|
const HAUTEUR_MAX = 10;
|
||||||
const LARGEUR_DEFAUT = 7;
|
const LARGEUR_DEFAUT = 8;
|
||||||
const LARGEUR_MIN = 2;
|
const LARGEUR_MIN = 2;
|
||||||
const LARGEUR_MAX = 10;
|
const LARGEUR_MAX = 10;
|
||||||
|
|
||||||
@@ -30,76 +27,59 @@ $largeur = filter_input(INPUT_GET, 'colonnes', FILTER_VALIDATE_INT, [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$grille = new Grille($hauteur, $largeur);
|
$grille = new Grille($hauteur, $largeur);
|
||||||
$basedir = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["DOCUMENT_URI"]);
|
|
||||||
|
|
||||||
if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
|
if (!isset($_GET["grille"]) || $_GET["grille"] == "") {
|
||||||
do {
|
do {
|
||||||
$id = uniqid();
|
$id = uniqid();
|
||||||
$grille_valide = $grille->genere($id);
|
} while (!$grille->genere($id));
|
||||||
} while (!$grille_valide);
|
|
||||||
|
|
||||||
$_GET["grille"] = $id;
|
$_GET["grille"] = $id;
|
||||||
header("Location: $basedir/?" . http_build_query($_GET));
|
header("Location: " . dirname($_SERVER['DOCUMENT_URI']) . "?" . http_build_query($_GET));
|
||||||
} else {
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$id = htmlspecialchars($_GET["grille"]);
|
$id = htmlspecialchars($_GET["grille"]);
|
||||||
|
|
||||||
$grille_valide = $grille->load($id) || $grille->genere($id);
|
$grille_valide = $grille->load($id) || $grille->genere($id);
|
||||||
}
|
|
||||||
|
|
||||||
function formatter_definition($definition) {
|
mt_srand(crc32($id));
|
||||||
if (isset($definition["nb_mots"]) && $definition["nb_mots"] > 1) {
|
if ($grille_valide) {
|
||||||
$nb_mots = $definition["nb_mots"];
|
$definitions_horizontales = [];
|
||||||
$nb_mots = " <small>($nb_mots mots)</small>";
|
for ($y = 0; $y < $hauteur; $y++) {
|
||||||
} else {
|
$definitions_horizontales[$y] = [];
|
||||||
$nb_mots = "";
|
foreach ($grille->lignes[$y] as $mot) {
|
||||||
|
$definitions = $grille->dico[strlen($mot)][$mot];
|
||||||
|
if (count($definitions)) {
|
||||||
|
$definitions_horizontales[$y][] = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||||
}
|
}
|
||||||
if (isset($definition["auteur"])) {
|
|
||||||
$auteur = $definition["auteur"];
|
|
||||||
$auteur = " <small><em>$auteur</em></small>";
|
|
||||||
} else {
|
|
||||||
$auteur = "";
|
|
||||||
}
|
}
|
||||||
return ucfirst($definition["definition"]) . $nb_mots . $auteur;
|
|
||||||
}
|
}
|
||||||
|
$definitions_verticales = [];
|
||||||
function definition_courante($definitions, $position) {
|
for ($x = 0 ; $x < $largeur; $x++) {
|
||||||
foreach ($definitions as $id => $definition) {
|
$definitions_verticales[$x] = [];
|
||||||
if ($position <= $definition["fin"])
|
foreach ($grille->colonnes[$x] as $mot) {
|
||||||
return [$id, $definition];
|
$definitions = $grille->dico[strlen($mot)][$mot];
|
||||||
|
if (count($definitions)) {
|
||||||
|
$definitions_verticales[$x][] = $definitions[mt_rand(0, count($definitions) - 1)];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html lang="fr-FR" dir="ltr" prefix="og: https://ogp.me/ns#">
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>🄼🄾🅃🅂▣🄲🅁🄾🄸🅂🄴🅂</title>
|
<title>MOTS■CROISES</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
|
<link rel="icon" href="favicon.svg">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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="apercu.svg.php?grille=<?= $id ?>&lignes=<?= $hauteur ?>&colonnes=<?= $largeur ?>">
|
|
||||||
<link rel="icon" type="image/png" sizes="96x96"
|
|
||||||
href="apercu.png.php?grille=<?= $id ?>&lignes=<?= $hauteur ?>&colonnes=<?= $largeur ?>&largeur=96&hauteur=96" />
|
|
||||||
<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 ?>/apercu.png.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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<form id="grilleForm" method="get" location=".">
|
<form id="grilleForm" method="get" location=".">
|
||||||
<h1 class="large width">
|
<h1 class="large width">
|
||||||
<a href=".">
|
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -125,9 +105,8 @@ function definition_courante($definitions, $position) {
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</a>
|
|
||||||
</h1>
|
</h1>
|
||||||
<h1 class="small width"><a href=".">Mots■croisés</a></h1>
|
<h1 class="small width">Mots■croisés</h1>
|
||||||
<div class="grille-et-definitions">
|
<div class="grille-et-definitions">
|
||||||
<?php if ($grille_valide): ?>
|
<?php if ($grille_valide): ?>
|
||||||
<div class="grille">
|
<div class="grille">
|
||||||
@@ -143,36 +122,14 @@ function definition_courante($definitions, $position) {
|
|||||||
<tr>
|
<tr>
|
||||||
<th><?= $y + 1 ?></th>
|
<th><?= $y + 1 ?></th>
|
||||||
<?php for ($x = 0; $x < $largeur; $x++): ?>
|
<?php for ($x = 0; $x < $largeur; $x++): ?>
|
||||||
<?php if ($grille[$y][$x] == CASE_NOIRE): ?>
|
<?php if ($grille[$y][$x] == " "): ?>
|
||||||
<td class="case noire">
|
<td class="case noire">
|
||||||
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1"
|
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" value=" " disabled />
|
||||||
value="<?= CASE_NOIRE ?>" disabled />
|
|
||||||
</td>
|
</td>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<td class="case blanche">
|
<td class="case blanche">
|
||||||
<?php
|
<input id="<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1" pattern="[A-Z]" placeholder="<?= $grille[$y][$x] ?>"
|
||||||
$title = [];
|
title="<?= strip_tags("→ " . implode("\n→ ", $definitions_horizontales[$y]) . "\n↓ " . implode("\n↓ ", $definitions_verticales[$x])) ?>" />
|
||||||
[$iddh, $definition_horizontale] = definition_courante($grille->definitions["horizontales"][$y], $x);
|
|
||||||
[$iddv, $definition_verticale] = definition_courante($grille->definitions["verticales"][$x], $y);
|
|
||||||
if (isset($definition_horizontale["definition"]))
|
|
||||||
$title[0] = "→ " . $definition_horizontale["definition"];
|
|
||||||
if (isset($definition_horizontale["nb_mots"]))
|
|
||||||
$title[0] .= " (" . $definition_horizontale["nb_mots"] . ")";
|
|
||||||
if (isset($definition_horizontale["auteur"]))
|
|
||||||
$title[0] .= " (" . $definition_horizontale["auteur"] . ")";
|
|
||||||
if (isset($definition_verticale["definition"]))
|
|
||||||
$title[1] = "↓ " . $definition_verticale["definition"];
|
|
||||||
if (isset($definition_verticale["nb_mots"]))
|
|
||||||
$title[0] .= " (" . $definition_verticale["nb_mots"] . ")";
|
|
||||||
if (isset($definition_verticale["auteur"]))
|
|
||||||
$title[1] .= " (" . $definition_verticale["auteur"] . ")";
|
|
||||||
$title = htmlspecialchars(implode("\n", $title));
|
|
||||||
?>
|
|
||||||
<input id="case-<?= chr($x + 65) . ($y + 1) ?>" type="text" maxlength="1" size="1"
|
|
||||||
pattern="[A-Z]" title="<?= $title ?>"
|
|
||||||
data-iddh="<?= isset($definition_horizontale["definition"])? "dh-$y-$iddh" : "" ?>"
|
|
||||||
data-iddv="<?= isset($definition_verticale["definition"])? "dv-$x-$iddv" : "" ?>"
|
|
||||||
/>
|
|
||||||
</td>
|
</td>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
@@ -183,72 +140,50 @@ function definition_courante($definitions, $position) {
|
|||||||
<div class="definitions horizontales">
|
<div class="definitions horizontales">
|
||||||
<h2>Horizontalement</h2>
|
<h2>Horizontalement</h2>
|
||||||
<ol type="1">
|
<ol type="1">
|
||||||
<?php foreach ($grille->definitions["horizontales"] as $y => $definitions):
|
<?php foreach ($definitions_horizontales as $y => $definitions): ?>
|
||||||
$definitions = array_filter($definitions, function($definition) {
|
<li>
|
||||||
return isset($definition["definition"]);
|
|
||||||
});
|
|
||||||
?>
|
|
||||||
<?php if (count($definitions)): ?>
|
<?php if (count($definitions)): ?>
|
||||||
<?php if (count($definitions) == 1): ?>
|
<?php if (count($definitions) == 1): ?>
|
||||||
<?php foreach ($definitions as $id => $definition): ?>
|
<?= $definitions[0] ?>
|
||||||
<li id="<?= "dh-$y-$id" ?>"><label for="case-A<?= $y + 1 ?>"><?= formatter_definition($definition) ?></label></li>
|
|
||||||
<?php endforeach ?>
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<li>
|
|
||||||
<ol>
|
<ol>
|
||||||
<?php foreach ($definitions as $id => $definition): ?>
|
<?php foreach ($definitions as $definition) : ?>
|
||||||
<li id="<?= "dh-$y-$id" ?>">
|
<li><?= $definition ?></li>
|
||||||
<label for="case-<?= chr($definition["debut"] + 0x41) ?><?= $y + 1 ?>"><?= formatter_definition($definition) ?></label>
|
|
||||||
</li>
|
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</ol>
|
</ol>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php endif ?>
|
||||||
</li>
|
</li>
|
||||||
<?php endif ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
|
||||||
<li></li>
|
|
||||||
<?php endif ?>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<div class="definitions verticales">
|
<div class="definitions verticales">
|
||||||
<h2>Verticalement</h2>
|
<h2>Verticalement</h2>
|
||||||
<ol type="A">
|
<ol type="A">
|
||||||
<?php foreach ($grille->definitions["verticales"] as $x => $definitions):
|
<?php foreach ($definitions_verticales as $x => $definitions): ?>
|
||||||
$definitions = array_filter($definitions, function($definition) {
|
<li>
|
||||||
return isset($definition["definition"]);
|
|
||||||
});
|
|
||||||
?>
|
|
||||||
<?php if (count($definitions)): ?>
|
<?php if (count($definitions)): ?>
|
||||||
<?php if (count($definitions) == 1): ?>
|
<?php if (count($definitions) == 1): ?>
|
||||||
<?php foreach ($definitions as $id => $definition): ?>
|
<?= $definitions[0] ?>
|
||||||
<li id="<?= "dv-$x-$id" ?>"><label for="case-<?= chr($x + 0x41) ?>1"><?= formatter_definition($definition) ?></label></li>
|
|
||||||
<?php endforeach ?>
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<li>
|
|
||||||
<ol>
|
<ol>
|
||||||
<?php foreach ($definitions as $id => $definition): ?>
|
<?php foreach ($definitions as $definition) : ?>
|
||||||
<li id="<?= "dv-$x-$id" ?>">
|
<li><?= $definition ?></li>
|
||||||
<label for="case-<?= chr($x + 0x41) ?><?= $definition["debut"] + 1 ?>"><?= formatter_definition($definition) ?></label>
|
|
||||||
</li>
|
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</ol>
|
</ol>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php endif ?>
|
||||||
</li>
|
</li>
|
||||||
<?php endif ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
|
||||||
<li></li>
|
|
||||||
<?php endif ?>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
|
<?php else: http_response_code(500); ?>
|
||||||
<?php else:
|
|
||||||
http_response_code(500); ?>
|
|
||||||
<h3 class="erreur">Erreur de génération de la grille</h3>
|
<h3 class="erreur">Erreur de génération de la grille</h3>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nouvelle-grille">
|
<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>
|
<button type="submit">Nouvelle grille</button>
|
||||||
de
|
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?>"/>
|
||||||
|
|||||||
61
script.js
@@ -6,7 +6,7 @@ async function sha256(text) {
|
|||||||
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
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 largeur = Number(colonnes.value);
|
||||||
let nb_cases = inputs.length;
|
let nb_cases = inputs.length;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
@@ -17,31 +17,16 @@ for (let input of inputs) {
|
|||||||
|
|
||||||
input.onfocus = function (event) {
|
input.onfocus = function (event) {
|
||||||
for (li of document.querySelectorAll(
|
for (li of document.querySelectorAll(
|
||||||
`.definitions.horizontales > ol > li:nth-child(${input.y + 1})`
|
`.definitions.horizontales > ol > li:nth-child(${
|
||||||
|
input.y + 1
|
||||||
|
}), .definitions.verticales > ol > li:nth-child(${input.x + 1})`
|
||||||
)) {
|
)) {
|
||||||
li.classList.add("selectionee");
|
li.classList.add("selectionee");
|
||||||
for (liEnfant of li.querySelectorAll("li")) {
|
|
||||||
if (liEnfant.id == input.dataset.iddh) {
|
|
||||||
liEnfant.classList.add("selectionee");
|
|
||||||
} else {
|
|
||||||
liEnfant.classList.add("non-selectionee");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (li of document.querySelectorAll(
|
for (li of document.querySelectorAll(
|
||||||
`.definitions.verticales > ol > li:nth-child(${input.x + 1})`
|
`.definitions.horizontales > ol > li:not(:nth-child(${
|
||||||
)) {
|
input.y + 1
|
||||||
li.classList.add("selectionee");
|
})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))`
|
||||||
for (liEnfant of li.querySelectorAll("li")) {
|
|
||||||
if (liEnfant.id == input.dataset.iddv) {
|
|
||||||
liEnfant.classList.add("selectionee");
|
|
||||||
} else {
|
|
||||||
liEnfant.classList.add("non-selectionee");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (li of document.querySelectorAll(
|
|
||||||
`.definitions.horizontales > ol > li:not(:nth-child(${input.y + 1})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))`
|
|
||||||
)) {
|
)) {
|
||||||
li.classList.add("non-selectionee");
|
li.classList.add("non-selectionee");
|
||||||
}
|
}
|
||||||
@@ -50,28 +35,26 @@ for (let input of inputs) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
input.onkeydown = function (event) {
|
input.onkeydown = function (event) {
|
||||||
next_input = input;
|
next_input = null;
|
||||||
do {
|
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "ArrowUp":
|
case "ArrowUp":
|
||||||
next_input = inputs[(next_input.index - largeur + nb_cases) % nb_cases];
|
next_input = inputs[(input.index - largeur + nb_cases) % nb_cases];
|
||||||
break;
|
break;
|
||||||
case "ArrowDown":
|
case "ArrowDown":
|
||||||
next_input = inputs[(next_input.index + largeur) % nb_cases];
|
next_input = inputs[(input.index + largeur) % nb_cases];
|
||||||
break;
|
break;
|
||||||
case "ArrowLeft":
|
case "ArrowLeft":
|
||||||
next_input = inputs[(next_input.index - 1 + nb_cases) % nb_cases];
|
next_input = inputs[(input.index - 1 + nb_cases) % nb_cases];
|
||||||
break;
|
break;
|
||||||
case "ArrowRight":
|
case "ArrowRight":
|
||||||
next_input = inputs[(next_input.index + 1) % nb_cases];
|
next_input = inputs[(input.index + 1) % nb_cases];
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} while (next_input.disabled)
|
if (next_input) {
|
||||||
event.preventDefault();
|
|
||||||
next_input.focus();
|
next_input.focus();
|
||||||
next_input.select();
|
next_input.select();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
input.oninput = function (event) {
|
input.oninput = function (event) {
|
||||||
@@ -94,11 +77,21 @@ for (let input of inputs) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
input.onblur = function (event) {
|
input.onblur = function (event) {
|
||||||
for (li of document.querySelectorAll(".definitions li")) {
|
for (li of document.querySelectorAll(
|
||||||
|
`.definitions.horizontales > ol > li:nth-child(${
|
||||||
|
input.y + 1
|
||||||
|
}), .definitions.verticales > ol > li:nth-child(${input.x + 1})`
|
||||||
|
)) {
|
||||||
li.classList.remove("selectionee");
|
li.classList.remove("selectionee");
|
||||||
|
}
|
||||||
|
for (li of document.querySelectorAll(
|
||||||
|
`.definitions.horizontales > ol > li:not(:nth-child(${
|
||||||
|
input.y + 1
|
||||||
|
})), .definitions.verticales > ol > li:not(:nth-child(${input.x + 1}))`
|
||||||
|
)) {
|
||||||
li.classList.remove("non-selectionee");
|
li.classList.remove("non-selectionee");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let input of grilleForm.querySelectorAll(".nouvelle-grille input")) {
|
for (let input of grilleForm.querySelectorAll(".nouvelle-grille input")) {
|
||||||
|
|||||||
@@ -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"
|
|
||||||
}
|
|
||||||
13
style.css
@@ -18,12 +18,6 @@ h1 {
|
|||||||
letter-spacing: 0.2em;
|
letter-spacing: 0.2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 a {
|
|
||||||
width: 100%;
|
|
||||||
text-decoration: none;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1.large.width {
|
h1.large.width {
|
||||||
display: inherit;
|
display: inherit;
|
||||||
padding-top: 1rem;
|
padding-top: 1rem;
|
||||||
@@ -114,7 +108,6 @@ h2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.grille input[disabled] {
|
.grille input[disabled] {
|
||||||
color: black;
|
|
||||||
background-color: black;
|
background-color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,10 +170,6 @@ h2 {
|
|||||||
opacity: 30%;
|
opacity: 30%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.definitions label {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.erreur {
|
.erreur {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
@@ -209,7 +198,6 @@ h2 {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 a:hover,
|
|
||||||
.nouvelle-grille button:hover {
|
.nouvelle-grille button:hover {
|
||||||
color: #2a6496;
|
color: #2a6496;
|
||||||
}
|
}
|
||||||
@@ -326,7 +314,6 @@ h1 a:hover,
|
|||||||
background-color: #edeeee;
|
background-color: #edeeee;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 a:hover,
|
|
||||||
.nouvelle-grille button:hover {
|
.nouvelle-grille button:hover {
|
||||||
color: #479fec;
|
color: #479fec;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
thumbnail.png
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 3.9 KiB |