1 /****************************************************************************
4 Copyright (c) 2001 Jerome Jacovella-St-Louis
7 poker.ec - Poker Main Window
8 ****************************************************************************/
14 static String cardsNames[] =
16 ":ac.png", ":ad.png", ":ah.png", ":as.png", ":2c.png", ":2d.png", ":2h.png", ":2s.png", ":3c.png", ":3d.png", ":3h.png", ":3s.png",
17 ":4c.png", ":4d.png", ":4h.png", ":4s.png", ":5c.png", ":5d.png", ":5h.png", ":5s.png", ":6c.png", ":6d.png", ":6h.png", ":6s.png",
18 ":7c.png", ":7d.png", ":7h.png", ":7s.png", ":8c.png", ":8d.png", ":8h.png", ":8s.png", ":9c.png", ":9d.png", ":9h.png", ":9s.png",
19 ":10c.png", ":10d.png", ":10h.png", ":10s.png",":jc.png", ":jd.png", ":jh.png", ":js.png", ":qc.png", ":qd.png", ":qh.png", ":qs.png",
20 ":kc.png", ":kd.png", ":kh.png", ":ks.png", ":rb.png", ":rr.png"
23 static define CARD_WIDTH = 111;
24 static define CARD_HEIGHT = 150;
26 enum PokerHand { nothing, onePair, twoPair, threeOfAKind, straight, flush, fullHouse, fourOfAKind, straightFlush, royalFlush };
30 STRAIGHT FLUSH 0.0012 %
31 FOUR OF A KIND 0.0240 %
35 THREE OF A KIND 2.1128 %
41 enum Facing { faceDown, faceUp };
43 static int lowHand[5] = { 4*0 + 1, 4*1, 4*2, 4*3, 4*5 };
44 static Player players[6];
45 static int deck[52], deckIndex;
47 static int numPlayers;
48 static int numPlayersLeft;
49 static char playerNames[6][20] =
58 static Pointf positions[5][6] =
60 {{ .50f, .82f }, { .50f, .18f }},
61 {{ .50f, .82f }, { .18f, .18f }, { .82f, .18f}},
62 {{ .50f, .82f }, { .18f, .50f }, { .50f, .18f}, { .82f, .50f}},
63 {{ .50f, .82f }, { .18f, .50f }, { .50f, .18f}, { .82f, .50f}, { .82f, .50f}},
64 {{ .25f, .82f }, { .18f, .50f }, { .25f, .18f}, { .75f, .18f}, { .82f, .50f}, { .75f, .82f}}
67 // --- Data Used by Child Window Classes ---
79 hasMinimize = true, hasMaximize = true, hasClose = true;
80 borderStyle = sizable;
82 size = Size { 986, 740 };
84 Bitmap bitmapCards[52];
87 Widow widowWindow { this, opacity = 0, text = "Widow", borderStyle = sizable, anchor = Anchor { left = 0.375, top = 0.34, right = 0.375, bottom = 0.34 } };
89 void DrawCard(Surface surface, int x, int y, int card)
93 bitmap = bitmapCards[card];
96 surface.Blit(bitmap, x, y, 0,0, bitmap.width,bitmap.height);
99 // --- Poker Game Flow ---
101 void CreatePlayers(int num)
106 for (c = 0; c<numPlayers; c++)
109 Pointf pos = positions[numPlayers - 2][c];
111 sprintf(string, "%s (%d)", playerNames[c], c + 1);
112 players[c] = Player { this, opacity = 0, text = string, anchor = Anchor { left = pos.x - 0.175, top = pos.y - 0.16, right = 1-(pos.x + 0.175), bottom = 1-(pos.y + 0.16) } };
115 players[0].human = true;
122 POKER_ShuffleDeck(deck);
124 numPlayersLeft = numPlayers;
125 for(c = 0; c<numPlayers; c++)
127 players[c].numDown = players[c].numUp = 0;
128 players[c].folded = false;
129 players[c].winner = false;
135 void Deal(Facing up, int howMany)
140 for(c = 0; c<howMany; c++)
141 for(p = 0; p<numPlayers; p++)
143 Player player = players[p];
148 player.up[player.numUp++] = deck[deckIndex++];
149 POKER_SortCards(player.up, player.numUp);
153 player.down[player.numDown++] = deck[deckIndex++];
154 POKER_SortCards(player.down, player.numDown);
161 void DealWidow(int howMany)
164 for(c = 0; c<howMany; c++)
165 widow[widowNum++] = deck[deckIndex++];
166 POKER_SortCards(widow, widowNum);
173 for(c = 0; c<numPlayers; c++)
175 if(players[c].money >= ANTE)
177 players[c].money -= ANTE;
181 players[c].folded = true;
186 void BettingRound(int firstBet)
193 if(numPlayersLeft >= 2)
196 for(p = 0; p<numPlayers; p++)
197 players[p].thisBet = 0;
199 for(p = firstBet;; p++)
205 if(p == numPlayers) p = 0;
207 if(player.folded) continue;
209 if(currentBet && player.thisBet == currentBet) break;
211 sprintf(string, "Your bet, %s?", playerNames[p]);
212 bet = Bet { parent = this, thisBet = &player.thisBet, text = string };
214 eInstance_IncRef(bet);
218 if(!app.ProcessInput(true))
221 eInstance_DecRef(bet);
225 //player.thisBet = 0;
227 if(player.thisBet < currentBet)
229 player.folded = true;
231 if(numPlayersLeft < 2)
235 else if(player.thisBet > currentBet)
237 currentBet = player.thisBet;
242 potMoney += player.thisBet;
243 player.money -= player.thisBet;
246 if(!currentBet && numBets >= numPlayersLeft)
252 void WinMoney(int numHand, int numWidow)
256 int bestHand[5] = { lowHand[0], lowHand[1], lowHand[2], lowHand[3], lowHand[4] };
260 for(p=0; p<numPlayers; p++)
264 Player player = players[p];
266 if(player.folded) continue;
270 if(c < player.numDown)
271 cards[c] = player.down[c];
272 else if(c - player.numDown < player.numUp)
273 cards[c] = player.up[c - player.numDown];
277 CopyBytesBy4(player.bestHand, lowHand, 5);
278 POKER_BestHand(cards, widow, c, widowNum, numHand, numWidow, player.bestHand);
279 player.handType = POKER_HandType(player.bestHand);
282 for(p=0; p<numPlayers; p++)
285 Player player = players[p];
286 if(player.folded) continue;
288 switch(POKER_Compare(bestHand, player.bestHand))
292 player.winner = true;
295 for(c=0; c<numPlayers; c++)
296 players[c].winner = false;
298 CopyBytesBy4(bestHand, player.bestHand, 5);
299 player.winner = true;
303 for(p=0; p<numPlayers; p++)
305 Player player = players[p];
306 if(player.folded) continue;
307 if(POKER_Compare(player.bestHand, bestHand) == 0)
308 player.money += potMoney / numWinners;
312 potMoney -= (potMoney / numWinners) * numWinners;
318 // --- Poker Games Definitions ---
321 TEXAS HOLDEM - The most popular poker game in Blackhawk. A variation of 7-Card
322 Stud where every player gets dealt 2 cards face down and there is a community
323 board of 5 cards. Players Ise the 2 cards in their hand plus the 5 community
324 cards to make the best possible 5 card hand. A dealers button moves around the
325 table each hand. The player to the left of the dealer button is dealt the
326 first card. Also the person to the left of the button has to post a blind.
327 There is a betting round after the players receive their first 2 cards. Then the
328 dealer places 3 cards on the board (the flop) and there is a betting round. Then
329 the dealer places another card on the board (the turn) and there is another
330 betting round. Then the dealer places the final card (the river) on the board
331 and there is a final betting round. Games may have 1 blind or 2 blinds. Games
332 vary from $2-5 betting to straight $5 betting.
350 OMAHA - A games similar to Texas Holdem except the players are dealt 4 cards
351 face down. There is a board of 5 community cards and you must Ise 2 cards out
352 of your hand to make the best possible hand. The game may be played straight
353 high or high/lowHand. There is a dealer button that moves around the table each
354 hand and the player that has the dealers button may choose to play the game
355 straight high or high/lowHand. The player to the left of the dealer button has
356 to post a small blind of $1 and the person to his/her left has to post the
357 large blind of $2. To qualify for a lowHand hand, the player must have 5 cards
358 that are 8 or lowHander. There is a betting round after the players receive their
359 4 cards. Then the dealer places 3 cards on the board (the flop). After the
360 betting round, the dealer places another card on the board (the turn) and there
361 is another betting round. Then the dealer places the last card (the river) on
362 the board and there is a final betting round. The betting limits are Isually
398 // --- Poker Window Class ---
399 bool OnLoadGraphics()
402 cardBack.LoadT(":back.png",null,displaySystem);
403 for(i = 0; i < 52; i++)
405 bitmapCards[i] = Bitmap {};
406 bitmapCards[i].LoadT(cardsNames[i], null, displaySystem);
411 void OnUnloadGraphics()
415 delete bitmapCards[i];
426 bool OnClose(bool parentClosing)
428 if(MessageBox { type = yesNo, text = "Exit", contents = "Quit?" }.Modal() == yes)
433 bool OnKeyHit(Key key, unichar ch)
435 if(!gameOver) return false;
438 case f1: TexasHoldem(); break;
439 case f2: OmahaHoldem(); break;
440 case f3: SevenCardStud(); break;
448 class PokerApp : GuiApplication
451 appName = "Poker Master";
456 // Initialize Card Deck
457 RandomSeed((int)(GetTime() * 1000));
458 for(c = 0; c<52; c++)