Problem: Creating a video poker game for my internet programming class.
I have everything else working except I’m missing something in my logic down below.
It returns true for Full House when all I have is 3 of a Kind.
I know my logic for the 3 of the kind works. But when comparing the two cards not involved in the 3 of a Kind is where something is wrong.
Here’s the code:
//Calculate if Full House exist
function checkHouse()
{
$kindFlag = false;
$pairFlag = false;
$tempCardValue = 0;
$temp = array();
$counter = 0;
//check for 3 of a kind, save card positions so they aren't tested for a pair
for($i=0; $i<3; $i++)
{
for($j=($i+1); $j<4; $j++)
{
for($k=($j+1); $k<5; $k++)
{
if($this->Hand[$i]->GetSortValue() == $this->Hand[$j]->GetSortValue() && $this->Hand[$i]->GetSortValue() == $this->Hand[$k]->GetSortValue())
{
$kindFlag = true;
$tempCardValue = $this->Hand[$i]->GetSortValue();
break 3;
}
}
}
}
//Checks 2 remaining cards to see if they match
for($i=0; $i<5; $i++)
{
if($this->Hand[$i]->GetSortValue() != $tempCardValue)
{
$temp[$counter] = $this->Hand[$i]->GetSortValue();
$counter++;
}
}
if($temp[0] == $temp[1])
{
$pairFlag = true;
}
//Computes Full House or not
if($pairFlag && $kindFlag)
return true;
else
return false;
}
Just a suggestion, but you’re implementation of the cards seems overly complicated. It should be easy to do a check for pairs and fullhouses, and what not.
start with a class called Card (this is from memory so there may be syntax errors and what not):
and then you can add a class called Hand and it would tabulate the result
then you can call
It’d be easy to implement the rest of the card checks in the Hand class:
etc… I didn’t mean to write so much code, sorry, lol