public void NewGame() { while (CommunityCards.Size != 0) { GameDeck.Return(CommunityCards.Draw()); } foreach (Player player in Players) { while (player.Hand.Size != 0) { GameDeck.Return(player.Hand.Draw()); } } for (int i = 0; i < ActivePlayers.Count; i++) { if (Players[i].Money > -500) { ActivePlayers[i] = true; } } GameDeck.Shuffle(); for (int i = 0; i < ActivePlayers.Count; i++) { if (ActivePlayers[i]) { Players[i].Hand.Return(GameDeck.Draw()); Players[i].Hand.Return(GameDeck.Draw()); } } IncrementBlindLocations(); }
private void Reset() { PlayersAtTable.Clear(); PlayersInCurrentPlay.Clear(); OwnCards.Clear(); CommunityCards.Clear(); }
public void PopCards(int amount, string message) { if (amount > 0) //Pop the appropriate number of cards from the top of the deck { var sb = new StringBuilder(); sb.Append("The " + message + " shows: "); for (int i = 0; i < amount; ++i) { Card popped = Deck.Pop(); if (i == 2 || amount == 1) { sb.Append(popped.Name + "."); } else { sb.Append(popped.Name + ", "); } CommunityCards.Add(popped); } PokerMessage(Dealer, sb.ToString()); } }
public void ResetGame() { CloseGumps(); State = PokerGameState.Inactive; RoundActions = new List <PlayerAction>(); CommunityCards.Clear(); //create and shuffle a new deck Deck = new Deck(); PokerPots.Clear(); ActivePlayers.Clear(); foreach (var player in Players.ToArray()) { player.ClearGame(); } ActivePlayers.AddRange(Players.Where(x => x.Currency > 0)); if (GetActiveElliblePlayersCount() > 1) { BeginGame(); } else { StopIntermission(); ActivePlayers.Clear(); } }
public static void ReturnCards(CommunityCards community, Deck deck) { foreach (Card c in community.Cards) { ReturnCard(c, deck); } community.Cards.Clear(); }
public void CheatCommunityCards(List <Card> cards) { var deck = this.Deck.ToList(); deck.RemoveAll(cards.Contains); CommunityCards.AddRange(cards); this.Deck = new Queue <Card>(deck); }
// Methods /// <summary> /// Draw the community cards to be displayed on the table. /// Creates temporary card, and puts into the ObservableCollection<Card> CommunityCards /// as well as the static PlayerCommCards parameter in PlayerModel that is used so all players know what they have. /// </summary> /// <param name="numCards"></param> public void DrawCommunityCards(int numCards) { for (int i = 0; i < numCards; i++) { Card tempCard = dealer.DrawCard(); CommunityCards.Add(tempCard); PlayerModel.PlayerCommCards.Add(tempCard); } }
private void SetCommunityCards(BoardCards communityCards) { foreach (var card in communityCards) { var newCard = new ReplayerCardViewModel(); newCard.CardId = card.CardIntValue; CommunityCards.Add(newCard); } }
public List <IPlayer> Winners() { var winners = new List <IPlayer>(); foreach (var p in Players) { if (!p.Folded) { // var hand = p.Hand.ToList(); var cardsmoq = new List <Card>(); var formoq = p.Hand.ToList(); foreach (var c in formoq) { cardsmoq.Add((Card)c); } cardsmoq.AddRange(CommunityCards.ToList()); p.StrongestHand = HandLogic.HandCalculator(cardsmoq); } else { var cardsmoq = new List <Card>(); var formoq = p.Hand.ToList(); foreach (var c in formoq) { cardsmoq.Add((Card)c); } p.StrongestHand = new HandStrength(0, HandRank.Fold, cardsmoq); } } var maxHand = 0; foreach (var p in Players) { if (p.StrongestHand.HandStrongessValue > maxHand) { maxHand = p.StrongestHand.HandStrongessValue; } } foreach (var p in Players) { if (p.StrongestHand.HandStrongessValue == maxHand) { winners.Add(p); } } return(winners); }
private void OnCommunityHasBeedDealtACard(CommunityHasBeenDealtACardEvent e) { logger.Debug("Community card dealt: {0}", e.Card); CommunityCards.Add(e.Card); }
public override PlayerAction GetTurn(GetTurnContext context) { #region Preflop if (context.RoundType == GameRoundType.PreFlop) { var handValue = HandStrengthValuationBluffasaurus.PreFlop(this.FirstCard, this.SecondCard); var optimalValueCoeff = 2; var extreme = 64 - optimalValueCoeff; var powerful = 60 - optimalValueCoeff; var normal = 55 - optimalValueCoeff; var weak = 50 - (optimalValueCoeff * 2); var awful = 43 - (optimalValueCoeff * 2); var lowerLimit = 40 - optimalValueCoeff; // if we are first to act on a small blind if (context.MoneyToCall == context.SmallBlind && context.CurrentPot == context.SmallBlind * 3) { inPosition = true; if (handValue >= extreme) { return(PlayerAction.Raise(context.SmallBlind * 20)); } else if (handValue >= powerful) { return(PlayerAction.Raise(context.SmallBlind * 16)); } else if (handValue >= normal) { return(PlayerAction.Raise(context.SmallBlind * 12)); } else if (handValue >= awful) // that makes around 74% of all possible hands { // can be further optimized if (context.SmallBlind > context.MoneyLeft / 50) { return(PlayerAction.CheckOrCall()); } return(PlayerAction.Raise(context.SmallBlind * 10)); } else if (handValue > lowerLimit && context.SmallBlind < context.MoneyLeft / 40) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else // we are on big blind or opp has raised { // opponent has not raised if (context.MoneyToCall == 0) { if (handValue >= extreme) // cards like AA, KK, AKs { return(PlayerAction.Raise(context.SmallBlind * 20)); } else if (handValue >= powerful) { return(PlayerAction.Raise(context.SmallBlind * 16)); } else if (handValue >= awful) // that makes around 74% of all possible hands { // can be further optimized if (context.SmallBlind > context.MoneyLeft / 50) { return(PlayerAction.CheckOrCall()); } return(PlayerAction.Raise(context.SmallBlind * 6)); } else { return(PlayerAction.CheckOrCall()); } } else // opponent has raised { // if opp has raised a lot(has a very strong hand) if (context.MoneyToCall > context.SmallBlind * 8 && context.MoneyToCall > 40) { if (handValue >= extreme) // cards like AA, KK, AKs { return(PlayerAction.Raise(context.SmallBlind * 16)); } else if (handValue >= powerful) { // we have some more money and want to wait for a better shot if (context.MoneyToCall > context.MoneyLeft / 4 && context.MoneyToCall > context.SmallBlind * 6) { return(this.Fold()); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else // opponent has not raised a lot { if (handValue >= extreme) // cards like AA, KK, AKs { return(PlayerAction.Raise(context.SmallBlind * 20)); } else if (handValue >= powerful) { // if we have already raised enough this round if (context.MyMoneyInTheRound > context.SmallBlind * 10) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Raise(context.SmallBlind * 12)); } } else if (handValue >= normal) { return(PlayerAction.CheckOrCall()); } else if (handValue >= weak && (context.MoneyToCall <= 20 || context.MoneyToCall <= context.SmallBlind * 3)) { return(PlayerAction.CheckOrCall()); } else if (handValue >= awful && (context.MoneyToCall <= 20 || context.MoneyToCall <= context.SmallBlind * 2)) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } } } } #endregion #region Flop else if (context.RoundType == GameRoundType.Flop) { var raiseCoeff = context.SmallBlind * 0; if (context.MoneyLeft == 0) { return(PlayerAction.CheckOrCall()); } var flopCardStrength = CardsStrengthEvaluation.RateCards (new List <Card> { FirstCard, SecondCard, CommunityCards.ElementAt(0), CommunityCards.ElementAt(1), CommunityCards.ElementAt(2) }); if (inPosition) { if (flopCardStrength >= 2000) { return(PlayerAction.Raise(context.SmallBlind * 8 + raiseCoeff)); } else if (flopCardStrength >= 1000) { var pairInfo = this.GetPairInfo(); if (pairInfo == 0) { return(PlayerAction.CheckOrCall()); } else { if (pairInfo >= 11) { return(PlayerAction.Raise(context.SmallBlind * 12 + raiseCoeff)); } else { return(PlayerAction.Raise(context.SmallBlind * 8 + raiseCoeff)); } } } else { return(PlayerAction.CheckOrCall()); } } else { // opponent has raised if (context.MoneyToCall > 0) { // a lot if (context.MoneyToCall > context.CurrentPot - context.MoneyToCall && context.MoneyToCall > 50) { if (flopCardStrength >= 3000) { return(PlayerAction.Raise(context.SmallBlind * 30 + raiseCoeff)); } if (flopCardStrength >= 2000) { return(PlayerAction.Raise(context.SmallBlind * 10 + raiseCoeff)); } else if (flopCardStrength >= 1000) { // is common pair logic var pairInfo = this.GetPairInfo(); if (pairInfo == 0) { return(this.Fold()); } else { // money are a lot and we fold if (context.MoneyToCall > context.MoneyLeft / 3 && context.MoneyLeft > 300) { return(this.Fold()); } else { if (pairInfo >= 11) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } } } else { return(this.Fold()); } } else //not a lot { if (flopCardStrength >= 2000) { return(PlayerAction.Raise(context.SmallBlind * 8 + raiseCoeff)); } else if (flopCardStrength >= 1000) { var pairInfo = this.GetPairInfo(); if (pairInfo == 0) { return(PlayerAction.CheckOrCall()); } else { if (pairInfo >= 11) { return(PlayerAction.Raise(context.SmallBlind * 8 + raiseCoeff)); } else { return(PlayerAction.CheckOrCall()); } } } else { if (context.MoneyToCall >= 20) { return(this.Fold()); } else { return(PlayerAction.CheckOrCall()); } } } } else // opp has checked (has bad hand) { if (flopCardStrength >= 2000) { return(PlayerAction.Raise(context.SmallBlind * 8 + raiseCoeff)); } else if (flopCardStrength >= 1000) { return(PlayerAction.Raise(context.SmallBlind * 16 + raiseCoeff)); } return(PlayerAction.CheckOrCall()); } } } #endregion #region Turn else if (context.RoundType == GameRoundType.Turn || context.RoundType == GameRoundType.River) { if (context.RoundType == GameRoundType.River) { inPosition = false; } if (context.MoneyLeft == 0) { return(PlayerAction.CheckOrCall()); } var flopCardStrength = CardsStrengthEvaluation.RateCards (new List <Card> { FirstCard, SecondCard, CommunityCards.ElementAt(0), CommunityCards.ElementAt(1), CommunityCards.ElementAt(2) }); if (flopCardStrength >= 2000) { return(PlayerAction.Raise(context.CurrentPot)); } else { var hand = new List <Card>(); hand.Add(this.FirstCard); hand.Add(this.SecondCard); var ehs = EffectiveHandStrenghtCalculator.CalculateEHS(hand, this.CommunityCards); if (ehs < 0.3) { if (context.MoneyToCall <= context.MoneyLeft / 200) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else if (ehs < 0.5) { if (context.MoneyToCall <= context.MoneyLeft / 40) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else if (ehs < 0.62) { var currentPot = context.CurrentPot; int moneyToBet = (int)(currentPot * 0.55); if (context.MoneyToCall == 0) { return(PlayerAction.Raise(moneyToBet)); } else if (context.MoneyToCall < context.MoneyLeft / 20 || context.MoneyToCall < 50) { if (context.MoneyToCall < moneyToBet && context.MyMoneyInTheRound == 0) { return(PlayerAction.Raise(moneyToBet - context.MoneyToCall + 1)); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else if (ehs < 0.75) { var currentPot = context.CurrentPot; int moneyToBet = (int)(currentPot * 0.75); if (context.MoneyToCall == 0) { return(PlayerAction.Raise(moneyToBet)); } else if (context.MoneyToCall < context.MoneyLeft / 10 || context.MoneyToCall < 70) // TODO: { if (context.MoneyToCall < moneyToBet && context.MyMoneyInTheRound == 0) { return(PlayerAction.Raise(moneyToBet - context.MoneyToCall + 1)); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else if (ehs < 0.85) { var currentPot = context.CurrentPot; int moneyToBet = (int)(currentPot * 0.85); if (context.MoneyToCall == 0) { if (moneyToBet < 50) { moneyToBet = 50; } return(PlayerAction.Raise(moneyToBet)); } else if (context.MoneyToCall < context.MoneyLeft / 2 || context.MoneyToCall < 250) { if (context.MoneyToCall < moneyToBet && context.MyMoneyInTheRound == 0) { return(PlayerAction.Raise(moneyToBet - context.MoneyToCall + 1)); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else { var currentPot = context.CurrentPot; int moneyToBet = currentPot; if (moneyToBet < 80) { moneyToBet = 80; } return(PlayerAction.Raise(moneyToBet)); } } } #endregion return(PlayerAction.CheckOrCall()); // It should never reach this point }
public void AddCommunityCard(Card card) { CommunityCards.Add(card); }
public override PlayerAction GetTurn(GetTurnContext context) { var bigBlind = context.SmallBlind * 2; #region Preflop if (context.RoundType == GameRoundType.PreFlop) { var handValue = HandStrengthValuationBluffasaurus.PreFlop(this.FirstCard, this.SecondCard); var agression = 0; var extreme = 64 - agression; var powerful = 60 - agression; var normal = 56 - agression; // top 40% of cards var weak = 50 - agression; var awful = 45 - agression; // 70% of the cards inPosition = true; // we are first to act on a small blind - we are not in position so we want to play around 70% of the cards and only raise around 40% if (context.MyMoneyInTheRound == context.SmallBlind) { inPosition = false; if (handValue >= extreme) { return(PlayerAction.Raise(bigBlind * 4)); } else if (handValue >= powerful) { return(PlayerAction.Raise(bigBlind * 3)); } else if (handValue >= normal) { return(PlayerAction.Raise(bigBlind * 1)); } else if (handValue >= awful) { return(PlayerAction.CheckOrCall()); } else if (context.MoneyToCall < context.MoneyLeft / (double)100) // lets try our luck if it is cheap enough { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else if (context.MyMoneyInTheRound == bigBlind && context.CurrentPot == context.SmallBlind * 3) // we are to act on big blind { // we are in position and opp has not raised on small blind (probably hasn't a great hand) - we should make him fold most of his hands and if he calls we must be able to defend if (context.MoneyToCall == 0) { if (handValue >= extreme) { return(PlayerAction.Raise(bigBlind * 8)); } else if (handValue >= powerful) { return(PlayerAction.Raise(bigBlind * 6)); } else if (handValue >= normal) { return(PlayerAction.Raise(bigBlind * 4)); } else if (handValue >= weak && bigBlind < context.MoneyLeft / (double)50) // we dont have a great hand either but we can make him sweat about it and we can always fold later { return(PlayerAction.Raise(bigBlind * 2)); } else // that makes around 74% of all possible hands { return(PlayerAction.CheckOrCall()); } } else // opp has raised out of position - we can three bet him TODO: check if this logic can be combined with below else { // opp has raised a lot - we should call him or raise only on our best cards if (context.MoneyToCall >= bigBlind * 8 && context.MoneyToCall >= context.MoneyLeft / (double)25) { if (handValue >= extreme) { return(PlayerAction.Raise(context.MoneyToCall)); } else if (handValue >= powerful) { return(PlayerAction.CheckOrCall()); } else // TODO: here we could open more hands if we know that our opp raises a lot on cheap hands { return(PlayerAction.Fold()); } } else if (context.MoneyToCall >= bigBlind * 4) { if (handValue >= powerful) { return(PlayerAction.Raise(context.MoneyToCall)); } else if (handValue >= normal) { return(PlayerAction.CheckOrCall()); } else if (handValue >= weak && context.MoneyToCall < context.MoneyLeft / (double)30) // we dont have a great hand either but we can make him sweat about it and we can always fold later { return(PlayerAction.CheckOrCall()); } else // that makes around 74% of all possible hands { return(PlayerAction.Fold()); } } else // opp raised with less than 4 big blinds { if (handValue >= normal) { return(PlayerAction.Raise((int)(context.MoneyToCall * 2.5))); } else if (handValue >= weak && bigBlind < context.MoneyLeft / (double)30) // we dont have a great hand either but we can make him sweat about it and we can always fold later { return(PlayerAction.CheckOrCall()); } else if (handValue >= awful && context.MoneyToCall < bigBlind * 2) // that makes around 74% of all possible hands { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } } } else // opp reraises us or we have checked on SB and he has raised { if (handValue >= extreme) { return(PlayerAction.CheckOrCall()); } // opp has raised a lot - we should call him or raise only on our best cards if (context.MoneyToCall >= bigBlind * 8 && context.MoneyToCall >= context.MoneyLeft / (double)25) { if (handValue >= powerful) { return(PlayerAction.CheckOrCall()); } else if (handValue >= normal && context.MyMoneyInTheRound > context.MoneyToCall * 2) // TODO: here we could open more hands if we know that our opp raises a lot on cheap hands { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } else if (context.MoneyToCall >= bigBlind * 4) { if (handValue >= normal) { return(PlayerAction.CheckOrCall()); } else if (handValue >= weak && context.MyMoneyInTheRound > context.MoneyToCall * 2) { return(PlayerAction.CheckOrCall()); } else // that makes around 74% of all possible hands { return(PlayerAction.Fold()); } } else // opp raised with less than 4 big blinds { if (handValue >= normal) { return(PlayerAction.CheckOrCall()); } else if (handValue >= weak && context.MyMoneyInTheRound > context.MoneyToCall * 2) { return(PlayerAction.CheckOrCall()); } else if (handValue >= awful && context.MoneyToCall < bigBlind * 2) // that makes around 74% of all possible hands { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } } } #endregion #region Flop else if (context.RoundType == GameRoundType.Flop) { if (context.MoneyLeft == 0) { return(PlayerAction.CheckOrCall()); } var flopCardStrength = CardsStrengthEvaluation.RateCards (new List <Card> { FirstCard, SecondCard, CommunityCards.ElementAt(0), CommunityCards.ElementAt(1), CommunityCards.ElementAt(2) }); // we are first to act out of position if (context.MoneyToCall == 0 && !inPosition) { if (flopCardStrength >= 4000) { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 2, bigBlind * 4))); // we are 100% sure to win so we want to keep him in the game as long as possible } else if (flopCardStrength >= 3000) { // TODO: 3of a kind logic var threeOfAKindWeHave = this.HowManyOfThreeOfAKindWeHave(); if (threeOfAKindWeHave == 2) { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 2, bigBlind * 4))); } else { return(PlayerAction.CheckOrCall()); } } if (flopCardStrength >= 2000) { if (!this.IsPairInCommunity()) { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 2, bigBlind * 4))); } else { if (this.HaveHighestKicker()) { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 3, bigBlind * 3))); } else { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 4, bigBlind * 2))); } } } else if (flopCardStrength >= 1000) { var pairValue = this.GetPairValue(); if (pairValue == 0) { return(PlayerAction.CheckOrCall()); } else { if (this.IsHighestPair(pairValue)) // we have the highest pair possible { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 2, bigBlind * 4))); } else { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 3, bigBlind * 3))); } } } else { return(PlayerAction.CheckOrCall()); } } else if (context.MyMoneyInTheRound == 0 && inPosition) // we are to act in position { if (context.MoneyToCall == 0) // opp has checked { if (flopCardStrength >= 2000) { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 2, bigBlind * 4))); } else if (flopCardStrength >= 1000) { var pairValue = this.GetPairValue(); if (pairValue != 0) { if (this.IsHighestPair(pairValue)) // we have the highest pair possible { return(PlayerAction.Raise(Math.Max(context.CurrentPot, bigBlind * 8))); } else { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 2, bigBlind * 4))); } } } // we have nothing or pair is in community cards if (this.HaveHighestKicker()) { return(PlayerAction.Raise(Math.Max(context.CurrentPot / 4, bigBlind * 2))); } else { return(PlayerAction.CheckOrCall()); } } } // opp has raised // an awful lot if (context.MoneyToCall >= (context.CurrentPot - context.MoneyToCall) && context.MoneyToCall >= 60) { if (flopCardStrength >= 4000) { return(PlayerAction.Raise(context.MoneyToCall)); } else if (flopCardStrength >= 3000) { // TODO: 3of a kind logic var threeOfAKindWeHave = this.HowManyOfThreeOfAKindWeHave(); if (threeOfAKindWeHave == 2) { return(PlayerAction.Raise(context.MoneyToCall)); } else if (threeOfAKindWeHave == 1 || this.HaveHighestKicker()) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } if (flopCardStrength >= 2000) { if (!this.IsPairInCommunity()) { return(PlayerAction.Raise(context.MoneyToCall)); } else { if (this.HaveHighestKicker()) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } } else { return(this.Fold()); } } else if (context.MoneyToCall > (context.CurrentPot - context.MoneyToCall) / 2 && context.MoneyToCall >= 40) // opp has raised a reasonable amout { if (flopCardStrength >= 4000) { return(PlayerAction.Raise(context.CurrentPot)); } else if (flopCardStrength >= 3000) { // TODO: 3of a kind logic var threeOfAKindWeHave = this.HowManyOfThreeOfAKindWeHave(); if (threeOfAKindWeHave == 2) { return(PlayerAction.Raise(context.CurrentPot)); } else if (threeOfAKindWeHave == 1) { return(PlayerAction.Raise(context.CurrentPot / 2)); } else if (this.HaveHighestKicker()) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } else if (flopCardStrength >= 2000) { if (!this.IsPairInCommunity()) { return(PlayerAction.Raise(context.MoneyToCall)); } else { var pairValue = this.GetPairValue(); if (this.IsHighestPair(pairValue)) { return(PlayerAction.Raise(context.MoneyToCall)); } else { return(PlayerAction.CheckOrCall()); } } } else if (flopCardStrength >= 1000) { var pairValue = this.GetPairValue(); if (pairValue == 0) { return(this.Fold()); } if (this.IsHighestPair(pairValue) || this.HaveHighestKicker()) { return(PlayerAction.CheckOrCall()); } } return(this.Fold()); } else // opp has raised a little { if (flopCardStrength >= 4000) { return(PlayerAction.Raise(context.MoneyToCall * 2)); } else if (flopCardStrength >= 3000) { // TODO: 3of a kind logic var threeOfAKindWeHave = this.HowManyOfThreeOfAKindWeHave(); if (threeOfAKindWeHave == 2) { return(PlayerAction.Raise(context.MoneyToCall * 2)); } else if (threeOfAKindWeHave == 1) { return(PlayerAction.Raise(context.MoneyToCall)); } else if (this.HaveHighestKicker()) { return(PlayerAction.Raise(context.MoneyToCall)); } else { return(PlayerAction.CheckOrCall()); } } else if (flopCardStrength >= 2000) { if (!this.IsPairInCommunity()) { return(PlayerAction.Raise(context.MoneyToCall * 2)); } else { var pairValue = this.GetPairValue(); if (this.IsHighestPair(pairValue)) { return(PlayerAction.Raise(context.MoneyToCall)); } else { return(PlayerAction.CheckOrCall()); } } } else if (flopCardStrength >= 1000) { var pairValue = this.GetPairValue(); if (pairValue == 0) { return(PlayerAction.CheckOrCall()); } if (this.IsHighestPair(pairValue) || this.HaveHighestKicker()) { return(PlayerAction.Raise(context.MoneyToCall / 2)); } } if (this.HaveHighestKicker()) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } } #endregion #region Turn else if (context.RoundType == GameRoundType.Turn || context.RoundType == GameRoundType.River) { if (context.MoneyLeft == 0) { return(PlayerAction.CheckOrCall()); } var flopCardStrength = CardsStrengthEvaluation.RateCards (new List <Card> { FirstCard, SecondCard, CommunityCards.ElementAt(0), CommunityCards.ElementAt(1), CommunityCards.ElementAt(2) }); var hand = new List <Card>(); hand.Add(this.FirstCard); hand.Add(this.SecondCard); var ehs = EffectiveHandStrenghtCalculator.CalculateEHS(hand, this.CommunityCards); // we are first to act out of position - we should always add a little bit of pressure on our opp if (context.MoneyToCall == 0 && !inPosition) { if (ehs < 0.3) { return(PlayerAction.CheckOrCall()); } if (ehs < 0.5) { if (this.HaveHighestKicker()) { return(PlayerAction.Raise(context.CurrentPot / 5)); } else { return(PlayerAction.CheckOrCall()); } } else if (ehs < 0.63) { return(PlayerAction.Raise(context.CurrentPot / 4)); } else if (ehs < 0.75) { return(PlayerAction.Raise(context.CurrentPot / 3)); } else { return(PlayerAction.Raise(context.CurrentPot / 2)); } } else if (context.MyMoneyInTheRound == 0 && inPosition) // we are to act in position { if (context.MoneyToCall == 0) // opp has checked { // he has nothing, but neither have we - we should try to bluff him most of the time, or atleast make him sweat for that money if (ehs < 0.5) { // he has checked as first action previous round - he has nothing => we bluff if (context.PreviousRoundActions.Where(x => x.PlayerName != this.Name).FirstOrDefault().Action == PlayerAction.CheckOrCall()) { return(PlayerAction.Raise(context.CurrentPot)); // bluff - we are trying to make him fold } if (this.HaveHighestKicker()) { return(PlayerAction.Raise(context.CurrentPot / 2)); // we are trying to make him fold } else { return(PlayerAction.Raise(context.CurrentPot / 5)); } } else if (ehs < 0.60) { return(PlayerAction.Raise(context.CurrentPot / 4)); } else if (ehs < 0.70) { return(PlayerAction.Raise(context.CurrentPot / 2)); } else { return(PlayerAction.Raise(context.CurrentPot / 3)); } } } // opp has raised // an awful lot if (context.MoneyToCall >= (context.CurrentPot - context.MoneyToCall)) { if (ehs < 0.60) { return(this.Fold()); } else if (ehs < 0.70) { if (context.MoneyToCall < context.MoneyLeft / 10 || context.MoneyToCall < 70) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else if (ehs < 0.85) { int moneyToBet = (int)(context.CurrentPot * 0.85); if (context.MoneyToCall < context.MoneyLeft / 2 || context.MoneyToCall < 250) { if (context.MoneyToCall < moneyToBet && context.MyMoneyInTheRound == 0) { return(PlayerAction.Raise(moneyToBet - context.MoneyToCall + 1)); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else { return(PlayerAction.Raise(context.MoneyToCall)); } } else if (context.MoneyToCall > (context.CurrentPot - context.MoneyToCall) / 2) // opp has raised a reasonable amout { if (ehs < 0.50) { return(this.Fold()); } else if (ehs < 0.60) { if (context.MoneyToCall < context.MoneyLeft / 10 || context.MoneyToCall < 70) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else if (ehs < 0.75) { int moneyToBet = (int)(context.CurrentPot * 0.75); if (context.MoneyToCall < context.MoneyLeft / 2 || context.MoneyToCall < 250) { if (context.MoneyToCall < moneyToBet && context.MyMoneyInTheRound == 0) { return(PlayerAction.Raise(moneyToBet - context.MoneyToCall + 1)); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else { return(PlayerAction.Raise(context.MoneyToCall)); } } else // opp has raised a little { if (ehs < 0.40) { return(this.Fold()); } else if (ehs < 0.50) { return(PlayerAction.CheckOrCall()); } else if (ehs < 0.60) { if (context.MoneyToCall < context.MoneyLeft / 10 || context.MoneyToCall < 70) { return(PlayerAction.CheckOrCall()); } else { return(this.Fold()); } } else if (ehs < 0.75) { int moneyToBet = (int)(context.CurrentPot * 0.85); if (context.MoneyToCall < context.MoneyLeft / 2 || context.MoneyToCall < 250) { if (context.MoneyToCall < moneyToBet && context.MyMoneyInTheRound == 0) { return(PlayerAction.Raise(moneyToBet - context.MoneyToCall + 1)); } else { return(PlayerAction.CheckOrCall()); } } else { return(this.Fold()); } } else { return(PlayerAction.Raise(context.CurrentPot / 2)); } } } #endregion return(PlayerAction.CheckOrCall()); // It should never reach this point }
public void Draw(List <Card> communityCards) { CommunityCards.AddRange(communityCards); }
public void Draw(Card communityCard) { CommunityCards.Add(communityCard); }
public void Begin() { Players.Clear(); CurrentBet = 0; NextRaise = 0; Steps = 0; PokerLogging.createPokerLog(Dealer.TableName); foreach (PokerPlayer player in Players.Players) { if (player.PendingCredit > 0) { int balance = Banker.GetBalance(player.Mobile, TypeOfCurrency); if ((player.PendingCredit + player.Currency) > Dealer.MinBuyIn && (player.PendingCredit + player.Currency) < Dealer.MaxBuyIn && balance >= player.PendingCredit) { player.Currency += player.PendingCredit; Banker.Withdraw(player.Mobile, TypeOfCurrency, player.PendingCredit); player.Mobile.SendMessage(61, "You have withdrawn " + player.PendingCredit + "."); player.PendingCredit = 0; } else if ((player.PendingCredit + player.Currency) > Dealer.MaxBuyIn && balance >= player.PendingCredit) { int diff = Dealer.MaxBuyIn - player.Currency; if (diff > 0) { player.Currency += diff; Banker.Withdraw(player.Mobile, TypeOfCurrency, diff); player.Mobile.SendMessage(61, "You have withdrawn " + diff + "gp."); player.PendingCredit = 0; } else { player.Mobile.SendMessage(61, "You cannot withdraw any further currency as you are at or above the max buy-in."); player.PendingCredit = 0; } } else if ((player.PendingCredit + player.Currency) < Dealer.MinBuyIn) { player.Mobile.SendMessage(61, "Your current rebuy-in amount does not meet the minimum buy-in for this hand."); player.PendingCredit = 0; } } } List <PokerPlayer> dispose = Players.Players.Where(player => player.RequestLeave || !player.IsOnline() || player.Currency <= 0) .ToList(); foreach (PokerPlayer player in dispose.Where(player => Players.Contains(player))) { RemovePlayer(player); } foreach (PokerPlayer player in Players.Players) { player.ClearGame(); player.Game = this; if (player.Currency >= Dealer.BigBlind && player.IsOnline()) { Players.Round.Add(player); } } if (DealerButton == null) //First round / more player { if (Players.Round.Count == 2) //Only use dealer button and small blind { DealerButton = Players.Round[0]; SmallBlind = Players.Round[1]; BigBlind = null; } else if (Players.Round.Count > 2) { DealerButton = Players.Round[0]; SmallBlind = Players.Round[1]; BigBlind = Players.Round[2]; } else { return; } } else { if (Players.Round.Count == 2) //Only use dealer button and small blind { if (DealerButton == Players.Round[0]) { DealerButton = Players.Round[1]; SmallBlind = Players.Round[0]; } else { DealerButton = Players.Round[0]; SmallBlind = Players.Round[1]; } BigBlind = null; } else if (Players.Round.Count > 2) { int index = Players.Round.IndexOf(DealerButton); if (index == -1) //Old dealer button was lost :( { DealerButton = null; Begin(); //Start over return; } if (index == Players.Round.Count - 1) { DealerButton = Players.Round[0]; SmallBlind = Players.Round[1]; BigBlind = Players.Round[2]; } else if (index == Players.Round.Count - 2) { DealerButton = Players.Round[Players.Round.Count - 1]; SmallBlind = Players.Round[0]; BigBlind = Players.Round[1]; } else if (index == Players.Round.Count - 3) { DealerButton = Players.Round[Players.Round.Count - 2]; SmallBlind = Players.Round[Players.Round.Count - 1]; BigBlind = Players.Round[0]; } else { DealerButton = Players.Round[index + 1]; SmallBlind = Players.Round[index + 2]; BigBlind = Players.Round[index + 3]; } } else { return; } } PokerHand = new PokerHandObject(); PokerHand.Community = new List <Card>(); PokerHand.StartTime = DateTime.Now; PokerHand.PokerGameId = new PokerHandSerial(); PokerActions = new List <PokerActionObject>(); PokerPlayers = new List <PokerPlayerObject>(); CommunityCards.Clear(); Deck = new Deck(); State = PokerGameState.DealHoleCards; PokerLogging.StartNewHand(Dealer.TableName); PokerHand.InitialPlayers = Players.Players.Count; foreach (PokerPlayer player in Players.Players) { var playerobject = new PokerPlayerObject(); playerobject.PokerPlayerId = new PokerPlayerSerial(); playerobject.Serial = player.Mobile.Serial; playerobject.charname = player.Mobile.RawName; playerobject.HoleCards = new List <Card>(); playerobject.PokerGameId = PokerHand.PokerGameId; playerobject.Bankroll = player.Currency; PokerPlayers.Add(playerobject); } if (BigBlind != null) { BigBlind.Currency -= Dealer.BigBlind; CommunityCurrency += Dealer.BigBlind; BigBlind.RoundCurrency = Dealer.BigBlind; BigBlind.RoundBet = Dealer.BigBlind; BigBlind.Bet = Dealer.BigBlind; } else { DealerButton.Currency -= Dealer.BigBlind; CommunityCurrency += Dealer.BigBlind; DealerButton.RoundCurrency = Dealer.BigBlind; DealerButton.RoundBet = Dealer.BigBlind; DealerButton.Bet = Dealer.BigBlind; } SmallBlind.Currency -= Dealer.SmallBlind; CommunityCurrency += Dealer.SmallBlind; SmallBlind.RoundCurrency = Dealer.SmallBlind; SmallBlind.RoundBet = Dealer.SmallBlind; SmallBlind.Bet = Dealer.SmallBlind; NextRaise = Dealer.BigBlind; if (PokerPots == null) { PokerPots = new List <PokerPot>(); } var pokerpotobj = new PokerPot(); if (BigBlind != null) { pokerpotobj.AddtoPot(BigBlind.Bet, BigBlind); pokerpotobj.AddtoPot(SmallBlind.Bet, SmallBlind); } else { pokerpotobj.AddtoPot(SmallBlind.Bet, SmallBlind); } PokerPots.Add(pokerpotobj); if (BigBlind != null) { //m_Players.Push( m_BigBlind ); BigBlind.SetBBAction(); CurrentBet = Dealer.BigBlind; } else { //m_Players.Push( m_SmallBlind ); SmallBlind.SetBBAction(); CurrentBet = Dealer.BigBlind; } if (Players.Next() == null) { return; } NeedsGumpUpdate = true; Timer = new PokerGameTimer(this); Timer.Start(); }
public void DoRoundAction() //Happens once State is changed (once per state) { if (State == PokerGameState.Showdown) { DoShowdown(false); } else if (State == PokerGameState.DealHoleCards) { DealHoleCards(); State = PokerGameState.PreFlop; NeedsGumpUpdate = true; } else if (!IsBettingRound) { int numberOfCards = 0; string round = String.Empty; switch (State) { case PokerGameState.Flop: { numberOfCards += 3; round = "flop"; State = PokerGameState.PreTurn; } break; case PokerGameState.Turn: { ++numberOfCards; round = "turn"; State = PokerGameState.PreRiver; } break; case PokerGameState.River: { ++numberOfCards; round = "river"; State = PokerGameState.PreShowdown; } break; } if (numberOfCards != 0) //Pop the appropriate number of cards from the top of the deck { var sb = new StringBuilder(); sb.Append("The " + round + " shows: "); for (int i = 0; i < numberOfCards; ++i) { Card popped = Deck.Pop(); if (i == 2 || numberOfCards == 1) { sb.Append(popped.Name + "."); } else { sb.Append(popped.Name + ", "); } CommunityCards.Add(popped); PokerHand.Community.Add(popped); } PokerMessage(Dealer, sb.ToString()); Players.Turn.Clear(); NeedsGumpUpdate = true; } } else { if (Players.Turn.Count == Players.Round.Count) { switch (State) { case PokerGameState.PreFlop: State = PokerGameState.Flop; break; case PokerGameState.PreTurn: State = PokerGameState.Turn; break; case PokerGameState.PreRiver: State = PokerGameState.River; break; case PokerGameState.PreShowdown: State = PokerGameState.Showdown; break; } } else if (Players.Turn.Count == 0 && State != PokerGameState.PreFlop) //We need to initiate betting for this round { CurrentBet = Dealer.BigBlind; NextRaise = 0; ResetPlayerActions(); CheckLonePlayer(); AssignNextTurn(); } else if (Players.Turn.Count == 0 && State == PokerGameState.PreFlop) { CheckLonePlayer(); AssignNextTurn(); } } }
public static PokerCombination CreatePokerCombination(Hand hand, CommunityCards community) { PokerCombination result = new PokerCombination(hand, community); var straightGroups = GetStraightGroups(result); var flushGroups = GetFlushGroups(result); var sameValueGroups = GetSameValueGroups(result); // Check for Straight Flush if (straightGroups.Count > 0 && flushGroups.Count > 0) { List <List <Card> > sflushs = new List <List <Card> >(); foreach (var flush in flushGroups) { var str = GetStraightGroups(flush); if (str.Count > 0) { sflushs.Add(str[0]); } } if (sflushs.Count > 0) { if (sflushs[0][0].Value == 14) { result.CombinationType = Combination.RoyalFlush; } else { result.CombinationType = Combination.StraightFlush; } result.HighCard = sflushs[0][0]; return(result); } } // Check for quads if (sameValueGroups.Count > 0) { foreach (var group in sameValueGroups) { if (group.Count > 3) { result.CombinationType = Combination.FourOfAKind; result.HighCard = group[0]; result.HighGroup = group; var remain = result.SortedCards.Except(group).ToList(); result.Kickers.Add(remain[0]); return(result); } } } // Check for full house if (sameValueGroups.Count > 1) { var biggest = sameValueGroups.OrderByDescending(g => g.Count).ToList()[0]; if (biggest.Count > 2) { result.CombinationType = Combination.FullHouse; result.HighCard = biggest[0]; result.HighGroup = biggest; result.LowGroup = sameValueGroups.OrderByDescending(g => g.Count).ToList()[1]; return(result); } } // Return if flush if (flushGroups.Count > 0) { result.CombinationType = Combination.Flush; result.HighGroup = flushGroups[0]; result.HighCard = result.HighGroup[0]; return(result); } // Return if straight if (straightGroups.Count > 0) { result.CombinationType = Combination.Straight; result.HighGroup = straightGroups[0]; result.HighCard = result.HighGroup[0]; return(result); } // Return if tris if (sameValueGroups.Count == 1 && sameValueGroups[0].Count == 3) { result.CombinationType = Combination.ThreeOfAKind; result.HighCard = sameValueGroups[0][0]; result.HighGroup = sameValueGroups[0]; var remain = result.SortedCards.Except(result.HighGroup).ToList(); result.Kickers.Add(remain[0]); result.Kickers.Add(remain[1]); return(result); } // Return if 2 pairs if (sameValueGroups.Count > 1) { result.CombinationType = Combination.TwoPairs; result.HighCard = sameValueGroups[0][0]; result.HighGroup = sameValueGroups[0]; result.LowGroup = sameValueGroups[1]; var remain = result.SortedCards.Except(result.HighGroup).Except(result.LowGroup).ToList(); result.Kickers.Add(remain[0]); return(result); } // Return if a pair if (sameValueGroups.Count == 1) { result.CombinationType = Combination.APair; result.HighCard = sameValueGroups[0][0]; result.HighGroup = sameValueGroups[0]; var remain = result.SortedCards.Except(result.HighGroup).ToList(); result.Kickers.Add(remain[0]); result.Kickers.Add(remain[1]); result.Kickers.Add(remain[2]); return(result); } // If nothing else, it's a high card result.CombinationType = Combination.HighCard; result.HighCard = result.SortedCards[0]; result.Kickers.Add(result.SortedCards[1]); result.Kickers.Add(result.SortedCards[2]); result.Kickers.Add(result.SortedCards[3]); result.Kickers.Add(result.SortedCards[4]); return(result); }