private void DoBettingRound(Stage stage, out int lastToAct) { var bDone = false; var raisesRemaining = _maxNumRaisesPerBettingRound < 0 ? 999 : _maxNumRaisesPerBettingRound; int firstBettorPlayerNum; // calc call /raise amounts req var lastFullPureRaise = _bigBlindSize; int callLevel; var roundBets = _players.ToDictionary(p => p.PlayerNum, p => 0); if (stage == Stage.StagePreflop) { TakeBlinds(roundBets); firstBettorPlayerNum = GetNextActivePlayer(_bigBlindPlayerNum); callLevel = _bigBlindSize; //set this explicitly in case the big blind is short } else { firstBettorPlayerNum = GetNextActivePlayer(_dealerPlayerNum); callLevel = _potMan.MaxContributions(); } var currBettor = firstBettorPlayerNum; lastToAct = GetPrevActivePlayer(currBettor); while (!bDone) { // dont call GetAction if player is already all in var player = _players[currBettor]; if (player.StackSize > 0) { int callAmount; int minRaise; int maxRaise; CalcRequiredBetAmounts(currBettor, callLevel, lastFullPureRaise, out callAmount, out minRaise, out maxRaise); BroadcastAwaitingPlayer(player.PlayerNum); // get the players action ActionType playersAction; int playersBetAmount; int stageMaxBets = roundBets.Max(kvp => kvp.Value); player.GetAction(stage, stageMaxBets, callAmount, minRaise, maxRaise, raisesRemaining, _potMan.Size(), out playersAction, out playersBetAmount); // *** DO ACTION *** if (playersAction == ActionType.Fold) { // if fold then mark player as inactive player.IsActive = false; } else if ((playersAction == ActionType.Call) || (playersAction == ActionType.Raise)) { // if call or raise the take $ from players stack and put in pot TransferMoneyToPot(currBettor, playersBetAmount); roundBets[player.PlayerNum] += playersBetAmount; if (playersAction == ActionType.Raise) { // if raise then update lastToAct to the preceding active player lastToAct = GetPrevActivePlayer(currBettor); if (_maxNumRaisesPerBettingRound > 0) { raisesRemaining--; } // if this raise is less than the minimum (because all in) then we shouldn't count it as a proper raise and shouldn't allow the original raiser to reraise if (playersBetAmount - callAmount > lastFullPureRaise) { lastFullPureRaise = playersBetAmount - callAmount; } if (_potMan.PlayerContributions(currBettor) > callLevel) { callLevel = _potMan.PlayerContributions(currBettor); } } } BroadcastAction(stage, currBettor, playersAction, playersBetAmount, roundBets[player.PlayerNum], callAmount); } // if this player is last to act or only one active player left then bDone = true if ((currBettor == lastToAct) || (GetNumActivePlayers() == 1)) { bDone = true; } else { currBettor = GetNextActivePlayer(currBettor); } } }
public void DisplayShowdown(HandRanker handRanker, PotManager potMan) { int i; // show pots Logger.Log(""); string sLogMsg = "Pots \t"; for (i = 0; i < potMan.Pots.Count(); i++) { sLogMsg += i + "\t"; } sLogMsg += "Total"; Logger.Log(sLogMsg); // !!! only show live players? for (i = 0; i < _numPlayers; i++) { sLogMsg = "Player " + i + "\t"; // !!! show stack size for player here? foreach (var p in potMan.Pots) { int value = 0; if (p.PlayerContributions.ContainsKey(i)) { value = p.PlayerContributions[i]; } sLogMsg += value + "\t"; } sLogMsg += potMan.PlayerContributions(i); Logger.Log(sLogMsg); } sLogMsg = "Total "; foreach (var p in potMan.Pots) { sLogMsg += "\t" + p.Size(); } Logger.Log(sLogMsg); // Show hand ranks Logger.Log(""); Logger.Log("--- Hand Ranks ---"); foreach (var hri in handRanker.HandRanks) { var hand = hri.Hand; sLogMsg = hand.HandRankStr() + " "; for (i = 0; i < hand.NumSubRanks(); i++) { sLogMsg += hand.SubRank(i) + " "; } sLogMsg += "Players (" + string.Join(",", hri.Players) + ")"; Logger.Log(sLogMsg); } Logger.Log(""); }