Esempio n. 1
0
 /**
  * @param HandInterface $hand
  *
  * @return Score
  */
 public function match(HandInterface $hand) : Score
 {
     $cards = $hand->getCards();
     $max = -1;
     foreach ($cards as $card) {
         $max = max($max, $card->getFaceValue());
     }
     return new Score(new Hand(...$cards), $max);
 }
Esempio n. 2
0
 /**
  * @param Card          $cardToFind
  * @param HandInterface $hand
  *
  * @return Hand|null
  */
 public function search(Card $cardToFind, HandInterface $hand)
 {
     $matches = 0;
     $cards = [];
     foreach ($hand->getCards() as $key => $card) {
         if ($card->getFaceValue() === $cardToFind->getFaceValue()) {
             ++$matches;
             $cards[] = $card;
         }
     }
     return count($cards) ? new Hand(...$cards) : null;
 }
Esempio n. 3
0
 /**
  * @param HandInterface $hand
  *
  * @return HandInterface|null
  */
 public function find(HandInterface $hand)
 {
     if (count($hand->getCards()) < $this->requiredMatches) {
         return null;
     }
     $cards = $hand->getCards();
     foreach ($cards as $card) {
         $matchingHand = $this->handSearch->search($card, $hand);
         if ($matchingHand && count($matchingHand->getCards()) === $this->requiredMatches) {
             return $matchingHand;
         }
     }
     return null;
 }
Esempio n. 4
0
 /**
  * @param HandInterface $hand
  *
  * @return HandInterface
  */
 public function find(HandInterface $hand)
 {
     if (count($hand->getCards()) < 5) {
         return null;
     }
     $cards = $hand->getCards();
     foreach ($cards as $card) {
         $start = max($card->getFaceValue() - 4, 1);
         $end = min($card->getFaceValue() + 4, 14);
         $flushCards = [];
         for ($faceValueCounter = $start; $faceValueCounter <= $end; ++$faceValueCounter) {
             $matchingHand = $this->handSearch->search(new Card($faceValueCounter == 1 ? 14 : $faceValueCounter, Suit::diamonds()), $hand);
             if ($matchingHand && count($matchingHand->getCards())) {
                 $flushCards[] = $matchingHand->getCards()[0];
             }
             if (count($flushCards) == 5) {
                 return new Hand(...$flushCards);
             }
         }
     }
     return null;
 }