Esempio n. 1
0
 /**
  * @param HandInterface $hand
  *
  * @return bool|null
  */
 public function match(HandInterface $hand)
 {
     $straight = $this->straightFinder->find($hand);
     if (!$straight) {
         return false;
     }
     if (count($straight->getCards()) !== 5) {
         throw new \LogicException('A Straight should be an Hand of size 5. Found: ' . count($straight->getCards()));
     }
     return new Score($straight, $straight->getFaceValue() * self::MULTIPLIER);
 }
Esempio n. 2
0
 /**
  * @param HandInterface $hand
  *
  * @return bool
  */
 public function match(HandInterface $hand)
 {
     $threeOfAKind = $this->threeOfAKindFinder->find($hand);
     if (!$threeOfAKind) {
         return false;
     }
     if (count($threeOfAKind->getCards()) !== 3) {
         throw new \LogicException('A ThreeOfAKind should be an Hand of size 3. Found: ' . count($threeOfAKind->getCards()));
     }
     return new Score($hand->discard($threeOfAKind)->keep(2)->insert($threeOfAKind), $threeOfAKind->getFaceValue() * self::MULTIPLIER);
 }
Esempio n. 3
0
 /**
  * @param HandInterface $hand
  *
  * @return bool
  */
 public function match(HandInterface $hand)
 {
     $firstPair = $this->pairFinder->find($hand);
     if (!$firstPair) {
         return false;
     }
     if (count($firstPair->getCards()) !== 2) {
         throw new \LogicException('A pair should be an Hand of size 2. Found: ' . count($firstPair->getCards()));
     }
     $secondPair = $this->pairFinder->find($hand->discard($firstPair));
     if (!$secondPair) {
         return false;
     }
     if (count($secondPair->getCards()) !== 2) {
         throw new \LogicException('A pair should be an Hand of size 2. Found: ' . count($secondPair->getCards()));
     }
     return new Score($hand->discard($firstPair)->discard($secondPair)->keep(1)->insert($firstPair)->insert($secondPair), ($firstPair->getFaceValue() + $secondPair->getFaceValue()) * self::MULTIPLIER);
 }