Just a beta version for now, all this does is deal you a random 5 card hand. When I get some time I'll update this bad boy so my workmates and myself can play mel poker over the local ethernet.
string $hands[] = {
"High Card",
"Pair",
"Two Pair",
"Three of a Kind",
"Straght",
"Flush",
"Full House",
"Four of a Kind",
"Straight Flush"
};
global proc string[] shuffleArray(string $array[]) {
for ($i=0;$i<size($array);$i++)
{
int $index = rand(size($array));
string $tmp = $array[$i];
$array[$i] = $array[$index];
$array[$index] = $tmp;
}
return $array;
}
global proc string[] buildDeck(){
string $deck[];
string $suits[] = {"hearts", "clubs", "diamonds", "spades"};
int $cards[] = {2,3,4,5,6,7,8,9,10,11,12,13,14};
$i=0;
for ($card in $cards){
for ($suit in $suits){
$deck[$i] = ($card+","+$suit);
$i++;
}
}
shuffleArray $deck;
return $deck;
}
global proc string[] normalize(string $hand[]){
$i = 0;
string $buffer[];
for ($one in $hand){
tokenize $one "," $buffer;
$card = $buffer[0];
$suit = $buffer[1];
if ($buffer[0]==11) $card = "Jack";
if ($buffer[0]==12) $card = "Queen";
if ($buffer[0]==13) $card = "King";
if ($buffer[0]==14) $card = "Ace";
$hand[$i] = ($card +" of "+ $suit);
$i++;
}
return $hand;
}
global proc dealCards(int $players, int $dealer){
string $normalHand[];
string $deck[] = buildDeck();
$i = 0;
string $hand[];
while ($i<5){
$hand[$i] = $deck[$i];
$i++;
}
$normalHand = normalize($hand);
$result = stringArrayToString ($normalHand, ", ");
print $result;
}
dealCards(1,1);