public void PlayGame() { gameInterface.DisplayInitialInformation(); this.hand = DealCards(this.hand, new List <int> { 1, 2, 3, 4, 5 }, this.cardDealer); string[] cardsForDisplay = GetCardsForDisplay(this.hand, this.cardMapper, this.cardMapperForUI); gameInterface.DisplayCards(cardsForDisplay); IEnumerable <int> cardsToBeDiscarded = gameInterface.GetCardsToBeDiscarded(this.inputReader); if (cardsToBeDiscarded.Count() > 0) { gameInterface.DisplayInfoAboutCardsDiscarded(cardsToBeDiscarded); this.hand = DealCards(this.hand, cardsToBeDiscarded, this.cardDealer); string[] updatedCardsForDisplay = GetCardsForDisplay(this.hand, this.cardMapper, this.cardMapperForUI); gameInterface.DisplayCards(updatedCardsForDisplay); } HandCombination gameResult = this.evaluator.EvaluateHand(this.hand); CombinationAndPayout resultForDisplay = this.resultMapper.GetCombinationNameAndPayout(gameResult); gameInterface.DisplayGameResult(resultForDisplay); }
/// <summary> /// Method to remove all the touched cards of Player /// deck if they belong to removable rules, /// and add them to discarded deck /// and add top card of discarded deck to Player deck /// </summary> /// <param name="player"></param> /// <param name="tempLongTouchedList"></param> public void MultiCardDiscardedDeckSwap(Player player, Deck tempLongTouchedList) { Debug.Log("Multi Card Discarded Deck Swap Started"); if (HandCombination.IsStraight(player, tempLongTouchedList) == true || HandCombination.isThreeOfKind(player, tempLongTouchedList) == true) { tempLongTouchedList.SortByRankAsc(); Card temp = DiscardedDeck.Deal(); int i = 0; int size = tempLongTouchedList.CardsCount(); while (i < size) { Card removeCard = player.RemoveCard(tempLongTouchedList.GetCardByIndex(i)); DiscardedDeck.Add(removeCard); i++; UnityMainThreadDispatcher.Schedule(SingleSwapAnimationFromDiscardedDeck(PlayerUIMapping.Instance.cardholder[currentPlayerIndex], removeCard, CardDistributionAnimation.instance.playersPosition[currentPlayerIndex], false), 0.1f); } UnityMainThreadDispatcher.Schedule(SingleSwapAnimationFromDiscardedDeck(PlayerUIMapping.Instance.cardholder[currentPlayerIndex], null, CardDistributionAnimation.instance.playersPosition[currentPlayerIndex], true), 0.1f); player.AddToHand(temp); tempLongTouchedList.Clear(); GameView.Instance.isClearMethodCompleted = false; UnityMainThreadDispatcher.Schedule(() => GameView.Instance.LoadClearMethod(), Constants.clearMethodDelay); //UnityMainThreadDispatcher.Instance().Enqueue(SwitchTurnToNextPlayer(false, Constants.turnPlayerDelay)); UnityMainThreadDispatcher.Schedule(() => SwitchTurnToNextPlayer(false, Constants.turnPlayerDelay), 0.5f); } Debug.Log("Multi Card Discarded Deck Swap Completed"); }
private void button22_Click(object sender, EventArgs e) { Hand handhighlights = new Hand(); handhighlights = HandCombination.getHighCard(new Hand(myHand1)); for (int i = 0; i < myHand1.Count(); i++) { for (int j = 0; j < handhighlights.Count(); j++) { if (handhighlights.getCard(j) == myHand1.getCard(i) && handhighlights.getCard(j).getSuit() == myHand1.getCard(i).getSuit()) { myHand1.getCard(i).Highlight(); } } } int x = 0; for (int i = 0; i < myHand1.Count(); i++) { Bitmap bitmap = new Bitmap(myHand1.getCard(i).getImage()); Graphics g = Graphics.FromImage(b2); g.DrawImage(bitmap, 5 + x * 75, 5, 71, 96); x++; } pictureBox1.Image = b2; }
private void button25_Click(object sender, EventArgs e) { handhighlights2 = new Hand(); handhighlights2 = HandCombination.getBestHand(new Hand(myHand2)); for (int i = 0; i < myHand2.Count(); i++) { for (int j = 0; j < handhighlights2.Count(); j++) { if (handhighlights2.getCard(j) == myHand2.getCard(i) && handhighlights2.getCard(j).getSuit() == myHand2.getCard(i).getSuit()) { myHand2.getCard(i).Highlight(); } } } int x = 0; for (int i = 0; i < myHand2.Count(); i++) { Bitmap bitmap = new Bitmap(myHand2.getCard(i).getImage()); Graphics g = Graphics.FromImage(b1); g.DrawImage(bitmap, 5 + x * 75, 5, 71, 96); x++; } pictureBox2.Image = b1; MainList.Items.Add(handhighlights2.ToString()); }
public CombinationAndPayout GetCombinationNameAndPayout(HandCombination combination) { CombinationAndPayout result; switch (combination) { case HandCombination.JacksOrBetter: result.name = "jacks or better"; result.payout = 1; break; case HandCombination.TwoPairs: result.name = "two pairs"; result.payout = 2; break; case HandCombination.ThreeOfAKind: result.name = "three of a kind"; result.payout = 3; break; case HandCombination.Straight: result.name = "straight"; result.payout = 4; break; case HandCombination.Flush: result.name = "flush"; result.payout = 6; break; case HandCombination.FullHouse: result.name = "full house"; result.payout = 9; break; case HandCombination.FourOfAKind: result.name = "four of a kind"; result.payout = 25; break; case HandCombination.StraightFlush: result.name = "straight flush"; result.payout = 50; break; case HandCombination.RoyalFlush: result.name = "royal flush"; result.payout = 800; break; default: result.name = "no win"; result.payout = 0; break; } return(result); }
private void button12_Click(object sender, EventArgs e) { if (HandCombination.isHighCard(new Hand(myHand1))) { MessageBox.Show("This is High Card."); } else { MessageBox.Show("Not High Card."); } }
private void button11_Click(object sender, EventArgs e) { if (HandCombination.isOnePair(new Hand(myHand1))) { MessageBox.Show("This is 1Pair."); } else { MessageBox.Show("Not 1Pair."); } }
private void button9_Click(object sender, EventArgs e) { if (HandCombination.isThreeOfAKind(new Hand(myHand1))) { MessageBox.Show("This is 3Kind."); } else { MessageBox.Show("Not 3Kind."); } }
private void button8_Click(object sender, EventArgs e) { if (HandCombination.isStraight(new Hand(myHand1))) { MessageBox.Show("This is Straight."); } else { MessageBox.Show("Not Straight."); } }
private void button7_Click(object sender, EventArgs e) { if (HandCombination.isFlush(new Hand(myHand1))) { MessageBox.Show("This is Flush."); } else { MessageBox.Show("Not Flush."); } }
/// <summary> /// Method to decide which action to be taken by Player based on call percent calculation /// </summary> private void ChoseActionToPlayAndInformListeners() { int callPercent = GetCallPercent(GameController.Instance.GetPlayers(), this); Debug.Log("Call Percent" + callPercent); if (callPercent >= 85) { listener.SayMinimum(this); } else if (myDeck.CardsCount() < 3) { PickBestCard(myDeck, GameController.Instance.DiscardedDeck.GetTopCard()); } else { int straightResult = HandCombination.IsStraight(this, GameController.Instance.DiscardedDeck.GetTopCard()); Debug.Log("Straight Method result" + straightResult); // int threeOfKindResult = HandCombination.isThreeOfKind(this, GameController.Instance.DealtDeck.GetTopCard()); int threeOfKindResult = HandCombination.isThreeOfKind(this, GameController.Instance.DiscardedDeck.GetTopCard()); Debug.Log("Three of kinds method result" + threeOfKindResult); if (straightResult == 1) //Straight card exist in Player Deck { Debug.Log("Straight Card exist in Player Deck getting it now"); Deck straightCards = HandCombination.GetStraight(this); listener.MultiSwapFromDiscardedDeck(this, straightCards); } else if (straightResult == -1) //Straight card created by deck and discarded deck card combination { Debug.Log("Straight card created by deck and discarded deck card combination"); Card nonStraightCard = HandCombination.CreateStraight(this, GameController.Instance.DiscardedDeck.GetTopCard()); listener.SingleSwapFromDiscardedDeck(this, nonStraightCard); } else if (threeOfKindResult == 1) //Three of kind exist in Player Deck { Debug.Log("Three of kind exist in Player Deck getting it now"); Deck threeOfKind = HandCombination.GetThreeOfKind(this); listener.MultiSwapFromDiscardedDeck(this, threeOfKind); } else if (threeOfKindResult == -1) //Three of kind created using Player deck and Discarded Deck card { Debug.Log("Three of kind created using Player deck and Discarded Deck card"); Card threeOfKindCard = HandCombination.CreateThreeOfKind(this, GameController.Instance.DiscardedDeck.GetTopCard()); listener.SingleSwapFromDiscardedDeck(this, threeOfKindCard); } else { PickBestCard(myDeck, GameController.Instance.DiscardedDeck.GetTopCard()); //IF nothing match, pick AI player deck largest card } } }
//timer to take care of showdown situations private void TimerShowdown_Tick(object sender, EventArgs e) { showdownCount++; if (showdownCount > pokerTable.getPot().getPlayersInPot().Count) { //unhighlights hands and evaluates hands to determine winner(s) for (int i = 0; i < pokerTable[pokerTable.getCurrentIndex()].getHand().Count(); i++) { pokerTable[pokerTable.getCurrentIndex()].getHand()[i].UnHighlight(); } DrawToScreen(); pokerTable.ShowDown(); lblBanner.Text = pokerTable.winnermessage; TimerShowdown.Stop(); TimerWait3Seconds.Start(); } else { //displays hands to the user for (int i = 0; i < pokerTable[pokerTable.getCurrentIndex()].getHand().Count(); i++) { pokerTable[pokerTable.getCurrentIndex()].getHand()[i].UnHighlight(); } int currentIndex = pokerTable.incrementIndexShowdown(pokerTable.getCurrentIndex()); pokerTable.setCurrentIndex(currentIndex); pokerTable[currentIndex].getHand()[0].FaceUp = true; pokerTable[currentIndex].getHand()[1].FaceUp = true; Hand bestHand = HandCombination.getBestHand(new Hand(pokerTable[currentIndex].getHand())); for (int i = 0; i < pokerTable[currentIndex].getHand().Count(); i++) { for (int j = 0; j < bestHand.Count(); j++) { if (bestHand.getCard(j) == pokerTable[currentIndex].getHand().getCard(i) && bestHand.getCard(j).getSuit() == pokerTable[currentIndex].getHand().getCard(i).getSuit()) { pokerTable[currentIndex].getHand().getCard(i).Highlight(); } } } lblBanner.Text = pokerTable[currentIndex].Name + " has: " + Environment.NewLine + bestHand.ToString(); DrawToScreen(); } }
public HandCombProbs(HandCombination handComb, List <Tile.TileProp> necessaryTiles, float prob) { this.handComb = handComb; this.necessaryTiles = necessaryTiles; this.prob = prob; }
public void Run() { int ante = 20; bool anothergame = true; while (anothergame) { // utworzenie potasowanej talii 52 kart deck.Shuffle(); // utworzenie dwóch "rąk" List <Card> dealerHand = new List <Card>(); List <Card> playerHand = new List <Card>(); List <Card> twoHAND = new List <Card>(); twoHAND = deck.handDeck(); for (int i = 0; i < 10; i++) { if (i < 5) { dealerHand.Add(twoHAND[i]); } else { playerHand.Add(twoHAND[i]); } } List <Card> dealerHandCover = Turn(dealerHand); // karta playera uporzadkowana playerHand.Sort(new CardComparer_Value()); //plansza przed Call ale juz z Ante bool beforeCall = true; gambler.SetMoney(gambler.GetMoney() - ante); DisplayTable.DisplayBoard(dealerHandCover, playerHand, ante, 0, gambler.GetMoney(), beforeCall); bool setcal = gambler.SetCall(); if (setcal) { beforeCall = false; gambler.SetMoney(gambler.GetMoney() - 2 * ante); DisplayTable.DisplayBoard(dealerHand, playerHand, ante, 2 * ante, gambler.GetMoney(), beforeCall); HandCombination dealer = Analisis.HandAnalizer(dealerHand); HandCombination player = Analisis.HandAnalizer(playerHand); // sprawdzenie czy ręka delera kwlifikuje sie do porównania if (dealer != HandCombination.nothing) { Hand handpower = new Hand(dealer); int outcome = handpower.CompareTo(player); if (outcome == 1) { Console.WriteLine("You lost 60$"); Console.WriteLine("Press any key"); Console.ReadKey(); gambler.SetMoney(gambler.GetMoney() - 3 * ante); } if (outcome == -1) { Console.WriteLine("You won aggregate money!!!"); Console.WriteLine("Press any key"); int agregate = 1; string generalhand = player.ToString().Substring(0, 2); if (generalhand == "PO") { agregate = 100; } if (generalhand == "po") { agregate = 50; } if (generalhand == "qu") { agregate = 20; } if (generalhand == "fu") { agregate = 7; } if (generalhand == "fl") { agregate = 5; } if (generalhand == "st") { agregate = 4; } if (generalhand == "tr") { agregate = 3; } if (generalhand == "dp") { agregate = 2; } gambler.SetMoney(gambler.GetMoney() + agregate * 3 * ante + 2 * ante); } if (outcome == 0) { Console.WriteLine("draw, get back Call"); Console.WriteLine("Press any key"); Console.ReadKey(); gambler.SetMoney(gambler.GetMoney() + 2 * ante); } } else //dealer: nothing { foreach (Card item in dealerHand) { if (item.Rank == Ranks.Ace || item.Rank == Ranks.King) //reka kwalifikacyjna { Hand handpower = new Hand(dealer); int outcome = handpower.CompareTo(player); if (outcome == 1) { Console.WriteLine("Dealer won, you lost 60$"); Console.WriteLine("Press any key"); Console.ReadKey(); gambler.SetMoney(gambler.GetMoney() - 3 * ante); break; } if (outcome == -1) { Console.WriteLine("You won aggregate money!!!"); Console.WriteLine("Press any key"); Console.ReadKey(); int agregate = 1; string generalhand = player.ToString().Substring(0, 2); if (generalhand == "PO") { agregate = 100; } if (generalhand == "po") { agregate = 50; } if (generalhand == "qu") { agregate = 20; } if (generalhand == "fu") { agregate = 7; } if (generalhand == "fl") { agregate = 5; } if (generalhand == "st") { agregate = 4; } if (generalhand == "tr") { agregate = 3; } if (generalhand == "dp") { agregate = 2; } gambler.SetMoney(gambler.GetMoney() + agregate * 3 * ante + 3 * ante); break; } if (outcome == 0) { Console.WriteLine("draw, get back Call"); Console.WriteLine("Press any key"); Console.ReadKey(); gambler.SetMoney(gambler.GetMoney() + 2 * ante); break; } } else { Console.WriteLine("You get back your Ante & Call plus extra Ante"); Console.WriteLine("Press any key"); Console.ReadKey(); gambler.SetMoney(gambler.GetMoney() + 4 * ante); break; } } } } else { Console.Write("Would you like to play? - press Y: "); string choice2 = Console.ReadLine().ToUpper(); if (choice2 != "Y") { anothergame = false; } } //beforeCall = true; if (gambler.GetMoney() <= 0) { anothergame = false; } } Console.WriteLine("End of the Game. You lost all your money"); }
public PlayerCombination(Card[] cards, HandCombination combination) { this.Cards = cards; this.Combination = combination; this.IsSuccessful = true; }
//most important method in the game, controls the turns of the players private void TimerNextMove_Tick(object sender, EventArgs e) { timerCount++; //condition if everyone folds if (pokerTable.PlayerWon()) { panelBubble.Hide(); pokerTable.setCurrentIndex(pokerTable.incrementIndexShowdown(pokerTable.getCurrentIndex())); pokerTable[pokerTable.getCurrentIndex()].CollectMoney(pokerTable.getPot()); lblBanner.Text = pokerTable[pokerTable.getCurrentIndex()].Message; lblBanner.Show(); TimerNextMove.Stop(); TimerWait3Seconds.Start(); return; } //condition to increment player's turn if (pokerTable.beginNextTurn()) { pokerTable.setCurrentIndex(pokerTable.incrementIndex(pokerTable.getCurrentIndex())); lblBanner.Hide(); //condition to pay small/big blind if (timerCount == 1) { pokerTable.PaySmallBlind(); } else if (timerCount == 2) { pokerTable.PayBigBlind(); } //condition that the current player is not AI, show labels to player else if (pokerTable.getCurrentIndex() == 0) { initalizeButtons(); TimerNextMove.Stop(); return; } //condition for AI else { AIPlayer currentPlayer = (AIPlayer)pokerTable[pokerTable.getCurrentIndex()]; if (difficulty == (int)DIFFICULTY.HARD) { Hand holeCards = new Hand(); holeCards.Add(pokerTable[0].getHand()[0]); holeCards.Add(pokerTable[0].getHand()[1]); currentPlayer.CalculateHandValueHard(holeCards, new Deck(pokerTable.getDeck())); } currentPlayer.MakeADecision(pokerTable.getPot(), pokerTable.decrementIndex(pokerTable.getCurrentIndex())); pokerTable[pokerTable.getCurrentIndex()] = currentPlayer; //grey out form if the AI folds if (currentPlayer.IsFolded()) { panelList[pokerTable.getCurrentIndex()].BackgroundImage = Image.FromFile("inactivebutton.png"); } } updateMove(); if (timerCount > 2 && pokerTable.getCurrentIndex() != 0 && difficulty == 1) { timerCalculate.Start(); } } else { //deal community cards pokerTable.TurnCount = 0; lblBanner.Show(); panelBubble.Hide(); if (pokerTable[0].getHand().Count() == 2) { pokerTable.DealFlop(); lblBanner.Text = "Dealing the Flop"; toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString()); } else if (pokerTable[0].getHand().Count() == 5) { pokerTable.DealTurn(); lblBanner.Text = "Dealing the Turn"; toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString()); } else if (pokerTable[0].getHand().Count() == 6) { pokerTable.DealRiver(); lblBanner.Text = "Dealing the River"; toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString()); } else if (pokerTable[0].getHand().Count() == 7) { //start timer for showdown lblBanner.Text = "Showdown"; TimerNextMove.Stop(); TimerShowdown.Start(); return; } //reset agressor the dealer int dealerPosition = pokerTable.getDealerPosition(); pokerTable.setCurrentIndex(pokerTable.getDealerPosition()); pokerTable.getPot().AgressorIndex = pokerTable.getDealerPosition(); DrawToScreen(); } }