Пример #1
0
 static void Main(string[] args)
 {
     for (int r = 0; r < 3; ++r)
     {
         HsSd.Precalculate(0);
     }
 }
 protected override void CalculateValue(int[] hand, int handLength, double[] value)
 {
     float[] hssd = HsSd.CalculateFast(hand, handLength, HsSd.SdKind.Sd3);
     value[0] = hssd[0];
     value[1] = hssd[1];
     value[2] = AHVO.CalculateFast(hand, 2, handLength - 2);
 }
Пример #3
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }
            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }
            foreach (string handS in _cmdLine.Hands)
            {
                handS.Trim();
                if (handS.Length % 2 != 0)
                {
                    Console.WriteLine("Wrong HE hand: {0}", handS);
                    continue;
                }
                string cards = "";
                for (int i = 0; i < handS.Length; i += 2)
                {
                    cards += handS.Substring(i, 2) + " ";
                }
                int[] hand = null;
                try
                {
                    hand = StdDeck.Descriptor.GetIndexes(cards);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Wrong HE hand: {0}, {1}", cards, e.ToString());
                    continue;
                }
                int round = HeHelper.HandSizeToRound[hand.Length];
                if (round == -1)
                {
                    Console.WriteLine("Wrong HE hand size: {0}", handS);
                    continue;
                }
                Console.Write("HS/SD3/SD+1 of {0}:", StdDeck.Descriptor.GetCardNames(hand));
                for (int r = 0; r <= round; ++r)
                {
                    float [] result;
                    Console.Write(" round {0}: ", r);
                    result = HsSd.CalculateFast(hand, HeHelper.RoundToHandSize[r], HsSd.SdKind.Sd3);
                    Console.Write(" {0:0.000000}", result[0]);
                    Console.Write(" {0:0.000000}", result[1]);
                    if (r < 3)
                    {
                        result = HsSd.CalculateFast(hand, HeHelper.RoundToHandSize[r], HsSd.SdKind.SdPlus1);
                        Console.Write(" {0:0.000000}", result[1]);
                    }
                }
                Console.WriteLine();
            }

            return(0);
        }
Пример #4
0
        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);
        }
Пример #5
0
 public void Test_HsSd_Pockets()
 {
     for (int p = 0; p < HePocket.Count; ++p)
     {
         HePocketKind pk   = (HePocketKind)p;
         int[]        hand = HePocket.KindToHand(pk);
         float[]      hssd = HsSd.Calculate(hand, 1);
         Console.WriteLine("{0} {1:0.0000} {2:0.0000}", HePocket.KindToString(pk),
                           hssd[0], hssd[1]);
     }
 }
Пример #6
0
 public void Test_Preview()
 {
     string[] hands = new string[]
     {
         "7c 6c 8c 5c Ad",
         "7c 6c 8c 5c Ad Qs",
         "9d 9h 2c Qs Ah",
         "9d 9h 2c Qs Ah Ks",
     };
     foreach (string handS in hands)
     {
         int[] hand = StdDeck.Descriptor.GetIndexes(handS);
         for (int r = HeHelper.HandSizeToRound[hand.Length] + 1; r <= 3; ++r)
         {
             float[] hssd = HsSd.Calculate(hand, r);
             Console.WriteLine("Hand: {0} round: {1} hs: {2:0.0000} sd: {3:0.0000}", handS, r, hssd[0], hssd[1]);
         }
     }
 }
Пример #7
0
        void CalculateFastRandomTest(int round, int repCount)
        {
            int rngSeed = (int)DateTime.Now.Ticks;

            Console.WriteLine("CalculateFast random test round {0}, rep count {1}, RNG seed {2}", round, repCount, rngSeed);

            Random      rng        = new Random(rngSeed);
            SequenceRng dealer     = new SequenceRng(rngSeed, StdDeck.Descriptor.FullDeckIndexes);
            int         handLength = HeHelper.RoundToHandSize[round];

            for (int r = 0; r < repCount; ++r)
            {
                dealer.Shuffle(handLength);
                HsSd.SdKind sdKind   = round == 3 ? HsSd.SdKind.Sd3 : (HsSd.SdKind)rng.Next(0, 2);
                int         sdRound  = sdKind == HsSd.SdKind.SdPlus1 ? round + 1 : 3;
                float[]     hssdFast = HsSd.CalculateFast(dealer.Sequence, handLength, sdKind);
                float[]     hssd     = HsSd.Calculate(dealer.Sequence, handLength, sdRound);
                Assert.AreEqual(hssd[0], hssdFast[0], 1e-6);
                Assert.AreEqual(hssd[1], hssdFast[1], 1e-6);
            }
        }
Пример #8
0
 public void Test_Precalculate()
 {
     HsSd.Precalculate(0);
     HsSd.Precalculate(1);
     HsSd.Precalculate(2);
 }