public static StrategyTree Convert(string xmlFile, DeckDescriptor deckDescr) { XmlDocument xml = new XmlDocument(); xml.Load(xmlFile); return(Convert(xml, deckDescr)); }
public void Test_Cardsets() { DeckDescriptor dd = new DeckDescriptor("TestDeck", _cardNames1, _cardSets1); Assert.AreEqual(0x00, dd.GetCardSet("").bits); Assert.AreEqual(0x00, dd.GetCardSet(" ").bits); Assert.AreEqual(0x01, dd.GetCardSet("Q").bits); Assert.AreEqual(0x01, dd.GetCardSet("Q ").bits); Assert.AreEqual(0x01, dd.GetCardSet(" Q").bits); Assert.AreEqual(0x01, dd.GetCardSet(" Q ").bits); Assert.AreEqual(0x11, dd.GetCardSet("Q A").bits); Assert.AreEqual(0x11, dd.GetCardSet("A Q").bits); Assert.AreEqual(0x11, dd.GetCardSet(" Q A").bits); Assert.AreEqual(0x11, dd.GetCardSet("A Q").bits); Assert.AreEqual(0x11, dd.GetCardSet("A Q ").bits); Assert.AreEqual(0x00, dd.GetCardSet(new string[] {}).bits); Assert.AreEqual(0x01, dd.GetCardSet(new string[] { "Q" }).bits); Assert.AreEqual(0x11, dd.GetCardSet(new string[] { "Q", "A" }).bits); Assert.AreEqual(0x11, dd.GetCardSet(new string[] { "A", "Q" }).bits); Assert.AreEqual(0x00, dd.GetCardSet(new int[] { }).bits); Assert.AreEqual(0x13, dd.GetCardSet(new int[] { 0, 2, 1 }).bits); Assert.AreEqual(0x13, dd.GetCardSet(new int[] { 1, 2, 0 }).bits); Assert.AreEqual(0x00, dd.GetCardSet(new int[] { 0, 2, 1 }, 1, 0).bits); Assert.AreEqual(0x12, dd.GetCardSet(new int[] { 0, 2, 1 }, 1, 2).bits); Assert.AreEqual(0x12, dd.GetCardSet(new int[] { 0, 1, 2 }, 1, 2).bits); }
public void Test_Strings() { DeckDescriptor dd = new DeckDescriptor("TestDeck", _cardNames1, _cardSets1); Assert.AreEqual("", dd.GetCardNames(new CardSet { bits = 0x00 })); Assert.AreEqual("A Q", dd.GetCardNames(new CardSet { bits = 0x11 })); Assert.AreEqual("A K Q", dd.GetCardNames(new CardSet { bits = 0x13 })); Assert.AreEqual(new string[] {}, dd.GetCardNamesArray(new CardSet { bits = 0x00 })); Assert.AreEqual(new string[] { "A", "Q" }, dd.GetCardNamesArray(new CardSet { bits = 0x11 })); Assert.AreEqual(new string[] { "A", "K", "Q" }, dd.GetCardNamesArray(new CardSet { bits = 0x13 })); Assert.AreEqual(new string[] { }, dd.GetCardNamesArray(new int[] { })); Assert.AreEqual(new string[] { "A", "K" }, dd.GetCardNamesArray(new int[] { 2, 1 })); Assert.AreEqual(new string[] { "A", "K", "Q" }, dd.GetCardNamesArray(new int[] { 2, 1, 0 })); Assert.AreEqual(new string[] { }, dd.GetCardNamesArray(new int[] { 2, 1, 0 }, 1, 0)); Assert.AreEqual(new string[] { "K" }, dd.GetCardNamesArray(new int[] { 2, 1 }, 1, 1)); Assert.AreEqual(new string[] { "A", "K" }, dd.GetCardNamesArray(new int[] { 2, 1, 0 }, 0, 2)); }
public void Test_XmlSerialization() { DeckDescriptor dd = new DeckDescriptor("TestDeck", _cardNames1, _cardSets1); StringBuilder sb = new StringBuilder(); using (TextWriter tw = new StringWriter(sb)) { dd.XmlSerialize(tw); } Console.WriteLine(sb.ToString()); DeckDescriptor dd2; using (TextReader textReader = new StringReader(sb.ToString())) { dd2 = XmlSerializerExt.Deserialize <DeckDescriptor>(textReader); } dd2.ConstructFromXml(null); Assert.IsNotNull(dd2); Assert.AreEqual(dd.Name, dd2.Name); Assert.AreEqual(dd.Size, dd2.Size); Assert.AreEqual(dd.CardNames, dd2.CardNames); Assert.AreEqual(dd.CardSets, dd2.CardSets); Assert.AreEqual(dd.FullDeck, dd2.FullDeck); Assert.AreEqual(dd.FullDeckIndexes, dd2.FullDeckIndexes); }
public void Test_Convert() { DeckDescriptor dd = StdDeck.Descriptor; Assert.AreEqual(CardSet.Empty, NormRank.Convert(CardSet.Empty)); Assert.AreEqual(dd.FullDeck, NormRank.Convert(dd.FullDeck)); CardSet cs = new CardSet { bits = 0xFFFFFFFFFFFFFFFF }; Assert.AreEqual(cs, NormRank.Convert(cs)); Assert.AreEqual(dd.GetCardSet("Ac"), NormRank.Convert(dd.GetCardSet("Ac"))); Assert.AreEqual(dd.GetCardSet("Ac"), NormRank.Convert(dd.GetCardSet("Ad"))); Assert.AreEqual(dd.GetCardSet("Ac"), NormRank.Convert(dd.GetCardSet("Ah"))); Assert.AreEqual(dd.GetCardSet("Ac"), NormRank.Convert(dd.GetCardSet("As"))); Assert.AreEqual(dd.GetCardSet("Ac Kc"), NormRank.Convert(dd.GetCardSet("Ac Kc"))); Assert.AreEqual(dd.GetCardSet("Ac Kc"), NormRank.Convert(dd.GetCardSet("Ac Kd"))); Assert.AreEqual(dd.GetCardSet("Ac Kc"), NormRank.Convert(dd.GetCardSet("Ad Kc"))); Assert.AreEqual(dd.GetCardSet("Ac Kc"), NormRank.Convert(dd.GetCardSet("As Kh"))); Assert.AreEqual(dd.GetCardSet("3c 3d"), NormRank.Convert(dd.GetCardSet("3c 3d"))); Assert.AreEqual(dd.GetCardSet("3c 3d"), NormRank.Convert(dd.GetCardSet("3c 3h"))); Assert.AreEqual(dd.GetCardSet("3c 3d"), NormRank.Convert(dd.GetCardSet("3s 3h"))); Assert.AreEqual(dd.GetCardSet("2c 3c 3d 4c 4d 4h 6c 6d 6h 6s"), NormRank.Convert(dd.GetCardSet("2d 3s 3h 4c 4h 4d 6s 6d 6h 6c"))); }
void VerifyPreflopPockets(HsSdKMeansAdaptiveCa ca) { DeckDescriptor dd = StdDeck.Descriptor; int[] hand; hand = dd.GetIndexes("Ac Ah"); Assert.AreEqual(7, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Ac Kc"); Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Ac Kh"); Assert.AreEqual(5, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("5s 5h"); Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("7s 8s"); Assert.AreEqual(3, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("8s 7d"); Assert.AreEqual(2, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("7c 2d"); Assert.AreEqual(1, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Qc 2d"); Assert.AreEqual(0, ca.GetAbstractCard(hand, hand.Length)); }
public void Test_HasDuplicates() { DeckDescriptor dd = new DeckDescriptor("TestDeck", new string[] { "Q", "K", "A" }, _cardSets1); Assert.IsFalse(dd.HasDuplicates); dd = new DeckDescriptor("TestDeck", new string[] { "Q", "Q", "A" }, _cardSets1); Assert.IsTrue(dd.HasDuplicates); }
public static StrategyTree Convert(XmlDocument xml, DeckDescriptor deckDescr) { XmlToStrategyTree conv = new XmlToStrategyTree { DeckDescr = deckDescr }; conv.Walk(xml, xml.DocumentElement); return(conv.StrategyTree); }
public void Test_GetAbstractCard() { Props parameters = XmlSerializerExt.Deserialize <Props>(Path.Combine(_testResDir, "ca-hssd-ahvo-km.xml")); HsSdAhvoKMeansAdaptiveCa ca = CalculateCa(parameters, new int[] { 0, 5000, 5000, 5000 }, 1); VerifyPreflopPockets(ca); DeckDescriptor dd = StdDeck.Descriptor; int[] hand; // In comments there are normalized values to verify in debugger. #region Preflop bucket 7 (AA) //------------------------------------------------------------ // 0.61537 0.42559 0.09124 hand = dd.GetIndexes("Ac As Kh 5h 2d"); Assert.AreEqual(3, ca.GetAbstractCard(hand, hand.Length)); // 0.63778 0.43364 0.35852 hand = dd.GetIndexes("Ad As 7s 7h 5s"); Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length)); #endregion #region Preflop bucket 7 (AA), flop bucket 4 hand = dd.GetIndexes("Ac Ah Td Jh Js 5h"); Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 1)); // 0.647707503 0.222747622 0.335863970 Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Ad Ah 5d 5s Ks 2d"); Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 1)); // 0.642999891 0.228836240 0.187371225 Assert.AreEqual(7, ca.GetAbstractCard(hand, hand.Length)); #endregion #region Preflop bucket 7 (AA), flop bucket 4, turn bucket 6 hand = dd.GetIndexes("Ac Ad 2h Qd Qh 3s 2s"); Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 2)); Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length - 1)); // 0.20689665 0.00000000 0.44819598 Assert.AreEqual(1, ca.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Ad Ah Qd Th Td 7c Jd"); Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 2)); Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length - 1)); // 0.22068975 0.00000000 0.16117185 Assert.AreEqual(2, ca.GetAbstractCard(hand, hand.Length)); #endregion }
public void Test_Calculate_Range() { DeckDescriptor d = StdDeck.Descriptor; CardSet[] range1 = new CardSet[] { d.GetCardSet("Ac Ah"), d.GetCardSet("Kc Kd") }; CardSet[] range2 = new CardSet[] { d.GetCardSet("7h 6h"), d.GetCardSet("5c 4d") }; PocketEquity.Result r = PocketEquity.Calculate(range1, range2); Assert.AreEqual(0.79960, r.Equity, 0.000005); Assert.AreEqual(4, r.Count); }
/// <summary> /// Returns an array containing enumerated combinations. /// </summary> public static CardSet[] Combin(DeckDescriptor deckDescr, int count, CardSet sharedCards, CardSet deadCards) { CardSet unused = deadCards | sharedCards; int combCount = (int)EnumAlgos.CountCombin(deckDescr.Size - unused.CountCards(), count); CombinArrayParams p = new CombinArrayParams(); p.arr = new CardSet[combCount]; Combin(deckDescr, count, sharedCards, deadCards, OnCombinArray, p); return(p.arr); }
public void Test_HandToToKind() { DeckDescriptor deck = StdDeck.Descriptor; Assert.AreEqual(HePocketKind._AQo, HePocket.HandToKind(deck.GetIndexes("Ac Qd"))); Assert.AreEqual(HePocketKind._AQo, HePocket.HandToKind(deck.GetIndexes("As Qc"))); Assert.AreEqual(HePocketKind._22, HePocket.HandToKind(deck.GetIndexes("2s 2c"))); Assert.AreEqual(HePocketKind._32s, HePocket.HandToKind(deck.GetIndexes("2s 3s"))); Assert.AreEqual(HePocketKind._32s, HePocket.HandToKind(deck.GetIndexes("3c 2c"))); }
public void Test_CalculateFast() { DeckDescriptor dd = StdDeck.Descriptor; int[] hand; float[] hssd; // Compare with values calculated by another implementation. hand = dd.GetIndexes("Kh Kd"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.0620, hssd[1], 0.00005); hand = dd.GetIndexes("4s 3s"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.2029, hssd[1], 0.00005); hand = dd.GetIndexes("Ac Ah"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.1060, hssd[1], 0.00005); hand = dd.GetIndexes("7c 6c 8c 5c Ad"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.2377, hssd[1], 0.00005); hand = dd.GetIndexes("7c 6c 8c 5c Ad"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.3908, hssd[1], 0.00005); hand = dd.GetIndexes("7c 6c 8c 5c Ad Qs"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.4038, hssd[1], 0.00005); hand = dd.GetIndexes("9d 9h 2c Qs Ah"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.0805, hssd[1], 0.00005); hand = dd.GetIndexes("9d 9h 2c Qs Ah"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.Sd3); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.1273, hssd[1], 0.00005); hand = dd.GetIndexes("9d 9h 2c Qs Ah Ks"); hssd = HsSd.CalculateFast(hand, HsSd.SdKind.SdPlus1); Assert.AreEqual(HandStrength.CalculateFast(hand), hssd[0], 0.00005); Assert.AreEqual(0.1125, hssd[1], 0.00005); }
public void Test_KindToHand() { DeckDescriptor deck = StdDeck.Descriptor; int[] hand = HePocket.KindToHand(HePocketKind._AA); Assert.AreEqual(deck.GetIndexes("Ac Ad").ToArray(), hand); hand = HePocket.KindToHand(HePocketKind._KQo); Assert.AreEqual(deck.GetIndexes("Kc Qd").ToArray(), hand); hand = HePocket.KindToHand(HePocketKind._54s); Assert.AreEqual(deck.GetIndexes("4c 5c").ToArray(), hand); }
public void Test_CardSetToKind() { Assert.AreEqual(169, (int)HePocketKind.__Count); DeckDescriptor deck = StdDeck.Descriptor; Assert.AreEqual(HePocketKind._AQo, HePocket.CardSetToKind(deck.GetCardSet("Ac Qd"))); Assert.AreEqual(HePocketKind._AQo, HePocket.CardSetToKind(deck.GetCardSet("As Qc"))); Assert.AreEqual(HePocketKind._22, HePocket.CardSetToKind(deck.GetCardSet("2s 2c"))); Assert.AreEqual(HePocketKind._32s, HePocket.CardSetToKind(deck.GetCardSet("2s 3s"))); Assert.AreEqual(HePocketKind._32s, HePocket.CardSetToKind(deck.GetCardSet("3c 2c"))); }
public void Test_GetBucket() { // Fix number of buckets to get exact abstract cards. string minBucketsCounts = "8 7 6 5"; string maxBucketsCounts = "8 7 6 5"; HsKMeansAdaptiveCa b = CalculateCa(minBucketsCounts, maxBucketsCounts, "0.1 0.1 0.1 0.1", new int[] { 0, 1000, 1000, 1000 }, false); DeckDescriptor dd = StdDeck.Descriptor; int[] hand; // Preflop hand = dd.GetIndexes("Ac Ah"); Assert.AreEqual(7, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("7c 2d"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("3d 2c"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // Flop hand = dd.GetIndexes("Ac Ah As Ad 2h"); Assert.AreEqual(6, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("2c 3d As Ks Qh"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // Turn hand = dd.GetIndexes("Ac Ah As Ad 2h 2d"); Assert.AreEqual(5, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("6c 7c 3c 4c 5c As"); Assert.AreEqual(5, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("2c 3d 7s 5s Qh 9d"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // River hand = dd.GetIndexes("Ac Ah As Ad 2h 2d Qh"); Assert.AreEqual(4, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("6c 7c 8d 4c 5c As 8c"); Assert.AreEqual(4, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("2c 3d As Ks Qh 9d 6h"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // Runner - runner hand = dd.GetIndexes("8c 7c"); Assert.AreEqual(2, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("8c 7c Ad Qc Jd"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("8c 7c Ad Qc Jd 4c"); int abstrCard = b.GetAbstractCard(hand, hand.Length); Assert.IsTrue(0 < abstrCard && abstrCard < 5, "Not worst, not best"); hand = dd.GetIndexes("8c 7c Ad Qc Jd 4c 5c"); Assert.AreEqual(4, b.GetAbstractCard(hand, hand.Length)); }
public void Test_Properties() { DeckDescriptor dd = new DeckDescriptor("TestDeck", _cardNames1, _cardSets1); Assert.AreEqual("TestDeck", dd.Name); Assert.AreEqual(_cardNames1.Length, dd.Size); Assert.AreEqual(_cardNames1, dd.CardNames); Assert.AreEqual(_cardSets1, dd.CardSets); Assert.AreEqual(0x13, dd.FullDeck.bits); Assert.AreEqual(new int[] { 0, 1, 2 }, dd.FullDeckIndexes); Assert.IsFalse(dd.HasDuplicates); }
public void Test_SD3_UnnormalizedAdaptive() { Props parameters = XmlSerializerExt.Deserialize <Props>(Path.Combine(_testResDir, "ca-hssd-km.xml")); parameters.Set("SdKind", "Sd3"); parameters.Set("NormalizeHandValues", "false"); parameters.Set("MinBucketCounts", "8 10 10 1"); parameters.Set("MaxBucketCounts", "8 10 10 4"); parameters.Set("ClusterSizes0", "0 0.05 0.05 0.05"); parameters.Set("ClusterSizes1", "0 2 2 0"); HsSdKMeansAdaptiveCa ca = CalculateCa(parameters, new int[] { 0, 5000, 5000, 200 }, 1); VerifyPreflopPockets(ca); DeckDescriptor dd = StdDeck.Descriptor; int[] hand; // In comments there are normalized values. #region Preflop bucket 3 (87s) //------------------------------------------------------------ // 0.572431087493896 0.380353838205338 hand = dd.GetIndexes("7d 8d 5d 5h 4d"); Assert.AreEqual(5, ca.GetAbstractCard(hand, hand.Length)); // 0.57322484254837 0.173631072044373 hand = dd.GetIndexes("7c 8c 7s 2s As"); Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length)); //------------------------------------------------------------ #endregion #region Buckets 4,9,9 (adapted to one cluster, make sure min and max hs go to the same bucket 0) // Min hs // 0.953535377979279 0 hand = dd.GetIndexes("5h 5s 3s 5c 3d 2c 3c"); Assert.AreEqual(0, ca.GetAbstractCard(hand, hand.Length)); // Max hs // 1 0 hand = dd.GetIndexes("5h 5s 3d 5d 5c Jc 2h"); Assert.AreEqual(0, ca.GetAbstractCard(hand, hand.Length)); //------------------------------------------------------------ #endregion }
public void Test_CountEquiv() { DeckDescriptor dd = StdDeck.Descriptor; Assert.AreEqual(1, NormRank.CountEquiv(CardSet.Empty, dd)); Assert.AreEqual(4 * 4 * 4 * 4, NormRank.CountEquiv(dd.GetCardSet("Ac Kd Qc Jh"), dd)); Assert.AreEqual(16, NormRank.CountEquiv(dd.GetCardSet("Ac Kd"), dd)); Assert.AreEqual(4, NormRank.CountEquiv(dd.GetCardSet("Kd"), dd)); Assert.AreEqual(6, NormRank.CountEquiv(dd.GetCardSet("Kc Kd"), dd)); Assert.AreEqual(4, NormRank.CountEquiv(dd.GetCardSet("Kc Kd Ks"), dd)); Assert.AreEqual(1, NormRank.CountEquiv(dd.GetCardSet("7c 7d 7s 7h"), dd)); }
public DealRecord(GameRecord cfg, DeckDescriptor deckDescr, SequenceRng randomDealer) { _cfg = cfg; _deckDescr = deckDescr; _randomDealer = randomDealer; // Loop through actions and // - find the fixed cards // - count random cards // - count enumerated cards for (int a = 0; a < _cfg.Actions.Count; ++a) { PokerAction action = _cfg.Actions[a]; if (!action.IsDealerAction()) { continue; } string[] cards = action.Cards.Split(_separator, StringSplitOptions.RemoveEmptyEntries); foreach (string card in cards) { if (card == "?") { _randomCount++; } else if (card.Length > 0 && card.Substring(0, 1) == "#") { int idx = int.Parse(card.Substring(1)); while (_enumCounts.Count <= idx) { _enumCounts.Add(0); _enumCombosCounts.Add(0); _enumCombos.Add(new List <CardSet>()); } _enumCounts[idx]++; } else { _fixedCards.UnionWith(_deckDescr.GetCardSet(card)); } } } // Count enumerated combinations. int deadCards = _fixedCards.CountCards(); for (int i = 0; i < _enumCounts.Count; ++i) { _enumCombosCounts[i] = EnumAlgos.CountCombin(_deckDescr.Size - deadCards, _enumCounts[i]); deadCards += _enumCounts[i]; } }
public void Test_CanLose() { DeckDescriptor d = StdDeck.Descriptor; Assert.IsFalse(HeHelper.CanLose(d.GetIndexes("Ac Ad Ah As 2c 2d 3c"))); Assert.IsFalse(HeHelper.CanLose(d.GetIndexes("7c 2d Ah Kh Qh Jh Th"))); Assert.IsTrue(HeHelper.CanLose(d.GetIndexes("7c 2d Kh Qh Jh Th 9h"))); Assert.IsTrue(HeHelper.CanLose(d.GetIndexes("7c 2d Th 9h 8h 7h 6h"))); Assert.IsFalse(HeHelper.CanLose(d.GetIndexes("Jh Qh Th 9h 8h 7h 6h"))); Assert.IsFalse(HeHelper.CanLose(d.GetIndexes("7h 3s Ac Ks Qd Js Tc"))); Assert.IsTrue(HeHelper.CanLose(d.GetIndexes("7h 3s Ks Qd Js Tc 9h"))); Assert.IsTrue(HeHelper.CanLose(d.GetIndexes("Ac Ad Ah Kc Kd 7c 3h 2s"))); }
public void Test_GetBucket() { string bucketCounts = "8 7 6 5"; HsRangeCa b = CalculateHsRangeCa(bucketCounts, new int[] { 0, 1000, 1000, 1000 }, false); DeckDescriptor dd = StdDeck.Descriptor; int [] hand; // Preflop hand = dd.GetIndexes("Ac Ah"); Assert.AreEqual(7, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("7c 2d"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("3d 2c"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // Flop hand = dd.GetIndexes("Ac Ah As Ad 2h"); Assert.AreEqual(6, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("2c 3d As Ks Qh"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // Turn hand = dd.GetIndexes("Ac Ah As Ad 2h 2d"); Assert.AreEqual(5, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("6c 7c 3c 4c 5c As"); Assert.AreEqual(5, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("2c 3d As Ks Qh 9d"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // River hand = dd.GetIndexes("Ac Ah As Ad 2h 2d Qh"); Assert.AreEqual(4, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("6c 7c 8d 4c 5c As 8c"); Assert.AreEqual(4, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("2c 3d As Ks Qh 9d 6h"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); // Runner - runner hand = dd.GetIndexes("8c 7c"); Assert.AreEqual(2, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("8c 7c Ad Qc Jd"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("8c 7c Ad Qc Jd 4c"); int abstrCard = b.GetAbstractCard(hand, hand.Length); Assert.IsTrue(0 < abstrCard && abstrCard < 5, "Not worst, not best"); hand = dd.GetIndexes("8c 7c Ad Qc Jd 4c 5c"); Assert.AreEqual(4, b.GetAbstractCard(hand, hand.Length)); }
/// <summary> /// Counts number of rank-equivalent hands that are comprised from the same cards /// ranks as the given hand, fully ignoring suits. /// For example, for AcKc or AsKh returns 16, for 2s2d returns 6. /// There must be no dead cards. /// </summary> /// <remarks>Works even if a deck contains different number of suits (<=4) for different ranks. /// </remarks> public static int CountEquiv(CardSet hand, DeckDescriptor deck) { int count = 1; for (int r = 0; r < 16; ++r) { UInt64 handRanks = hand.bits & _rankMasks[r]; UInt64 allRanks = deck.FullDeck.bits & _rankMasks[r]; int handRanksCount = CountBits.Count(handRanks); int allRanksCount = CountBits.Count(allRanks); int rankCount = (int)EnumAlgos.CountCombin(allRanksCount, handRanksCount); count *= rankCount; } return(count); }
/// <summary> /// A shortcut to convert to an XML file. /// </summary> public static void Convert(StrategyTree t, string fileName, DeckDescriptor deckDescr) { using (TextWriter w = new StreamWriter(File.Open(fileName, FileMode.Create))) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.ASCII; settings.Indent = true; using (XmlWriter xmlWriter = XmlWriter.Create(w, settings)) { StrategyTreeToXml xmlizer = new StrategyTreeToXml { Output = xmlWriter, DeckDescr = deckDescr }; xmlizer.Convert(t); } } }
/// <summary> /// Same as Combin, contains additional user-defined parameter that will be passed to the delegate. /// </summary> // Code is copied from non-generic Combin. Code reuse decreases performace by 10%. public static void Combin <ParamT>(DeckDescriptor deckDescr, int count, CardSet sharedCards, CardSet deadCards, EnumerateActionDelegate <ParamT> action, ParamT param) { UInt64 deadMask = deadCards.bits | sharedCards.bits; UInt64 *pLiveCardMasks = stackalloc UInt64[deckDescr.Size]; int liveCardsCount = 0; for (int c = 0; c < deckDescr.Size; ++c) { UInt64 bits = deckDescr.CardSets[c].bits; if ((bits & deadMask) == 0) { pLiveCardMasks[liveCardsCount++] = bits; } } CombinInternal(sharedCards.bits, pLiveCardMasks, liveCardsCount, count, action, param); }
public void Test_KindToCardset() { Assert.AreEqual(169, (int)HePocketKind.__Count); DeckDescriptor deck = StdDeck.Descriptor; Assert.AreEqual(deck.GetCardSet("Ac Ad"), HePocket.KindToCardSet(HePocketKind._AA)); Assert.AreEqual(deck.GetCardSet("Ac Kd"), HePocket.KindToCardSet(HePocketKind._AKo)); Assert.AreEqual(deck.GetCardSet("Ac Kc"), HePocket.KindToCardSet(HePocketKind._AKs)); Assert.AreEqual(deck.GetCardSet("7c 2d"), HePocket.KindToCardSet(HePocketKind._72o)); Assert.AreEqual(deck.GetCardSet("7c 5c"), HePocket.KindToCardSet(HePocketKind._75s)); //for (int i = 0; i < 169; ++i) //{ // HePocketKind pk = (HePocketKind)i; // Console.WriteLine("{0,-4}: {1}", pk, HePocket.KindToCardSet(pk)); //} }
public void Test_GetBucket_PreflopPocket() { string bucketCounts = "8 7 6 5"; HsRangeCa b = CalculateHsRangeCa(bucketCounts, new int[] { 0, 1000, 1000, 1000 }, false); DeckDescriptor dd = StdDeck.Descriptor; int[] hand; hand = dd.GetIndexes("7c 2d"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("6d 5d"); Assert.AreEqual(1, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Ac Ah"); Assert.AreEqual(7, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("3d 2c"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); }
public void Benchmark_GetCardSet() { DeckDescriptor dd = StdDeck.Descriptor; int repetitions = 10000000; DateTime start = DateTime.Now; UInt64 sum = 0; for (int r = 0; r < repetitions; ++r) { sum += dd.GetCardSet(dd.CardNames[r % dd.Size]).bits; } double time = (DateTime.Now - start).TotalSeconds; Console.WriteLine("Repetitions: {0:#,#}, time: {1:0.00} s, rep/s: {2:#,#}", repetitions, time, repetitions / time); }
public void Test_GetBucket_PreflopPocket() { string minBucketsCounts = "8 1 1 1"; string maxBucketsCounts = "8 7 6 5"; HsKMeansAdaptiveCa b = CalculateCa(minBucketsCounts, maxBucketsCounts, "0.1 0.1 0.1 0.1", new int[] { 0, 1000, 1000, 1000 }, false); DeckDescriptor dd = StdDeck.Descriptor; int[] hand; hand = dd.GetIndexes("7c 2d"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("6d 5d"); Assert.AreEqual(1, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("Ac Ah"); Assert.AreEqual(7, b.GetAbstractCard(hand, hand.Length)); hand = dd.GetIndexes("3d 2c"); Assert.AreEqual(0, b.GetAbstractCard(hand, hand.Length)); }
/// <summary> /// Combin all possible combinations of cards and calls an action for each combination. /// </summary> /// <param name="cards">Array to put the cards to.</param> /// <param name="startPos">Starting position in the cards array.</param> /// <param name="deadCards">Dead cards. If some shared cards are necessary, put it manually to both cards and deadCards.</param> public static void Combin <ParamT>(DeckDescriptor deckDescr, int count, int[] cards, int startPos, int[] deadCards, int deadCardsCount, EnumerateActionIdxDelegate <ParamT> action, ParamT param) { int[] deckCopy = deckDescr.FullDeckIndexes.ShallowCopy(); for (int i = 0; i < deadCardsCount; ++i) { deckCopy[deadCards[i]] = -1; } int liveCardsLength = deckCopy.Length - deadCardsCount; int *liveCards = stackalloc int[liveCardsLength]; int cnt = 0; for (int i1 = 0; i1 < deckCopy.Length; ++i1) { if (deckCopy[i1] >= 0) { liveCards[cnt++] = deckCopy[i1]; } } Debug.Assert(cnt == liveCardsLength); CombinInternal(liveCards, liveCardsLength, count, cards, startPos, action, param); }