poker.php
Source of poker.php
<p>
<?php
//set up arrays
$cardLocation = array();
$suits = array("heart", "diamond", "spade", "club");
//fill deck
for($rank=0; $rank<13; $rank++){
//print "<br />";
for($suit=0; $suit<4; $suit++){
$cardLocation[$rank][$suit] = "deck";
//print '<img style="width: 150px;" src="' . $suits[$suit] . ($rank+1) . '.png" />';
}
}
print "</p>";
//deal hand
for($player = 0; $player < 2; $player++){
print "<h2>Player " . ($player + 1) . "'s Hand:</h2><p>";
for($i=0; $i<5; $i++){
$duplicate = true;
while($duplicate){
$suit = rand(0,3);
$rank = rand(0,12);
if($cardLocation[$rank][$suit] == "deck"){
$cardLocation[$rank][$suit] = "player$player";
$duplicate = false;
print '<img style="width: 150px;" src="' . $suits[$suit] . ($rank + 1) . '.png" />';
}
}
}
print "</p>";
}
/**
Evaluate Poker Hand
Build a program that evaluates the hands to see who wins! I'll help get you started...
To Do:
1. Check for pairs
2. Check for three of a kind
3. Check for four of a kind
(HINT: Count how many PLAYER values in each RANK, then you can do a numpairs, numthrees, numfours to store how many two, three and four of a kinds you have)
2. Check for flushes.
(HINT: Count how many of each SUIT PLAYER has. If five of any, they have a flush)
3. Check for straights.
(HINT: Straights are easiest to do with plain if statements)
*/
?>
</p>
<p><a href="cards.php">deal</a></p>