public override PlayerAction GetTurn(GetTurnContext context) { #region PreFlopLogic if (context.RoundType == GameRoundType.PreFlop) { //checks if we have the button if (context.MyMoneyInTheRound == context.SmallBlind) { hasTheButton = true; } //checks if 3bettedPot; If the pot is big it is! if (context.CurrentPot > (context.SmallBlind * 4)) { is3bettedPot = true; } var playHand = HandStrengthValuation.PreFlop(this.FirstCard, this.SecondCard, hasTheButton); //http://www.holdemresources.net/h/poker-theory/hune/usage.html #region mFactor< 20 if (mFactor < 20) { double nashEquillibriumRatio = 0; if (hasTheButton) { nashEquillibriumRatio = HandStrengthValuation.GetPusherBlindsCount(this.FirstCard, this.SecondCard); } else { nashEquillibriumRatio = HandStrengthValuation.GetCallerBlindsCount(this.FirstCard, this.SecondCard); } //find if we have less money then the effective stack size bool push = context.MoneyLeft <= (nashEquillibriumRatio * (context.SmallBlind * 2)); if (push) { return(PlayerAction.Raise(context.CurrentMaxBet)); } else { if (context.CanCheck) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } } #endregion #region UnplayableHands if (playHand == CardValuationType.Unplayable) { if (context.CanCheck) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } #endregion // raises risky hands only if in position and if it is not a 3betted Pot if (playHand == CardValuationType.Risky && context.MyMoneyInTheRound == context.SmallBlind) { // var smallBlindsTimes = RandomProvider.Next(1, 8); return(PlayerAction.Raise(context.SmallBlind * 6)); } // folds if not in position else if (playHand == CardValuationType.Risky && !hasTheButton) { if (context.CanCheck) { return(PlayerAction.CheckOrCall()); } else { return(PlayerAction.Fold()); } } // if recommended and not in 3bettedPot and a big M RAISES if (playHand == CardValuationType.Recommended) { if (is3bettedPot && mFactor > 100) { return(PlayerAction.CheckOrCall()); } if (is3bettedPot && mFactor > 200) { return(PlayerAction.Fold()); } // var smallBlindsTimes = RandomProvider.Next(6, 10); return(PlayerAction.Raise(context.SmallBlind * 6)); } //needs refactoring if (playHand == CardValuationType.Premium || playHand == CardValuationType.TopPremium) { if (playHand == CardValuationType.TopPremium) { hasTopPremium = true; return(PlayerAction.Raise(context.SmallBlind * 10)); } if (playHand == CardValuationType.Premium) { return(PlayerAction.Raise(context.SmallBlind * 10)); } } // not sure if this doesn't brake everything if (context.CanCheck) { return(PlayerAction.CheckOrCall()); } // not sure if this doesn't brake everything else { return(PlayerAction.Fold()); } } #endregion #region Post-FlopLogic double currentPotRaise = context.CurrentPot * 0.55; int currentPotRaiseInt = (int)currentPotRaise; List <Card> allCards = new List <Card>(this.CommunityCards); allCards.Add(this.FirstCard); allCards.Add(this.SecondCard); HandRankType type = HandEvaluator.GetBestHand(allCards).RankType; var playerFirstHand = ParseHandToString.GenerateStringFromCard(this.FirstCard); var playerSecondHand = ParseHandToString.GenerateStringFromCard(this.SecondCard); string playerHand = playerFirstHand + " " + playerSecondHand; string openCards = string.Empty; foreach (var item in this.CommunityCards) { openCards += ParseHandToString.GenerateStringFromCard(item) + " "; } var chance = MonteCarloAnalysis.CalculateWinChance(playerHand, openCards.Trim()); int Check = 15; int Raise = 60; int AllIn = 85; if (context.MoneyToCall <= (context.SmallBlind * 2)) { return(PlayerAction.CheckOrCall()); } if (chance < Check) { return(PlayerAction.Fold()); } if (chance < Raise) { return(PlayerAction.CheckOrCall()); } else if (chance < AllIn) { if ((int)type >= (int)HandRankType.Pair) { return(PlayerAction.Raise(currentPotRaiseInt)); } else { return(PlayerAction.Raise(context.SmallBlind * 4)); } } else { return(PlayerAction.Raise(context.CurrentMaxBet)); } }
//public override void EndRound(EndRoundContext context) //{ // var opponentMoves = context.RoundActions.Where(x => x.PlayerName != this.Name); // foreach (var oponentAction in opponentMoves) // { // this.opponentActions.Add((int)oponentAction.Action.Type); // } // base.EndRound(context); //} public override PlayerAction GetTurn(GetTurnContext context) { var ourCards = ParseHandToString.GenerateStringFromCard(this.FirstCard) + " " + ParseHandToString.GenerateStringFromCard(this.SecondCard); var gapBetweenOurCards = Hand.GapCount(Hand.ParseHand(ourCards)); var openedCommunityCards = this.CommunityCards; var currentRound = context.RoundType; var openedCardsString = string.Empty; var turn = new Turn(); var myMoney = context.MoneyLeft; var allIn = PlayerAction.Raise(myMoney); var call = PlayerAction.CheckOrCall(); var fold = PlayerAction.Fold(); var smallBlind = context.SmallBlind; var moneyToCall = context.MoneyToCall; if (currentRound != GameRoundType.PreFlop) { for (int i = 0; i < openedCommunityCards.Count; i++) { if (i != 0) { openedCardsString = openedCardsString + " " + ParseHandToString.GenerateStringFromCard(openedCommunityCards.ElementAt(i)); } else { openedCardsString = ParseHandToString.GenerateStringFromCard(openedCommunityCards.ElementAt(i)); } } turn.DecideChanceForAction(ourCards, openedCardsString, currentRound, gapBetweenOurCards); var previous = context.PreviousRoundActions.LastOrDefault().Action; if (previous == null) { if (turn.Call >= 2) { return(call); } else if (turn.Raise == 2) { return(PlayerAction.Raise(smallBlind)); } else if (turn.Raise >= 3) { return(PlayerAction.Raise(smallBlind * 2)); } else if (turn.AllIn >= 2) { return(allIn); } else if (turn.Fold >= 2) { return(fold); } } else if (previous == call) { if (turn.Call >= 2 && (moneyToCall / myMoney < 0.3)) { return(call); } else if (turn.Raise >= 2 && (moneyToCall / myMoney < 0.50)) { return(PlayerAction.Raise(smallBlind)); } else if (turn.AllIn >= 2) { return(PlayerAction.Raise(smallBlind * 2)); } else if (turn.Fold >= 2) { return(fold); } } else if (previous.Type == PlayerActionType.Raise) { if (turn.Call >= 2 && (moneyToCall / myMoney < 0.50)) { return(call); } else if (turn.AllIn >= 2) { return(PlayerAction.Raise(smallBlind * 2)); } else if (turn.Fold >= 2) { return(fold); } } else if (context.IsAllIn) { if (turn.Call >= 2 && (moneyToCall / myMoney < 0.5)) { return(call); } else if (turn.Raise >= 2 && (moneyToCall / myMoney < 0.75)) { return(call); } else if (turn.AllIn >= 2) { return(call); } else if (turn.Fold >= 2) { return(fold); } } } else { if (!context.IsAllIn) { if (turn.Call >= 2) { return(call); } else if (turn.Raise >= 2) { return(PlayerAction.Raise(smallBlind)); } else if (turn.AllIn >= 2) { return(allIn); } else if (turn.Fold >= 2) { return(fold); } } else { if (turn.Call >= 2 && (moneyToCall / myMoney < 0.5)) { return(call); } else if (turn.Raise >= 2 && (moneyToCall / myMoney < 0.75)) { return(call); } else if (turn.AllIn >= 2) { return(call); } else if (turn.Fold >= 2) { return(fold); } } } return(call); }