élimination des doublons
This commit is contained in:
parent
38344a315c
commit
d852596386
18
Grille.php
18
Grille.php
@ -103,18 +103,30 @@ class Grille implements Iterator, ArrayAccess {
|
||||
$this->grille[$y][$x] = $lettre;
|
||||
|
||||
if ($x == $this->largeur - 1) {
|
||||
$this->lignes[$y] = explode(" ", $this->get_ligne($y, $this->largeur));
|
||||
$mots_ligne = explode(" ", $this->get_ligne($y, $this->largeur));
|
||||
foreach ($mots_ligne as $mot_ligne) {
|
||||
if (in_array($mot_ligne, array_merge(...$this->lignes, ...$this->colonnes))) {
|
||||
continue 2;
|
||||
}
|
||||
if (!isset($this->lignes[$y])) {
|
||||
$this->lignes[$y] = [];
|
||||
}
|
||||
$this->lignes[$y][] = $mot_ligne;
|
||||
}
|
||||
} else {
|
||||
unset($this->lignes[$y]);
|
||||
}
|
||||
if ($y == $this->hauteur - 1) {
|
||||
$mots_colonne = explode(" ", $this->get_colonne($x, $this->hauteur));
|
||||
foreach ($mots_colonne as $mot_colonne) {
|
||||
if (in_array($mot_colonne, array_merge(...$this->lignes))) {
|
||||
if (in_array($mot_colonne, array_merge(...$this->lignes, ...$this->colonnes))) {
|
||||
continue 2;
|
||||
}
|
||||
if (!isset($this->lignes[$x])) {
|
||||
$this->colonnes[$x] = [];
|
||||
}
|
||||
$this->colonnes[$x][] = $mot_colonne;
|
||||
}
|
||||
$this->colonnes[$x] = $mots_colonne;
|
||||
} else {
|
||||
unset($this->colonnes[$x]);
|
||||
}
|
||||
|
9
dico.php
9
dico.php
@ -39,6 +39,15 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) {
|
||||
}
|
||||
fclose($lecteur);
|
||||
}
|
||||
foreach ($dico as $longueur => $mots) {
|
||||
foreach ($mots as $mot => $definitions) {
|
||||
if (count($definitions)) {
|
||||
$dico[$longueur][$mot] = $definitions[array_rand($definitions)];
|
||||
} else {
|
||||
$dico[$longueur][$mot] = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mots_espaces($longueur, $nb_mots_restants=MAX_MOTS)
|
||||
{
|
||||
|
15
index.php
15
index.php
@ -44,22 +44,21 @@ $definitions = [
|
||||
foreach ($grille->lignes as $y => $mots) {
|
||||
$definitions["lignes"][$y] = [];
|
||||
foreach ($mots as $mot) {
|
||||
$definitions_lignes = $dico[strlen($mot)][$mot];
|
||||
if (count($definitions_lignes)) {
|
||||
$definitions["lignes"][$y][] = $definitions_lignes[array_rand($definitions_lignes)];
|
||||
$definition = $dico[strlen($mot)][$mot];
|
||||
if ($dico[strlen($mot)][$mot] != "") {
|
||||
$definitions["lignes"][$y][] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($grille->colonnes as $x => $mots) {
|
||||
$definitions["colonnes"][$y] = [];
|
||||
$definitions["colonnes"][$x] = [];
|
||||
foreach ($mots as $mot) {
|
||||
$definitions_colonnes = $dico[strlen($mot)][$mot];
|
||||
if (count($definitions_colonnes)) {
|
||||
$definitions["colonnes"][$x][] = $definitions_colonnes[array_rand($definitions_colonnes)];
|
||||
$definition = $dico[strlen($mot)][$mot];
|
||||
if ($dico[strlen($mot)][$mot] != "") {
|
||||
$definitions["colonnes"][$x][] = $definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user