public function populateFoundables($inflections, Grid $grid)
 {
     $foundableForms = [];
     foreach ($inflections as $inflection) {
         if (!isset($foundableForms[$inflection->getCleanedContent()])) {
             $foundableForms[$inflection->getCleanedContent()] = ['inflections' => [$inflection]];
         } else {
             $foundableForms[$inflection->getCleanedContent()]['inflections'][] = $inflection;
         }
     }
     $letterPoints = $this->scoreManager->getLettersPointsArray($grid->getLanguage());
     foreach ($foundableForms as $form => $foundableForm) {
         $foundable = new FoundableForm();
         $foundable->setGrid($grid);
         $foundable->setForm($form);
         $points = $this->scoreManager->getWordPoint($form, $letterPoints);
         $foundable->setPoints($points);
         foreach ($foundableForm['inflections'] as $inflection) {
             $foundable->addInflection($inflection);
         }
         $this->em->persist($foundable);
         $grid->addFoundableForm($foundable);
     }
     $this->em->flush();
     return;
 }
Пример #2
0
 public function findInflections(Grid $grid)
 {
     $this->em->getConnection()->getConfiguration()->setSQLLogger(null);
     $i = 0;
     $simplifiedGrid = array();
     $words = array();
     $this->currentLanguage = $grid->getLanguage();
     for ($y = 0; $y < 4; ++$y) {
         for ($x = 0; $x < 4; ++$x) {
             if ($grid->getSquares()[$i]) {
                 $simplifiedGrid[$y][$x] = $grid->getSquares()[$i]->getLetter()->getValue();
             } else {
                 $simplifiedGrid[$y][$x] = '_';
             }
             ++$i;
         }
     }
     // on l'alimente par récursivité avec la méthode nextLetter() en partant de chaque lettre
     for ($y = 0; $y < 4; ++$y) {
         for ($x = 0; $x < 4; ++$x) {
             // ajout au tableau des mots potentiels de ceux qui commencent par la lettre en x, y
             $words = array_unique(array_merge($words, $this->nextLetter('', $simplifiedGrid, $x, $y)), SORT_STRING);
         }
     }
     // words contient tous les débuts de mots ayant été trouvé dans le dictionnaire
     // il faut vérifier si chaque word existe réellement dans le dictionnaire
     if ($words) {
         $inflections = $this->em->getRepository("MagicWordBundle:Lexicon\\Inflection")->getExistingWords($words, $this->currentLanguage);
     }
     return $inflections;
 }