Question

My charity does "Poker Runs" motorcycle runs where player go to each stop and pick a card. We are looking to make this an easier way to track the winners without having to manually sort through each card.

I believe I have all other functions done, I just am unsure how to check for the full house with the method I am using. And also how to score just for a high card hand.

<?php 

$card_one_suit = $_POST['card_one_suit'];
$card_two_suit = $_POST['card_two_suit'];
$card_three_suit = $_POST['card_three_suit'];
$card_four_suit = $_POST['card_four_suit'];
$card_five_suit = $_POST['card_five_suit'];

$card_one = $_POST['card_one'];
$card_two = $_POST['card_two'];
$card_three = $_POST['card_three'];
$card_four = $_POST['card_four'];
$card_five = $_POST['card_five'];

$player = $_POST['name'];
$total_card_amount = $card_one + $card_two + $card_three + $card_four + $card_five;

$card_list = array();
array_push($card_list, $card_one, $card_two, $card_three, $card_four, $card_five);
$card_suits = array();
array_push($card_suits, $card_one_suit, $card_two_suit, $card_three_suit,         $card_four_suit, $card_five_suit);
$rank = 0;

foreach($card_list as $card) 
{
   $count_values[$card]++;
}

foreach($card_suits as $cards) 
{
    $count_suit_values[$cards]++;
}

//echo "$count_suit_values[$card_one_suit]";

//print_r($count_suit_values);

// ROYAL FLUSH
if(($total_card_amount == "60") && ($count_suit_values[$card_one_suit] == 5))
{
$rank = 1;
echo "ROYAL FLUSH";
}
// STRAIGHT FLUSH
else if (($total_card_amount == "20" || $total_card_amount == "25" || $total_card_amount == "30" || $total_card_amount == "35" || $total_card_amount == "40") && 
($count_suit_values[$card_one_suit] == 5))
{
$rank = 2;
echo "STRAIGHT FLUSH";
}
// FOUR OF A KIND
else if ($count_values[$card_one] == 4 || $count_values[$card_two] == 4 ||   $count_values[$card_three] == 4)
{
$rank = 3;
echo "FOUR OF A KIND";
}
// FULL HOUSE
// HOW TO FIGURE THIS OUT?
// FLUSH
else if ($count_suit_values[$card_one_suit] == 5 || $count_suit_values[$card_two_suit] == 5 || $count_suit_values[$card_three_suit] == 5)
{
$rank = 5;
echo "FLUSH";
}
// STRAIGHT
else if ($total_card_amount == "20" || $total_card_amount == "25" || $total_card_amount == "30" || $total_card_amount == "35" || $total_card_amount == "40")
{
$rank = 6;
echo "STRAIGHT";
}
// THREE OF A KIND
else if ($count_values[$card_one] == 3 || $count_values[$card_two] == 3 ||   $count_values[$card_three] == 3 || $count_values[$card_four] == 3)
{
$rank = 7;
echo "THREE OF A KIND";
}
// TWO PAIR
else if ($count_values[$card_one] == 2 && $count_values[$card_two] == 2 || $count_values[$card_one] == 2 && $count_values[$card_three] == 2 
|| $count_values[$card_one] == 2 && $count_values[$card_five] == 2 ||   $count_values[$card_two] == 2 && $count_values[$card_three] == 2)
{
$rank = 8;
echo "TWO PAIR";
}
// ONE PAIR
else if ($count_values[$card_one] == 2 || $count_values[$card_two] == 2 ||  $count_values[$card_three] == 2 || $count_values[$card_four] == 2)
{
$rank = 9;
echo "ONE PAIR";
}
// HIGH CARD
else
{
$rank = 10;
echo "NO MATCHES. DETERMINE HIGH CARD";
}

?>
Was it helpful?

Solution

For the hand to be a full house, the array count_values must contain two entries, one of those entries must have a value of 3.

else if (count($count_values) == 2 && (array_values($count_values)[0] == 3 || array_values($count_values)[1] == 3)) {
  echo 'FULL HOUSE';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top