public void Play(Player player, CardDeck deck) { ReplaceTrashCards(player, deck); base.Play(player); }
/** * The player should switch one card with any of the following: * * Four to a straight flush and royal flush, even breaking up a pair * Four to a flush with no pair. * Four to an outside straight with no pair. * * The player will sometimes switch with any of the following: * Four to a flush with a low pair (depends on the pair and dealer's up card). * Four to an inside straight with no pair (depends on the inside straight and dealer's up card). */ private void ApplyCardSwitchPolicy(Hand h, Player player, CardDeck deck) { Card switchCardForFlush = null; Card switchCardForStraight = null; Card dealersUpCard = base.GetDealerHand().GetUpCard(); bool isOutSideStraight = false; bool wantingDealersUp = false; /** * First, check if four to a flush */ Hashtable flushMap = new Hashtable(); foreach (Card c in h.GetCards()) { if (flushMap.ContainsKey(c.GetSuit())) { List <Card> l = (List <Card>)flushMap[c.GetSuit()]; l.Add(c); } else { List <Card> l = new List <Card>(); l.Add(c); flushMap.Add(c.GetSuit(), l); } } if (flushMap.Count == 2) { foreach (DictionaryEntry item in flushMap) { List <Card> l = (List <Card>)item.Value; if (l.Count == 1) { switchCardForFlush = l[0]; } } } /** * Check if four to a straight */ Card card1 = h.GetCards()[0]; Card card2 = h.GetCards()[1]; Card card3 = h.GetCards()[2]; Card card4 = h.GetCards()[3]; Card card5 = h.GetCards()[4]; // OXXXX if (card2.GetRank() + 1 == card3.GetRank() && card3.GetRank() + 1 == card4.GetRank() && card4.GetRank() + 1 == card5.GetRank()) { // Is outside straight if (card2.GetRank() >= 3 && card5.GetRank() <= 12) { isOutSideStraight = true; } else { if (dealersUpCard.GetRank() + 1 == card2.GetRank()) { wantingDealersUp = true; } } switchCardForStraight = card1; } // XOXXX else if (card1.GetRank() + 2 == card3.GetRank() && card3.GetRank() + 1 == card4.GetRank() && card4.GetRank() + 1 == card5.GetRank()) { if (dealersUpCard.GetRank() + 1 == card3.GetRank()) { wantingDealersUp = true; } switchCardForStraight = card2; } // XXOXX else if (card1.GetRank() + 1 == card2.GetRank() && card2.GetRank() + 2 == card4.GetRank() && card4.GetRank() + 1 == card5.GetRank()) { if (dealersUpCard.GetRank() + 1 == card4.GetRank()) { wantingDealersUp = true; } switchCardForStraight = card3; } // XXXOX else if (card1.GetRank() + 1 == card2.GetRank() && card2.GetRank() + 1 == card3.GetRank() && card3.GetRank() + 2 == card5.GetRank()) { if (dealersUpCard.GetRank() + 1 == card5.GetRank()) { wantingDealersUp = true; } switchCardForStraight = card4; } // XXXXO else if (card1.GetRank() + 1 == card2.GetRank() && card2.GetRank() + 1 == card3.GetRank() && card3.GetRank() + 1 == card4.GetRank()) { // is outside straight if (card1.GetRank() >= 3 && card4.GetRank() <= 12) { isOutSideStraight = true; } else { if (dealersUpCard.GetRank() - 1 == card4.GetRank()) { wantingDealersUp = true; } } switchCardForStraight = card5; } /** * Now do the card switch */ if (switchCardForFlush != null && switchCardForStraight != null && switchCardForFlush == switchCardForStraight) { // Potential Straight Flush DoSwitchCard(h, switchCardForFlush, player, deck); } else if (switchCardForFlush != null && h.GetRank() == CardRank.HighCard) { // Potential Flush DoSwitchCard(h, switchCardForFlush, player, deck); } else if (switchCardForStraight != null && h.GetRank() == CardRank.HighCard && isOutSideStraight) { // Potential Outside Straight DoSwitchCard(h, switchCardForStraight, player, deck); } else if (switchCardForStraight != null && h.GetRank() == CardRank.HighCard && !wantingDealersUp) { // Potential Inside Straight DoSwitchCard(h, switchCardForStraight, player, deck); } }
public void Play(Player player, CardDeck Deck) { }
static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; CardDeck deck = new CardDeck(); CaribbeanStudPoker caribbean = new CaribbeanStudPoker(); OasisPoker oasis = new OasisPoker(); FourCardPoker fourcard = new FourCardPoker(); FourCardPoker fourcardAcesUp = new FourCardPoker(ACES_UP); createPlayers(); for (int i = 0; i < 1000; i++) { //Console.WriteLine(""); for (int loop = 0; loop < 1; loop++) { playCaribbeanAndOasis(caribbean, oasis, deck); playFourcardAndAcesUp(fourcard, fourcardAcesUp, deck); } } // Caribbean Stud Poker: Console.WriteLine(""); Console.WriteLine("Caribbean Stud Poker:"); Console.WriteLine("Casino: wins = " + caribbean.GetWins() + ", losses = " + caribbean.GetLosses() + ", draws = " + caribbean.GetDraws()); Console.WriteLine("total balance = " + caribbean.GetBalance()); Console.WriteLine(""); Console.WriteLine("Number of Folds = " + caribbean.GetFolds() + ", Number of Calls = " + caribbean.GetCalls()); Console.WriteLine(""); Console.WriteLine("Number of Non Qualified games = " + caribbean.GetNq()); Console.WriteLine("Total Volume: " + caribbean.GetVolume()); Console.WriteLine(""); Console.WriteLine("House's edge: " + caribbean.GetHousesEdge()); Console.WriteLine("---------------------------"); // Oasis Poker: Console.WriteLine("Oasis Poker:"); Console.WriteLine(""); Console.WriteLine("Casino:" + " wins = " + oasis.GetWins() + ", losses = " + oasis.GetLosses() + ", draws = " + oasis.GetDraws()); Console.WriteLine("total balance = " + oasis.GetBalance()); Console.WriteLine(""); Console.WriteLine("Number of Folds = " + oasis.GetFolds() + ", Number of Calls = " + oasis.GetCalls()); Console.WriteLine(""); Console.WriteLine("Number of Non Qualified games = " + oasis.GetNq()); Console.WriteLine(""); Console.WriteLine("Total Volume: " + oasis.GetVolume()); Console.WriteLine("House's edge: " + oasis.GetHousesEdge()); Console.WriteLine("---------------------------"); // Four Card Poker: Aces Up Console.WriteLine("Four Card Poker; Aces Up:"); Console.WriteLine(""); Console.WriteLine("Casino:" + " wins = " + fourcardAcesUp.GetWins() + ", losses = " + fourcardAcesUp.GetLosses() + ", draws = " + fourcardAcesUp.GetDraws()); Console.WriteLine("total balance = " + fourcardAcesUp.GetBalance()); Console.WriteLine(""); Console.WriteLine("Number of Folds = " + fourcardAcesUp.GetFolds() + ", Number of Calls = " + fourcardAcesUp.GetCalls()); Console.WriteLine(""); Console.WriteLine("Total Volume: " + fourcardAcesUp.GetVolume()); Console.WriteLine("House's edge: " + fourcardAcesUp.GetHousesEdge()); Console.WriteLine("---------------------------"); // Four Card Poker: Console.WriteLine("Four Card Poker:"); Console.WriteLine(""); Console.WriteLine("Casino:" + " wins = " + fourcard.GetWins() + ", losses = " + fourcard.GetLosses() + ", draws = " + fourcard.GetDraws()); Console.WriteLine("total balance = " + fourcard.GetBalance()); Console.WriteLine(""); Console.WriteLine("Number of Folds = " + fourcard.GetFolds() + ", Number of Calls = " + fourcard.GetCalls()); Console.WriteLine(""); Console.WriteLine("Total Volume: " + fourcard.GetVolume()); Console.WriteLine("House's edge: " + fourcard.GetHousesEdge()); }
private static void playFourcardAndAcesUp(FourCardPoker fourCard, FourCardPoker acesUp, CardDeck deck) { // new give deck.Shuffle(); for (int i = 0; i < NUMBER_OF_PLAYERS; i++) { Hand playerHand = new Hand(deck.GetCards(FIVE_CARD_POKER)); playerHand = FourCardPoker.SortAndRankHandForFourCard(playerHand); fourCardPlayers[i].SetHand(playerHand); acesUpPlayers[i].SetHand(playerHand); } Hand dealerHand = new Hand(deck.GetCards(FOUR_CARD_DEALER_HAND)); dealerHand = FourCardPoker.SortAndRankHandForFourCard(dealerHand); fourCard.SetHand(dealerHand); acesUp.SetHand(dealerHand); CardDeck acesUpDeck = deck.Clone(); for (int i = 0; i < NUMBER_OF_PLAYERS; i++) { fourCard.Play(fourCardPlayers[i], deck); acesUp.Play(acesUpPlayers[i], acesUpDeck); } }
private static void playCaribbeanAndOasis(CaribbeanStudPoker caribbean, OasisPoker oasis, CardDeck deck) { // new give deck.Shuffle(); for (int i = 0; i < NUMBER_OF_PLAYERS; i++) { Hand playerHand = new Hand(deck.GetCards(FIVE_CARD_POKER)); playerHand = Pokergame.SortAndRankHand(playerHand); caribbeanPlayers[i].SetHand(playerHand); oasisPlayers[i].SetHand(playerHand); } Hand dealerHand = new Hand(deck.GetCards(FIVE_CARD_POKER)); dealerHand = Pokergame.SortAndRankHand(dealerHand); caribbean.SetHand(dealerHand); oasis.SetHand(dealerHand); caribbean.SkipQualification(false); oasis.SkipQualification(false); CardDeck oasisDeck = deck.Clone(); for (int i = 0; i < NUMBER_OF_PLAYERS; i++) { caribbean.Play(caribbeanPlayers[i]); oasis.Play(oasisPlayers[i], oasisDeck); } }
public void Play(Player player, CardDeck deck) { int ante = 1; int bid; //Console.Write(player.GetHand() + "vs " + dealerHand + "- " + player.GetHand().GetRank() + " -"); // Now start to play player.Debitbalance(ante); UpdateBalance(ante); bid = GetRaiseBet(player.GetHand()); if (bid > 0) { player.Debitbalance(bid); player.HandleCalls(); calls++; UpdateBalance(bid); if (player.GetHand().GetRank() > dealerHand.GetRank()) { // Player wins, pay out bid 1-to-1, plus initial ante*2 player.Creditbalance((bid + ante) * 2); player.HandleWins(); UpdateBalance(-(bid + ante) * 2); // Casino loses losses++; //Console.Write(" win, bid = " + bid); } else if (player.GetHand().GetRank() < dealerHand.GetRank()) { // Player lose player.HandleLoss(); // Casino wins wins++; //Console.Write(" loss, bid = " + bid); } else { // Hands are equal. Compare card by card int res = CompareHands(dealerHand, player.GetHand()); if (res == 1) { // Player lose player.HandleLoss(); // Casino wins wins++; //Console.Write(" loss, bid = " + bid); } else { player.Creditbalance((bid + ante) * 2); player.HandleWins(); UpdateBalance(-(bid + ante) * 2); // Casino loses losses++; //Console.Write(" win, bid = " + bid); } } } else { // Player folds player.HandleFold(); folds++; //Console.Write(" fold"); } if (playAcesUp) { // If the player has a Pair of Aces or better, then he shall also be paid after the Aces Up Pay Table int acesUp = AcesUpTable(player.GetHand()); player.Creditbalance(acesUp); UpdateBalance(-(acesUp)); //Console.WriteLine(", Aces Up = " + acesUp + ", balance = " + GetBalance()); } int AcesUpTable(Hand hand) { int toRet = -1; switch (hand.GetRank()) { case CardRank.FOURCARD_Quads: toRet = 50; break; case CardRank.FOURCARD_StraightFlush: toRet = 40; break; case CardRank.FOURCARD_Set: toRet = 8; break; case CardRank.FOURCARD_Flush: toRet = 5; break; case CardRank.FOURCARD_Straight: toRet = 4; break; case CardRank.FOURCARD_TwoPair: toRet = 3; break; case CardRank.FOURCARD_Pair: int playersPairRank = hand.GetPair1()[0].GetRank(); if (playersPairRank == Card.ACE) { toRet = 1; } break; case CardRank.FOURCARD_HighCard: toRet = -1; break; default: break; } return(toRet); } // If the player has at least a three of a kind, then he shall also be paid a Bonus, regardless of the value of the dealer's hand. if (player.GetHand().GetRank() >= CardRank.FOURCARD_Set) { int bonus = BonusTable(player.GetHand()); player.Creditbalance(bonus); player.HandleWins(); UpdateBalance(-(bonus)); //Console.WriteLine(", bonus = " + bonus); } else { //Console.WriteLine(", no bonus"); } }