thpokercheck

Gesponsorde koppelingen

PHP script bestanden

  1. thpokercheck

« Lees de omschrijving en reacties

THPokerCheck.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?
/*
*    Poker Engine Card Evaluator v0.1a
*    Produced by: Michel Ypma
*/


class THPokerCheck {
    
    private $cards = array();
    
    private $types = array('d','h','s','c');
    
    private $foundTypes = array();
    
    private $countCards = array();
    
    public $rules = array(
        'Royal Flush' => false,
        'Straight Flush' => false,
        'Four of a kind' => false,
        'Full House' => false,
        'Flush' => false,
        'Straight' => false,
        'Three of a kind' => false,
        'Two pair' => false,
        'One pair' => false,
        'High card' => false
    );
    
    public function evaluate($cards) {
        $this->cards = $cards;
        $this->countCards = $this->countAll();
        $this->start();
    }

    
    private function start() {
        $this->kinds();
        $this->isStraight();
        $this->isRoyalFlush();
    }

    
    private function isRoyalFlush() {
        foreach($this->foundTypes as $a) {
            $cache = $this->countCards[$a];
            $start = current($cache);
            if ($start != 14) return false;
            if ($this->isStraightFlush(1)) {
                $this->rules['Royal Flush'] = true;
            }
        }
    }

    
    private function isStraightFlush($bool = false) {
        foreach($this->foundTypes as $a) {
            $cache = $this->countCards[$a];
            $start = current($cache);
            $total = count($cache);
            $retries = $total - 5;
            $counter = 1;
            if ($this->isFlush()) {
                for ($i=0; $i < 4; $i++) {
                    next($cache);
                    $start--;
                    $counter++;
                    if (current($cache) != $start) {
                        if ($retries > 0 && $bool == false) {
                            $retries--;
                            $i--;
                            $counter = 1;
                        }
else {
                            return false;
                        }
                    }

                    // edit aan de hand van de ontdekking van cervetti
                    if ($counter == 5) {
                        $this->rules['Straight Flush'] = true;
                        return true;
                    }
                }
            }
else {
                return false;
            }

            return false;
        }
    }

    
    private function isStraight() {
        foreach($this->countCards as &$value) {
            foreach($value as $nKey => &$nValue) {
                $cache[] = $nValue;
            }
        }

        arsort($cache);
        
        $total = count($cache);
        $retries = $total - 5;
        $counter = $start = current($cache);
        
        foreach($cache as $a => $b) {
            if ($cache[$a] != $counter) {
                if ($retries > 0) {
                    $retries--;
                    $counter = $start = $cache[$a];
                }
else {
                    return false;
                }
            }

            if (($start - 5) == $counter ) {
                break;
            }

            $counter--;
        }

        $this->rules['Straight'] = true;
        return true;
    }

    
    private function isFlush() {
        foreach($this->foundTypes as $a) {
            $cache = $this->countCards[$a];
            $total = count($cache);
            if ($total >= 5) {
                $this->rules['Flush'] = true;
                return true;
            }
        }

        return false;
        
    }

    
    private function kinds() {
        foreach($this->countCards as $value) {
            foreach($value as $nKey => $nValue) {
                $cache[] = $nValue;
            }
        }

        $cache = array_count_values($cache);
        foreach($cache as $key => $value) {
            $pair += ($cache[$key] == 2) ? 1 : 0 ;
            $threekind += ($cache[$key] >= 3) ? 1 : 0 ;
            $fourkind += ($cache[$key] >= 4) ? 1 : 0 ;
        }

        $this->rules['One pair'] = ($pair == 1) ? true : false;
        $this->rules['Two pair'] = ($pair == 2) ? true : false;
        $this->rules['Three of a kind'] = ($threekind == 1) ? true : false;
        $this->rules['Four of a kind'] = ($fourkind == 1) ? true : false;
        $this->rules['Full House'] = ($threekind == 1 && $pair == 1) ? true : false;
        return true;
    }

    
    private function countAll() {
        foreach($this->cards as $knum => $hand) {
            foreach($hand as $type => $value) {
                switch($type) {
                    case
'd':
                    $this->countCards['d'][] = $value;
                    break;
                    case
'h':
                    $this->countCards['h'][] = $value;
                    break;
                    case
's':
                    $this->countCards['s'][] = $value;
                    break;
                    case
'c':
                    $this->countCards['c'][] = $value;
                    break;
                }

                $this->foundTypes[] = $type;
            }
        }

        $this->foundTypes = array_unique($this->foundTypes);
        
        for($i = 0; $i<=count($this->foundTypes);$i++) {
            (
$this->countCards[$this->foundTypes[$i]]) ? arsort($this->countCards[$this->foundTypes[$i]]) : '';
        }

        
        return $this->countCards;
    }

    
    private function getHighestCards($num = 1) {
        $cache = $this->getValues();
        arsort($cache);
        $cache = array_chunk($cache,5);
    }

    
    private function getValues() {
    $i = 0;
        foreach($this->countCards as $value) {
            foreach($value as $nKey => $nValue) {
                $cache[$i]['value'] = $nValue;
                $cache[$i]['type'] = $nKey;
                $i++;
            }
        }

        return $cache;
    }
    
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.