Esempio n. 1
0
        public static float[] CalculateFast(int[] hand, int handLength, SdKind sdKind)
        {
            Debug.Assert(handLength >= 0 && handLength <= 7);
            if (handLength == 7)
            {
                // SdKind.SdPlus1 will throw an exception, this is exactly what we want.
                return(Calculate(hand, handLength, sdKind == SdKind.SdPlus1 ? 4 : 3));
            }

            if (_lut2 == null)
            {
                LoadLuts();
            }

            float[] hssd = new float[2];

            int      round    = HeHelper.HandSizeToRound[handLength];
            CardSet  pocket   = StdDeck.Descriptor.GetCardSet(hand, 0, 2);
            CardSet  board    = StdDeck.Descriptor.GetCardSet(hand, 2, handLength - 2);
            NormSuit se       = new NormSuit();
            CardSet  sePocket = se.Convert(pocket);
            CardSet  seBoard  = se.Convert(board);

            if (round == 2)
            {
                Entry2 keyEntry = new Entry2(HePocket.CardSetToKind(sePocket), seBoard);
                int    idx      = Array.BinarySearch(_lut2, keyEntry);
                if (idx < 0)
                {
                    ThrowNoEntryException(sePocket, seBoard);
                }
                hssd[0] = _lut2[idx].Hs;
                // For turn, there is no difference between SD kinds.
                hssd[1] = _lut2[idx].SdPlus1;
            }
            else
            {
                Entry01 keyEntry = new Entry01(HePocket.CardSetToKind(sePocket), seBoard);
                int     idx      = Array.BinarySearch(_lut01[round], keyEntry);
                if (idx < 0)
                {
                    ThrowNoEntryException(sePocket, seBoard);
                }
                // For turn, there is no difference between SD kinds.
                hssd[0] = _lut01[round][idx].Hs;
                hssd[1] = sdKind == SdKind.SdPlus1 ? _lut01[round][idx].SdPlus1 : _lut01[round][idx].Sd3;
            }
            return(hssd);
        }
Esempio n. 2
0
 public Entry01(int APIversion, EventHandler handler, Entry01 basis, DependentList <TGIBlock> ParentTGIBlocks = null)
     : this(APIversion, handler, 1, basis.tgiIndex, ParentTGIBlocks ?? basis.ParentTGIBlocks)
 {
 }
Esempio n. 3
0
        static void OnPrecalculateBoard(ref CardSet board, PrecalculationContext d)
        {
            NormSuit       sei     = new NormSuit(d.pocketSei);
            CardSet        seBoard = sei.Convert(board);
            List <Entry01> list01  = null;
            List <Entry2>  list2   = null;
            UInt32         key     = GetKey((int)d.pocketKind, seBoard);
            bool           addNew  = false;

            // A key will be either present in the table or go to the end (greater than the rest).
            // This is due to the order of dealt boards in CardEnum
            if (d.Round < 2)
            {
                list01 = (List <Entry01>)d.list;
                addNew = list01.Count == 0 || list01[list01.Count - 1].Key < key;
            }
            else
            {
                list2  = (List <Entry2>)d.list;
                addNew = list2.Count == 0 || list2[list2.Count - 1].Key < key;
            }

            if (addNew)
            {
                List <int> pocketIdxs = StdDeck.Descriptor.GetIndexesAscending(d.pocket);
                List <int> boardIdxs  = StdDeck.Descriptor.GetIndexesAscending(seBoard);
                int[]      hand       = new int[pocketIdxs.Count + boardIdxs.Count];
                int        h          = 0;
                for (int i = 0; i < pocketIdxs.Count; ++i)
                {
                    hand[h++] = pocketIdxs[i];
                }
                for (int i = 0; i < boardIdxs.Count; ++i)
                {
                    hand[h++] = boardIdxs[i];
                }
                float[] sdhs;
                if (d.Round < 2)
                {
                    Entry01 newEntry = new Entry01 {
                        Key = key
                    };
                    sdhs             = Calculate(hand, d.Round + 1);
                    newEntry.Hs      = sdhs[0];
                    newEntry.SdPlus1 = sdhs[1];
                    sdhs             = Calculate(hand, 3);
                    newEntry.Sd3     = sdhs[1];
                    list01.Add(newEntry);
                }
                else
                {
                    Entry2 newEntry = new Entry2 {
                        Key = key
                    };
                    sdhs             = Calculate(hand, d.Round + 1);
                    newEntry.Hs      = sdhs[0];
                    newEntry.SdPlus1 = sdhs[1];
                    list2.Add(newEntry);
                }
            }
            d.count++;
        }