Пример #1
0
        private bool UnstackOne(ref board tb, ref series ts)
        {
            int iStack = GetBestMove(ref ts.topCard, ref tb);

            if (iStack < 0)
            {
                if (tb.Empties.Count == 0)
                {
                    return(false);
                }
                iStack = tb.Empties[0];
                tb.Empties.RemoveAt(0);
            }
            tb.PerformMove(ts.iStack, ts.top, iStack, ts.size);
            return(true);
        }
Пример #2
0
        /*
         * THIS DOES NOT WORK EXCEPT FOR VERY SIMPLE SEQ SERIES JYS !!!! need UnStack and to use patterns
         * This joins one SEQ series under another so as to concatanate the two series
         * */



        /*
         * this just exposes the top card and check to see if it can be recovered
         * jys this needs to be able to expose all cards that are exposable
         * (8s,6h,7D) expose to 8S,7D,6H
         *
         * right now, the series underneath must be SEQ, use the SOS one for that, but it does not use placeholders
         *
         * */
        public int ExposeOneTop(ref board tb)
        {
            int  e, n;
            int  LocAbove;  // location of card just above the top card
            card CardAbove;
            int  Any = 0;
            int  OriginalSource;

            foreach (card cT in tb.TopMost)
            {
                LocAbove = cT.iCard - 1;
                if (LocAbove <= 0)
                {
                    continue;                   // nothing to expose
                }
                CardAbove = tb.ThisColumn[cT.iStack].Cards[LocAbove];
                if (CardAbove.bFaceUp)
                {
                    continue;                       // already exposed
                }
                // we want only unexposed cards and the series underneath must be SEQ

                // we can expose this card by moving the one below it (our card cT)
                if (CardAbove.rank - 1 != cT.rank)
                {
                    continue;                                        // nope, wrong rank, we want to move it back
                }
                n = tb.ThisColumn[cT.iStack].Cards.Count - cT.iCard; // number of cards to move
                // the below does no error checking nor any statistics computation


                if (tb.NumEmptyColumns > 0)
                {
                    e = tb.Empties[0];
                    OriginalSource = cT.iStack;
                    tb.PerformMove(cT.iStack, cT.iCard, e, n);
                    tb.PerformMove(e, 0, OriginalSource, n);
                    Any++;
                }
                else
                {
                    // we will have to find a card that can hold it temporarily
                    foreach (card bC in tb.BottomMost)
                    {
                        if (bC.iStack == cT.iStack)
                        {
                            continue;
                        }
                        if (bC.rank - 1 == cT.rank)
                        {
                            OriginalSource = cT.iStack;
                            n = tb.ThisColumn[cT.iStack].Cards.Count - cT.iCard;
                            tb.PerformMove(cT.iStack, cT.iCard, bC.iStack, n);
                            tb.PerformMove(bC.iStack, bC.iCard + 1, OriginalSource, n);
                            Any++;
                        }
                    }
                }
                if (Any > 0)
                {
                    tb.ThisColumn[cT.iStack].CalculateColumnValue(cT.iStack, tb.NumEmptyColumns, tb.BoardState());
                }
            }

            if (Any > 0)
            {
                tb.ReScoreBoard(); // alternately CalcBoardScore and then GetSortedTops
                return(ExposeOneTop(ref tb));
            }
            return(Any);
        }
Пример #3
0
        private int UnstackOneSeries(ref board tb)
        {
            int Any = 0;

            cUnstackOrder[] cUO;
            column          cCol;
            card            CardExposed;

            PlaceHolder.Clear();
            cUO = new cUnstackOrder[tb.NumFacedownColumns()];
            int i = 0;

            tb.CopyWorkingCards(ref xBottomMost, GlobalClass.WorkingType.tBottomMost);
            tb.CopyWorkingInts(ref xEmpties, GlobalClass.WorkingType.tEmpties);
            tb.BuildPlaceholders(ref PlaceHolder);


            // get best unstack order in case we cannot unstack all of them
            i = 0;
            foreach (int e in tb.NonEmpties)
            {
                cCol = tb.ThisColumn[e];
                if (cCol.top == 0)
                {
                    continue;
                }
                int nSEQ = cCol.ThisSeries.Count;
                int nSOS = cCol.ThisSOS.Count;
                cUO[i++] = new cUnstackOrder(e, nSEQ);
            }
            Array.Sort(cUO, delegate(cUnstackOrder c1, cUnstackOrder c2)
            {
                return(c1.SizeSeries.CompareTo(c2.SizeSeries));
            });

            foreach (cUnstackOrder uo in cUO)
            {
                cCol = tb.ThisColumn[uo.e];
                for (i = uo.SizeSeries - 1; i >= 0; i--)
                {
                    series s      = cCol.ThisSeries[i];
                    int    iStack = utils.GetBestMove(s.topCard, ref tb, ref PlaceHolder);
                    if (iStack < 0)
                    {
                        if (xEmpties.Count == 0)
                        {
                            return(Any);
                        }
                        iStack = xEmpties[0];
                        xEmpties.RemoveAt(0);
                    }
                    CardExposed = tb.PerformMove(s.iStack, s.top, iStack, s.size);
                    RecoverPlaceholder(ref tb, ref CardExposed);
                    Any++;
                }
                if (Any > 0)
                {
                    return(Any);
                }
            }
            return(Any);
        }