Example #1
0
 private function validate(BoggleWord $word)
 {
     if ($word->getLength() < 3) {
         throw new IllegalWordLengthException("Word should at least have 2 characters");
     }
     if ($this->words->contains($word)) {
         throw new WordAlreadyEnteredException("Word was already entered before");
     }
     if (!$word->isPossibleInLayout($this->grid)) {
         throw new WordNotPossibleException("Word is impossible to make");
     }
     if (!$this->dictionary->contains($word)) {
         throw new WordNotInDictionaryException("Word doesn't exist in dictionary");
     }
 }
Example #2
0
 public function getPossibleWords(BoggleGrid $grid)
 {
     $result = array();
     foreach ($this->words as $word) {
         $w = new BoggleWord($word);
         $possible = true;
         foreach ($w->getWord() as $char) {
             if (!$grid->getLayout()->contains($char)) {
                 $possible = false;
                 break;
             }
         }
         if (!$possible) {
             continue;
         }
         if ($w->isPossibleInLayout($grid)) {
             $result[] = $w->getWord();
         }
     }
     return $result;
 }
 private function doCheck($word, $possible)
 {
     $w = new BoggleWord($word);
     $this->assertEqual($possible, $w->isPossibleInLayout($this->grid));
 }