-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCards.php
More file actions
48 lines (40 loc) · 940 Bytes
/
Cards.php
File metadata and controls
48 lines (40 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Cards Class
*/
class Cards
{
/**
* Generate a hand of cards
*
* @return array
*/
public function generateHand()
{
$sequences = array(2,3,4,5,6,7,8,9,10,"j","q","k","a");
$suites = array('h','c','s','d');
$cards = array();
foreach ($suites as $suite) {
foreach ($sequences as $sequence) {
$cards[] = $sequence . $suite;
}
}
shuffle($cards);
return array_slice( $cards, rand(0,48), 5 );
}
/**
* Check hand of cards using lookup string
*
* @param array $d a hand of cards with 5 array elements
* @return boolean
*/
public function checkHandIfStraight($d)
{
foreach( $d as $c )
$e[] = (int) str_replace(["j","q","k","a"], [11,12,13,0], $c);
sort($e);
$c = implode("", $e);
$l = "c023456789101112130";
return (bool) strpos($l, $c);
}
}