private static void CheckForFlush(Player player) { var allCards = player.Hand.Concat(deck.BoardCards).ToList();//Combine the board & the players cards. List<int> flushCardsRanks = new List<int>(); for (int a = 0; a < 4; a++) { foreach (Card card in allCards) { if (card.Suit == a) { flushCardsRanks.Add(card.Rank); } } if (flushCardsRanks.Count > 4) { CheckForStraight(player, flushCardsRanks, true); //Sends all cards with same suit for straight check. if (player.HandRank < 5) //No straight/royal flush setted by CheckfotStraight(), setting normal flush. { flushCardsRanks.Sort(); flushCardsRanks.RemoveRange(0, flushCardsRanks.Count - 5); //Leaving top 5 ranks from the flush. flushCardsRanks.Reverse(); List<int> kickers = new List<int>(); kickers.Add(0); //No kickers in Flush. player.SetRank(5, flushCardsRanks, kickers); } break; //Max one flush in a hand. Breaking. } flushCardsRanks.Clear(); } }
public override void CalculateBestAgainst(Player Opponent) { if (DerivedSetup.Naive) { CalculateBestAgainst_Naive(Opponent); } else { // If we're currently at the Flop or Turn, then next is the Turn or River, which is a single additional card. if (Phase == BettingPhase.Turn || Phase == BettingPhase.Flop) { CalculateBestAgainst_SingleCardOptimized(Opponent); } // Otherwise we're preflop and the Flop is next, which may require a special suit reduce. else { if (DerivedSetup.SuitReduce) { CalculateBestAgainst_FlopSuitReduced(Opponent); } else { CalculateBestAgainst_Naive(Opponent); } } } }
public number BestAgainstS(Player Opponent) { //UpdateChildrensPDFs(Opponent); CalculateBestAgainst(Opponent); number FinalEV = EV.Average(); return FinalEV; }
public DealState currentDealState; //preflop (0 cards), flop (3 cards), turn (4 cards), river (5 cards), showdown (showing cards) #endregion Fields #region Constructors public GameState(Player[] players, GameController game) { List<Player> activePlayers = new List<Player>(); foreach (Player p in players) { activePlayers.Add(p); } this.currentDealState = new PreFlopState(activePlayers, game); }
// Constructors public Game(int n_players, Deck deck, int starting_funds = Money.DEFAULT_ORIGINAL_AMOUNT, int buy_in = Money.DEFAULT_BUY_IN, int max_size = Hand.DEFAULT_MAX_SIZE, int big_blind = Money.DEFAULT_BIG_BLIND, int small_blind = Money.DEFAULT_SMALL_BLIND, int ante = Money.DEFAULT_ANTE) { if (n_players < 4) { n_players = 4; } else if (n_players > 6) { n_players = 6; } Random rand = new Random(); this.deck = deck; this.deck.shuffle(); players = new Player[n_players]; player_queue = new Queue<Player>(n_players); string player_1_name = query_player_1_name(); bool is_male_player = query_player_1_gender(); // initialize the players // initialize the bank // empty out the queue // assign and shuffle the deck /* int starting_funds = Money.DEFAULT_ORIGINAL_AMOUNT; int buy_in = Money.DEFAULT_BUY_IN; int big_blind = Money.DEFAULT_BIG_BLIND; int small_blind = Money.DEFAULT_SMALL_BLIND; int ante = Money.DEFAULT_ANTE; int max_size = Hand.DEFAULT_MAX_SIZE; */ bool[] AI_genders; string[] AI_names = choose_AI_names(player_1_name, out AI_genders); players[0] = new Player(starting_funds, buy_in, big_blind, small_blind, ante, deck.draw(5), this.deck, max_size, player_1_name, is_male_player); player_queue.Enqueue(players[0]); for (int i = 1; i < n_players; i++) { Wealth_Types wealth_type = (Wealth_Types)rand.Next((int)Wealth_Types.END); Betting_Types betting_type = (Betting_Types)rand.Next((int)Betting_Types.END); Perception_Types perception_type = (Perception_Types)rand.Next((int)Perception_Types.END); Personality personality = new Personality(wealth_type, betting_type, perception_type); players[i] = new AIPlayer(personality, this.deck, AI_names[i - 1], AI_genders[i - 1]); player_queue.Enqueue(players[i]); } // assign the bank's variables bank = new Money(0, buy_in, big_blind, small_blind, ante); }
public override void _CombineStrats(int p, number t1, number t2, Player player) { t1 = Tools.Restrict(t1); t2 = 1 - t1; number _t1, _t2; if (S != null && B != null && ActivePlayer == player && MyCommunity.AvailablePocket[p]) { RaiseCallFoldData _S = (RaiseCallFoldData)S, _B = (RaiseCallFoldData)B; // Update Raise branch number normalize_r = (t1 * _S.Raise[p] + t2 * _B.Raise[p]); if (normalize_r == 0) { _t1 = _t2 = 0; } else { _t1 = t1 * _S.Raise[p] / normalize_r; _t2 = t2 * _B.Raise[p] / normalize_r; } RaiseBranch._CombineStrats(p, _t1, _t2, player); // Update Call branch number normalize_c = (t1 * _S.Call[p] + t2 * _B.Call[p]); if (normalize_c == 0) { _t1 = _t2 = 0; } else { _t1 = t1 * _S.Call[p] / normalize_c; _t2 = t2 * _B.Call[p] / normalize_c; } CallBranch._CombineStrats(p, _t1, _t2, player); // Update this node's strategy S.Linear(p, t1, S, t2, B); Assert.That(t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1 && (Tools.Equals(t1 + t2, 1) || t1 == 0 && t2 == 0)); Assert.That(_S.IsValid()); } else { _t1 = t1; _t2 = t2; RaiseBranch._CombineStrats(p, _t1, _t2, player); CallBranch._CombineStrats(p, _t1, _t2, player); } }
public override void CalculateBestAgainst(Player Opponent) { Assert.That(ActivePlayer != Player.Undefined); if (!(this is CallFoldNode)) UpdateChildrensPDFs(Opponent); if (ActivePlayer == Opponent) CalculateBest_Inactive(Opponent); else CalculateBest_Active(Opponent); }
public Label displayPlayerInfo(Player player, bool firstLabel) { Label label = new Label(); int width = 1000; int height = 0; if (firstLabel) height = 15; else height = playersInfo[playersInfo.Count - 1].Location.Y + 20; Point point1 = new Point(height, width); label.Location = new Point(height, width); return label; }
public PhaseRoot(Node Parent, CommunityNode Community, int Spent, int Pot, int RootCount) : base(Parent, Spent, Pot) { MyPhaseRoot = this; MyCommunity = Community; Weight = MyCommunity.Weight; Phase = MyCommunity.Phase; InitiallyActivePlayer = MyCommunity.InitiallyActivePlayer; DataOffset = MaxDepth + RootCount; if (Phase == BettingPhase.Turn) DataOffset += Flop.N; if (Phase == BettingPhase.River) DataOffset += Flop.N + Card.N; Initialize(); }
public override void CalculateBestAgainst(Player Opponent) { // First decide strategy for children nodes. Update(PocketP, S, RaiseBranch.PocketP); RaiseBranch.CalculateBestAgainst(Opponent); // For each pocket we might have, calculate what we should do. if (!DerivedSetup.Naive) Data.ChanceToActPrecomputation(PocketP, S, MyCommunity); for (int p1 = 0; p1 < Pocket.N; p1++) { if (!MyCommunity.AvailablePocket[p1]) continue; // Calculate the chance the opponent will raise/fold number RaiseChance; if (DerivedSetup.Naive) { RaiseChance = TotalChance(PocketP, S, p1); } else { RaiseChance = Data.ChanceToActWithExclusion(PocketP, S, p1); } number FoldChance = 1 - RaiseChance; Assert.IsNum(RaiseChance); // Calculate EV for raising and folding. number RaiseEV = FoldChance * Pot + RaiseChance * RaiseBranch.EV[p1]; number FoldEV = RaiseChance * (-Spent); // Decide strategy based on which action is better. if (RaiseEV >= FoldEV) { B[p1] = 1; EV[p1] = RaiseEV; } else { B[p1] = 0; EV[p1] = FoldEV; } Assert.IsNum(EV[p1]); } }
public List<Move> generateLegalMoves(DealState currentDealState, Player player) { List<Move> legalMoves = new List<Move>(); bool canRaise = (player.currentStack >= (currentDealState.currentBet - player.betInRound + currentDealState.game.setRaiseAmount)); bool canCheck = (player.betInRound == currentDealState.currentBet); legalMoves.Add(new Fold()); if (canCheck) { legalMoves.Add(new Check()); } else { int callAmount = currentDealState.currentBet - player.betInRound; if (callAmount > player.currentStack) { callAmount = player.currentStack; } legalMoves.Add(new Call(callAmount)); } if (canRaise) { int increments = (player.currentStack - (currentDealState.currentBet - player.betInRound)) / currentDealState.game.setRaiseAmount; int raiseAmount = 0; int amountStackDeducted = 0; for (int i = 1; i < increments + 1; i++) { raiseAmount = i * currentDealState.game.setRaiseAmount; amountStackDeducted = currentDealState.currentBet - player.betInRound + raiseAmount; legalMoves.Add(new Raise(amountStackDeducted, raiseAmount)); } } return legalMoves; }
public override void _CombineStrats(int p, number t1, number t2, Player player) { t1 = Tools.Restrict(t1); t2 = 1 - t1; number _t1, _t2; if (S != null && B != null && ActivePlayer == player && MyCommunity.AvailablePocket[p]) { // Update Call branch number normalize = (t1 * S[p] + t2 * B[p]); if (normalize == 0) { _t1 = _t2 = 0; } else { _t1 = t1 * S[p] / normalize; _t2 = t2 * B[p] / normalize; } CallBranch._CombineStrats(p, _t1, _t2, player); // Update this node's strategy S.Linear(p, t1, S, t2, B); Assert.That(t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1 && (Tools.Equals(t1 + t2, 1) || t1 == 0 && t2 == 0)); Assert.That(S.IsValid()); } else { _t1 = t1; _t2 = t2; CallBranch._CombineStrats(p, _t1, _t2, player); } }
public BetNode(Node parent, PlayerAction ActionTaken, Player ActivePlayer, int Spent, int Pot, int NumRaises, int DataOffset = 0) : base(parent, Spent, Pot) { switch (ActionTaken) { case PlayerAction.Raise: BetCode += 'r'; break; case PlayerAction.Call: BetCode += 'c'; break; case PlayerAction.Fold: Assert.NotReached(); break; default: BetCode += '/'; break; } Phase = MyPhaseRoot.Phase; Weight = 0; this.ActivePlayer = ActivePlayer; this.NumRaises = NumRaises; this.DataOffset += DataOffset; #if DEBUG InstanceCount++; #endif }
private Actions AI_take_turn(Player player, ref bool is_call, out int player_bet, int turn) { AIPlayer AI = (AIPlayer) player; int call_amount = bank.current_bet - AI.money.current_bet; player_bet = get_AI_bet(AI, is_call, call_amount, turn); return get_AI_action(AI, ref is_call, player_bet, call_amount); }
protected virtual void CalculateBest_Inactive(Player Opponent) { }
protected override void UpdateChildrensPDFs(Player Opponent) { Assert.That(ActivePlayer != Player.Undefined); if (ActivePlayer == Opponent) UpdateChildrensPDFs_Inactive(); else UpdateChildrensPDFs_Active(); base.UpdateChildrensPDFs(Opponent); }
private void update_turn_loop_variables(Actions action, Player player, ref Player original_player, ref bool first_turn_taken, ref bool is_call) { if (action == Actions.FOLD) { player.fold(); if (original_player == player) { original_player = player_queue.Peek(); first_turn_taken = false; } } else if (action == Actions.BET) { is_call = true; original_player = player; first_turn_taken = false; } else if (action == Actions.RAISE) { if (!(original_player == player && first_turn_taken)) { original_player = player; first_turn_taken = false; } } }
public override void CalculateBestAgainst(Player Opponent) { /* Naive implementation. O(N^4) */ if (DerivedSetup.Naive) { // For each pocket we might have, calculate EV. PocketData UpdatedP = new PocketData(); uint PocketValue1, PocketValue2; for (int p1 = 0; p1 < Pocket.N; p1++) { if (!MyCommunity.AvailablePocket[p1]) continue; PocketValue1 = PocketValue[p1]; Assert.That(PocketValue1 < uint.MaxValue); // Update the opponent's pocket PDF using the new information, // (which is that we now know which pocket we have). UpdateOnExclusion(PocketP, UpdatedP, p1); OpCount++; number ShowdownEV = 0; for (int p2 = 0; p2 < Pocket.N; p2++) { if (!MyCommunity.AvailablePocket[p2]) continue; PocketValue2 = PocketValue[p2]; Assert.That(PocketValue2 < uint.MaxValue); if (PocketValue1 == PocketValue2) continue; else if (PocketValue1 > PocketValue2) ShowdownEV += UpdatedP[p2] * Pot; else ShowdownEV -= UpdatedP[p2] * Pot; } EV[p1] = ShowdownEV; Assert.IsNum(EV[p1]); } } else /* Asymptotically optimal implementation. O(N^2) */ { RiverCommunity River = (RiverCommunity)MyCommunity; Data.ProbabilityPrecomputation(PocketP, MyCommunity); number Correction; int _p1; // For each pocket we might have, calculate the chance to win. Data.ResetSummed(); _p1 = 0; while (_p1 < Pocket.N) { int p1 = River.SortedPockets[_p1]; if (!MyCommunity.AvailablePocket[p1]) { _p1++; continue; } // Find next highest pocket int NextHighest = _p1 + 1; uint CurrentPocketValue = River.PocketValue[p1]; while (NextHighest < Pocket.N && River.SortedPocketValue[NextHighest] == CurrentPocketValue) NextHighest++; // For all pockets of equal value, calculate the chance to win for (int EqualValuedPocket = _p1; EqualValuedPocket < NextHighest; EqualValuedPocket++) { int p = River.SortedPockets[EqualValuedPocket]; if (!MyCommunity.AvailablePocket[p]) continue; var pocket1 = Pocket.Pockets[p]; int c1 = pocket1.Cards[0], c2 = pocket1.Cards[1]; number ChanceToWin = Data.SummedChance - Data.SummedChance_OneCardFixed[c1] - Data.SummedChance_OneCardFixed[c2]; Correction = Data.MassAfterExclusion(PocketP, p); if (Correction < Tools.eps) { ChanceToWin = 0; } else { ChanceToWin /= Correction; } EV[p] = ChanceToWin * Pot; Assert.IsNum(EV[p]); } // Total the probability mass of our opponent having a hand with equal value for (int EqualValuedPocket = _p1; EqualValuedPocket < NextHighest; EqualValuedPocket++) { int p = River.SortedPockets[EqualValuedPocket]; if (!MyCommunity.AvailablePocket[p]) continue; var pocket1 = Pocket.Pockets[p]; int c1 = pocket1.Cards[0], c2 = pocket1.Cards[1]; number P = PocketP[p]; Data.SummedChance += P; Data.SummedChance_OneCardFixed[c1] += P; Data.SummedChance_OneCardFixed[c2] += P; } _p1 = NextHighest; } // For each pocket we might have, calculate the chance to lose. Data.ResetSummed(); _p1 = Pocket.N - 1; while (_p1 > 0) { int p1 = River.SortedPockets[_p1]; if (!MyCommunity.AvailablePocket[p1]) { _p1--; continue; } // Find next highest pocket int NextLowest = _p1 - 1; uint CurrentPocketValue = River.PocketValue[p1]; while (NextLowest >= 0 && River.SortedPocketValue[NextLowest] == CurrentPocketValue) NextLowest--; // For all pockets of equal value, calculate the chance to win for (int EqualValuedPocket = _p1; EqualValuedPocket > NextLowest; EqualValuedPocket--) { int p = River.SortedPockets[EqualValuedPocket]; if (!MyCommunity.AvailablePocket[p]) continue; var pocket1 = Pocket.Pockets[p]; int c1 = pocket1.Cards[0], c2 = pocket1.Cards[1]; number ChanceToLose = Data.SummedChance - Data.SummedChance_OneCardFixed[c1] - Data.SummedChance_OneCardFixed[c2]; Correction = Data.MassAfterExclusion(PocketP, p); if (Correction < Tools.eps) ChanceToLose = 0; else ChanceToLose /= Correction; EV[p] -= ChanceToLose * Pot; Assert.IsNum(EV[p]); } // Total the probability mass of our opponent having a hand with equal value for (int EqualValuedPocket = _p1; EqualValuedPocket > NextLowest; EqualValuedPocket--) { int p = River.SortedPockets[EqualValuedPocket]; if (!MyCommunity.AvailablePocket[p]) continue; var pocket1 = Pocket.Pockets[p]; int c1 = pocket1.Cards[0], c2 = pocket1.Cards[1]; number P = PocketP[p]; Data.SummedChance += P; Data.SummedChance_OneCardFixed[c1] += P; Data.SummedChance_OneCardFixed[c2] += P; } _p1 = NextLowest; } } }
private bool should_skip(Player player) { if (player == null || player.should_skip()) { return true; } else { return false; } }
private void update_first_turn_taken(Player player, Player original_player, ref bool first_turn_taken) { if (player != null && player == original_player) { first_turn_taken = true; } }
private Actions human_take_turn(Player player, ref bool is_call, out int player_bet) { Actions action = Actions.END; print_human_turn_output_separator(); player.hand.display(); // initialize while loop variables player_bet = -1; bool innocuous_action = true; while(player_bet < 0 || innocuous_action) { action = Actions.END; while (action == Actions.END) { action = player.choose_action(bank.current_bet, bank.current_amount, is_call); } Console.WriteLine(); // update while loop variable if (action == Actions.CHECK_TELLS) // has to be handled from above the player's scope { Player[] available_players = new Player[player_queue.Count]; int available_player_index = 0; foreach (Player available_player in player_queue) { available_players[available_player_index++] = available_player; } player.check_tells(available_players); } else { player_bet = player.take_action(action, bank.current_bet); } if (player_bet < 0) { player_bet = -1; action = Actions.END; continue; } innocuous_action = action != Actions.BET && action != Actions.RAISE && action != Actions.FOLD && action != Actions.CALL; } print_human_turn_output_separator(); return action; }
private bool is_end_of_turn(Player player, Player original_player, bool first_turn_taken) { if(player != null && player == original_player && first_turn_taken && player.money.current_bet == bank.current_bet) { int original_queue_size = player_queue.Count; player_queue.Enqueue(player); // set the original player as the front of the queue for (int i = 0; i < original_queue_size; i++) { player_queue.Enqueue(player_queue.Dequeue()); } return true; } return false; }
private bool enqueue(Player player) { if(!player.is_out && !player.folded && !player.all_in) { player_queue.Enqueue(player); return true; } else { return false; } }
private int gather_divided_winnings(Player[] winners) { int winnings = bank.withdraw(bank.current_amount); bank.refresh(); winnings /= winners.Length; return winnings; }
private void end_round(Player[] winners, int divided_winnings) { Console.WriteLine("\t\t888888888888888888888888888888888888"); Console.WriteLine("\t\t888888888888888888888888888888888888"); Console.WriteLine(); for (int i = 0; i < players.Length; i++) { for (int j = 0; j < winners.Length; j++) { if (winners[j] == null && !players[i].is_out) { players[i].end_round(false, 0); } else if (players[i] == winners[j]) { // display winning message players[i].end_round(true, divided_winnings); } else if (!players[i].is_out) { players[i].end_round(false, 0); } } } Console.WriteLine(); Console.WriteLine("\t\t888888888888888888888888888888888888"); Console.WriteLine("\t\t888888888888888888888888888888888888"); Console.WriteLine(); reset_queue(); }
public void Hand_StartsEmpty() { Player testPlayer = new Poker.Player(); Assert.IsEmpty(testPlayer.hand); }
public void refreshPlayer(Player player, GameState state) { if (player != null && !(player.outOfMoney() && !player.inHand)) { this.player = player; playerName.Text = player.name; this.chipCount.Text = player.chipCount.ToString(); this.chipsCommitted.Text = player.chipsCommitted.ToString(); this.lastAction.Text = player.lastAction; if (player.human) revealCards(); else if (player.inHand) this.playerCards.Text = "HAS CARDS."; else this.playerCards.Text = "NO CARDS."; if (state.players[state.buttonPos] == player) { playerButton.Image = button; playerButton.Show(); } else playerButton.Hide(); if (state.nextToPlay() == player) { playerAction.Image = action; playerAction.Show(); } else playerAction.Hide(); } else makeEverythingEmpty(); }
private static void CheckForStraight(Player player, List<int> cardRanks, bool couldBeRoyal) { List<int> straightRanks = new List<int>(); if (cardRanks == null) // If null - get board & player hand. { var allCards = player.Hand.Concat(deck.BoardCards).ToList(); cardRanks = (from rank in allCards select rank.Rank).ToList(); } if (cardRanks.IndexOf(14) != -1) //Ace could be the lowest and the highest rank in straight. cardRanks.Add(1); //Adding 1 as the lowest rank if there is an Ace. for (int a = 0; a < cardRanks.Count; a++) { straightRanks.Add(cardRanks[a]); for (int b = 1; b < 7; b++) { if (cardRanks.IndexOf(cardRanks[a] + b) != -1) straightRanks.Add(cardRanks[a] + b); else break; } if (straightRanks.Count > 4) { List<int> kickers = new List<int>(); kickers.Add(0); //No kickers in straight. if (couldBeRoyal) //If method called by CheckForFlush, then set handrank 8 (Royal Flush). { straightRanks.RemoveRange(0, straightRanks.Count - 5); //Leaving top 5 ranks. straightRanks.Reverse(); player.SetRank(8, straightRanks, kickers); } else //Normal straight. { straightRanks.RemoveRange(0, straightRanks.Count - 5);//Leaving top 5 ranks. straightRanks.Reverse(); player.SetRank(4, straightRanks, kickers); } break; //Max one straight. Breaking. } straightRanks.Clear(); } }
private static void CheckForPairs(Player player) { var allCards = player.Hand.Concat(deck.BoardCards).ToList(); List<int> ranks = (from rank in allCards select rank.Rank).ToList(); List<int[]> pairs = new List<int[]>(); //new int array [0] - card rank of the pair, [1] - the lenght of the pair. for (int rank = 2; rank < 15; rank++) { int count = 0; foreach (int otherRank in ranks) if (rank == otherRank) count++; if (count > 1) pairs.Add(new int[2] { rank, count }); //New pair with rank = cardRank & lenght = count. count = 0; } int pairsNumber = pairs.Count; // The number of the existing pairs. if (pairsNumber == 0) { if (player.HandRank < 1) { List<int> cardRanks = (from rank in allCards select rank.Rank).ToList(); cardRanks.Sort(); cardRanks.RemoveRange(0, 2); // Leaving top 5 cards sorted by rank. cardRanks.Reverse(); List<int> cardSum = new List<int>(); cardSum.Add(0); //No cards involved in pairs. player.SetRank(0, cardSum, cardRanks); } } else { if (pairsNumber != 0) { for (int a = 0; a < pairsNumber; a++) { List<int> cardRanks = (from rank in allCards select rank.Rank).ToList(); List<int> cardSum = new List<int>(); //Storing the cards sum ranks. cardRanks.Clear(); cardRanks = (from rank in allCards select rank.Rank).ToList(); int pairRank = pairs[a][0]; int pairLenght = pairs[a][1]; for (int b = 0; b < pairLenght; b++) //Adding the pair card ranks from 2 to 4 times (the pair lenght) cardSum.Add(pairRank); cardRanks.RemoveAll(rank => rank == pairRank); //Removing all cards involved in the pair. int handRank = 0; if (pairLenght == 4) handRank = 7; //Four of a kind. if (pairLenght == 3) handRank = 3; //Three of a kind. if (pairLenght == 2) handRank = 1; //Pair. if (player.HandRank < handRank) { int kickersNumber = 5 - pairLenght; cardRanks.Sort(); cardRanks.RemoveRange(0, cardRanks.Count - kickersNumber);//Leaving the top 3, 2 or 1 kickers (kickersNumber). cardRanks.Reverse(); player.SetRank(handRank, cardSum, cardRanks); } } } if (pairsNumber > 1 && player.HandRank < 7) { List<int> cardRanks = (from rank in allCards select rank.Rank).ToList(); List<int> cardSum = new List<int>(); //Storing the cards sum ranks. List<int> pairsRanks = new List<int>(); List<int> pairsLenght = new List<int>(); for (int a = 0; a < pairsNumber; a++) //Store all pairs and their lenghts. { pairsRanks.Add(pairs[a][0]); pairsLenght.Add(pairs[a][1]); } int highestLenght = pairsLenght.Max(); if (highestLenght == 3) //Full House { int index = pairsLenght.IndexOf(highestLenght); for (int i = 0; i < 3; i++) cardSum.Add(pairsRanks[index]); //Adds the rank ot the pair with lenght = 3. pairsRanks.RemoveAt(index); //Removes this pair. for (int i = 0; i < 2; i++) cardSum.Add(pairsRanks.Max()); //Adds two more ranks from the second highest pair. if (player.HandRank < 6) { List<int> kickers = new List<int>(); kickers.Add(0); // No kickers in Full House. player.SetRank(6, cardSum, kickers); } } if (highestLenght == 2) //Two pairs { for (int a = 0; a < 2; a++) { int highestRank = pairsRanks.Max();//Gets the highest ranks from the pairs. for (int b = 0; b < 2; b++) { cardSum.Add(highestRank); //Adds the ranks. } cardRanks.RemoveAll(rank => rank == highestRank);//Removing the ranks. pairsRanks.Remove(highestRank);//Removing the pair. } if (player.HandRank < 2) { cardRanks.Sort(); cardRanks.RemoveRange(0, 2); //Leaving one kicker. player.SetRank(2, cardSum, cardRanks); } } } } }
public void newSplitPot(Player allInPlayer) { List<Player> eligiblePlayers = new List<Player>(); int sidePotCount = 0; int chipsToMatch = allInPlayer.chipsCommitted; foreach(Player player in players){ if(player.inHand && player.chipsCommitted > 0){ player.chipsCommitted -= chipsToMatch; sidePotCount+= chipsToMatch; eligiblePlayers.Add(player); } } sidePotCount += potCount; potCount = 0; if(sidePotCount > 0) sidePots.Add(new Tuple<int, List<Player>>(sidePotCount, eligiblePlayers)); }
private Player[] determine_winners() { // guard conditions if (player_queue.Count < 1) { return new Player[0]; } Player[] winners = new Player[player_queue.Count]; int index = 0; Hand_Values best_hand_value = (Hand_Values)0; Card_Value best_card_value = (Card_Value)0; // get best hand/card combo foreach (Player player in player_queue) { if (player != null && player.hand != null && !player.folded && !player.is_out) { if (player.hand.best_hand_value > best_hand_value) { best_hand_value = player.hand.best_hand_value; if (player.hand.cards[0] != null) { best_card_value = player.hand.cards[0].value; } else { Console.WriteLine("ERROR: Null card existing in hand when determining round winner."); } } else if (player.hand.best_hand_value == best_hand_value) { if (player.hand.cards[0] != null && player.hand.cards[0].value > best_card_value) { best_card_value = player.hand.cards[0].value; } } } else if (player == null || player.hand == null) { Console.WriteLine("ERROR: Null player or hand possessed by player when determining round winner."); } } foreach (Player player in player_queue) { if (player == null || player.hand == null || player.hand.cards[0] == null) { Console.WriteLine("ERROR: Null exception when determining round winner."); } else if (!player.folded && !player.is_out && player.hand.best_hand_value == best_hand_value && player.hand.cards[0].value == best_card_value) { winners[index++] = player; } } // use tiebreaker to determine the best of the winners Hand[] hands = new Hand[index]; for (int i = 0; i < index; i++) { hands[i] = winners[i].hand; } Card_Value tie_breaking_card = Hand.tie_breaker(hands); // use tie breaking card to figure out who the winner of winners is Player[] winners_of_winners = new Player[winners.Length]; Card_Value best_tie_card_value = Hand.get_best_tie_card(winners[0].hand).value; // find the best tie card value for (int i = 0; i < winners.Length; i++) { if (winners[i] == null) { break; } else { Card best_tie_card = Hand.get_best_tie_card(winners[i].hand); if (best_tie_card.value > best_tie_card_value) { best_tie_card_value = best_tie_card.value; } } } // select the winners of the winners using the tie breaking card value index = 0; for (int i = 0; i < winners.Length; i++) { if (winners[i] == null) { break; } else if (Hand.get_best_tie_card(winners[i].hand).value == best_tie_card_value) { winners_of_winners[index++] = winners[i]; } } // condense Player[] winners_no_nulls = new Player[index]; for (int i = 0; i < index; i++) { winners_no_nulls[i] = winners_of_winners[i]; } return winners_no_nulls; }