public string GetHandDescription(IEnumerable<Card> holeCards, IEnumerable<Card> communityCards) { string hCards = AggregateCards(holeCards); string bCards = AggregateCards(communityCards); Hand hand = new Hand(hCards, bCards); return hand.Description; }
public uint EvaluateHandValue(IEnumerable<Card> holeCards, IEnumerable<Card> communityCards) { string hCards = AggregateCards(holeCards); string bCards = AggregateCards(communityCards); Hand hand = new Hand(hCards, bCards); return hand.HandValue; }
public List <int> WhoIsWinner() { string board = ""; for (int i = 0; i < cardsOnTable.Count; i++) { board += cardsOnTable[i].getStringForLib(); } List <HoldemHand.Hand> hands = new List <HoldemHand.Hand>(); List <HoldemHand.Hand> sortedHands = new List <HoldemHand.Hand>(); for (int i = 0; i < CurrentHand.Count; i++) { Player player = Players[CurrentHand[i]]; HoldemHand.Hand hand = new HoldemHand.Hand(player.card1.getStringForLib() + " " + player.card2.getStringForLib(), board); hands.Add(hand); } sortedHands = hands.OrderByDescending(x => x.HandValue).ToList(); int tie = 1; for (int i = 0; i < CurrentHand.Count - 1; i++) { if (sortedHands[i].HandValue != sortedHands[i + 1].HandValue) { break; } tie++; } List <int> retVal = new List <int>(); for (int i = 0; i < CurrentHand.Count; i++) { for (int j = 0; j < tie; j++) { if (hands[i] == sortedHands[j]) { retVal.Add(CurrentHand[i]); } } } return(retVal); }
public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards) { if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() == 0) { return(false); } HoldemHand.Hand hand = new HoldemHand.Hand(string.Join("", playerCards.Select(c => c.CardStringValue)), boardCards.ToString()); if (hand.HandTypeValue > HoldemHand.Hand.HandTypes.Pair) { return(true); } if (hand.HandTypeValue == HoldemHand.Hand.HandTypes.Pair) { return(playerCards.Any(x => x.RankNumericValue == boardCards.Max(b => b.RankNumericValue))); } return(false); }
/// <summary> /// The method returns the number of draws that are possible for the /// specified HandType. /// </summary> /// <param name="player">Two card mask making up the players pocket cards</param> /// <param name="board">The community cards</param> /// <param name="dead">Dead cards</param> /// <param name="type">They type of mask to count draws for.</param> /// <returns>The number of draws for this mask type.</returns> public static int DrawCount(string player, string board, string dead, Hand.HandTypes type) { #if DEBUG if (!Hand.ValidateHand(player)) throw new ArgumentException("player fails to Validate"); if (!Hand.ValidateHand(board)) throw new ArgumentException("board fails to Validate"); #endif return DrawCount(Hand.ParseHand(player), Hand.ParseHand(board), Hand.ParseHand(dead), type); }
/// <summary> /// The method returns the number of draws that are possible for the /// specified HandType. Note that DrawCount(pocket, board, dead, type) is not /// necessarily the same as DrawCount(pocket | board, dead, type). /// /// This method returns all possible draws that are the same as the requested type. /// </summary> /// <param name="mask">Hand</param> /// <param name="dead">Dead cards</param> /// <param name="type">They type of mask to count draws for.</param> /// <returns>The number of draws for this mask type.</returns> public static int DrawCount(ulong mask, ulong dead, Hand.HandTypes type) { int retval = 0; #if DEBUG if (BitCount(mask) >= 7) throw new ArgumentException("mask must contain less than 7 cards"); if ((mask & dead) != 0UL) throw new ArgumentException("mask must not contain dead cards"); #endif // Get original mask type Hand.HandTypes playerOrigHandType = Hand.EvaluateType(mask); if (playerOrigHandType >= type) return 0; // Look ahead one card foreach (ulong card in Hand.Hands(0UL, mask | dead, 1)) { // Get new mask value Hand.HandTypes playerNewHandType = Hand.EvaluateType(mask | card); // If the mask improved and it matches the specified type, count it. if (playerNewHandType > playerOrigHandType && playerNewHandType == type) { retval++; } } return retval; }
/// <summary> /// The method returns the number of draws that are possible for the /// specified HandType. This method only returns the counts that improve the /// player's mask rather than just the board. Because of this subtle distinction, /// DrawCount(player, board, dead, type) doesn't necessarily return the same value as /// DrawCount(player | board, dead, type). /// </summary> /// <param name="player">Two card mask making up the players pocket cards</param> /// <param name="board">The community cards</param> /// <param name="dead">Dead cards</param> /// <param name="type">They type of mask to count draws for.</param> /// <returns>The number of draws for this mask type.</returns> public static int DrawCount(ulong player, ulong board, ulong dead, Hand.HandTypes type) { int retval = 0; #if DEBUG if (BitCount(player) != 2) throw new ArgumentException("player must have exactly 2 cards"); if (BitCount(board) != 3 && BitCount(board) != 4) throw new ArgumentException("board must contain 3 or 4 cards"); if (((board | player) & dead) != 0UL) throw new ArgumentException("player and board must not contain dead cards"); #endif // Get original mask value uint playerOrigHandVal = Hand.Evaluate(player | board); if (Hand.HandType(playerOrigHandVal) > (uint)type) return 0; // Look ahead one card foreach (ulong card in Hand.Hands(0UL, board | player | dead, 1)) { // Get new mask value uint playerNewHandVal = Hand.Evaluate(player | board | card); // Get new board value uint boardHandVal = Hand.Evaluate(board | card); // Is the new mask better than the old one? We don't // want to know about supersizing the kickers so this // ensures that mask moved up in mask type. bool handImproved = Hand.HandType(playerNewHandVal) > Hand.HandType(playerOrigHandVal); // This compare ensures we aren't just making the board stronger bool handStrongerThanBoard = playerNewHandVal > boardHandVal; // If the mask improved and it matches the specified type, return true if (handImproved && handStrongerThanBoard && Hand.HandType(playerNewHandVal) == (int)type) { retval++; } } return retval; }
public void TestMoreInstanceOperators() { string board = "2d kh qh 3h qc"; // Create a hand with AKs plus board Hand h1 = new Hand("ad kd", board); // Create a hand with 23 unsuited plus board Hand h2 = new Hand("2h 3d", board); Assert.IsTrue(h1 > h2); Assert.IsTrue(h1 >= h2); Assert.IsTrue(h2 <= h1); Assert.IsTrue(h2 < h1); Assert.IsTrue(h1 != h2); }
public void TestInstanceOperators() { foreach (ulong pocketmask in Hand.Hands(2)) { string pocket = Hand.MaskToString(pocketmask); foreach (ulong boardmask in Hand.RandomHands(0UL, pocketmask, 5, 0.001)) { string board = Hand.MaskToString(boardmask); Hand hand1 = new Hand(pocket, board); Hand hand2 = new Hand(); hand2.PocketMask = pocketmask; hand2.BoardMask = boardmask; Assert.IsTrue(hand1 == hand2, "Equality test failed"); } } }
public double getEquity(HoldemHand.Hand hero, List <Villain> opponents, HoldemHand.Hand board) { ulong heroMask = hero.MaskValue; ulong boardMask = board.MaskValue; string mergedVillainRange = ""; // Will need a more sophisticated method for merging all the villain ranges foreach (Villain v in opponents) { mergedVillainRange += v.range; } // A Pocket Query Returns an array of all // hands that meet the criterion. ulong[] opposingRange = PocketHands.Query(mergedVillainRange); //ulong[] hero = PocketHands.Query("Connected Offsuit"); // Holds stats long heroWins = 0, villainsWin = 0, ties = 0, count = 0; // Iterate through 10000 trials. for (int trials = 0; trials < 10000; trials++) { // Pick a random pocket hand out of // player1's query set //ulong player1Mask = Hand.RandomHand(player1, 0UL, 2); // Pick a random pocket hand for player2 ulong villainMask = HoldemHand.Hand.RandomHand(opposingRange, heroMask, 2); // Pick a random board // Need to write a method for creating a random entire board if preflop, just turn/river on flop etc // Based on the board given parameter //ulong boardMask // = Hand.RandomHand(player1Mask | player2Mask, 5); // Create a hand value for each player uint heroHandValue = HoldemHand.Hand.Evaluate(boardMask | heroMask, 7); uint villainHandValue = HoldemHand.Hand.Evaluate(boardMask | villainMask, 7); // Calculate Winners if (heroHandValue > villainHandValue) { heroWins++; } else if (heroHandValue < villainHandValue) { villainsWin++; } else { ties++; } count++; } return((heroWins + ties / 2.0) / ((double)count) * 100.0); }