élimination des doublons
This commit is contained in:
		
							
								
								
									
										18
									
								
								Grille.php
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								Grille.php
									
									
									
									
									
								
							| @ -103,18 +103,30 @@ class Grille implements Iterator, ArrayAccess { | |||||||
|             $this->grille[$y][$x] = $lettre; |             $this->grille[$y][$x] = $lettre; | ||||||
|  |  | ||||||
|             if ($x == $this->largeur - 1) { |             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 { |             } else { | ||||||
|                 unset($this->lignes[$y]); |                 unset($this->lignes[$y]); | ||||||
|             } |             } | ||||||
|             if ($y == $this->hauteur - 1) { |             if ($y == $this->hauteur - 1) { | ||||||
|                 $mots_colonne = explode(" ", $this->get_colonne($x, $this->hauteur)); |                 $mots_colonne = explode(" ", $this->get_colonne($x, $this->hauteur)); | ||||||
|                 foreach ($mots_colonne as $mot_colonne) { |                 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; |                         continue 2; | ||||||
|                     } |                     } | ||||||
|  |                     if (!isset($this->lignes[$x])) { | ||||||
|  |                         $this->colonnes[$x] = []; | ||||||
|  |                     } | ||||||
|  |                     $this->colonnes[$x][] = $mot_colonne; | ||||||
|                 } |                 } | ||||||
|                 $this->colonnes[$x] = $mots_colonne; |  | ||||||
|             } else { |             } else { | ||||||
|                 unset($this->colonnes[$x]); |                 unset($this->colonnes[$x]); | ||||||
|             } |             } | ||||||
|  | |||||||
							
								
								
									
										9
									
								
								dico.php
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								dico.php
									
									
									
									
									
								
							| @ -39,6 +39,15 @@ if (($lecteur = fopen("dico.csv", "r")) !== FALSE) { | |||||||
|     } |     } | ||||||
|     fclose($lecteur); |     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) | 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) { | foreach ($grille->lignes as $y => $mots) { | ||||||
|     $definitions["lignes"][$y] = []; |     $definitions["lignes"][$y] = []; | ||||||
|     foreach ($mots as $mot) { |     foreach ($mots as $mot) { | ||||||
|         $definitions_lignes = $dico[strlen($mot)][$mot]; |         $definition = $dico[strlen($mot)][$mot]; | ||||||
|         if (count($definitions_lignes)) { |         if ($dico[strlen($mot)][$mot] != "") { | ||||||
|             $definitions["lignes"][$y][] = $definitions_lignes[array_rand($definitions_lignes)]; |             $definitions["lignes"][$y][] = $definition; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| foreach ($grille->colonnes as $x => $mots) { | foreach ($grille->colonnes as $x => $mots) { | ||||||
|     $definitions["colonnes"][$y] = []; |     $definitions["colonnes"][$x] = []; | ||||||
|     foreach ($mots as $mot) { |     foreach ($mots as $mot) { | ||||||
|         $definitions_colonnes = $dico[strlen($mot)][$mot]; |         $definition = $dico[strlen($mot)][$mot]; | ||||||
|         if (count($definitions_colonnes)) { |         if ($dico[strlen($mot)][$mot] != "") { | ||||||
|             $definitions["colonnes"][$x][] = $definitions_colonnes[array_rand($definitions_colonnes)]; |             $definitions["colonnes"][$x][] = $definition; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| ?> | ?> | ||||||
| <!DOCTYPE HTML> | <!DOCTYPE HTML> | ||||||
| <html> | <html> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user