示例#1
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);
        }
示例#2
0
        public int SOSExposeTop(ref board tb)
        {
            bool                  bAnySameSuit = false;
            List <series>         TopSeries    = new List <series>();
            List <cPossibleMoves> ActualMoves  = new List <cPossibleMoves>();

            NewBoards.Clear();
            TryUnstackAll(ref tb);

            tb.CopyWorkingCards(ref xBottomMost, GlobalClass.WorkingType.tBottomMost);
            foreach (column cCol in tb.ThisColumn)
            {
                if (cCol.iStack > 9)
                {
                    break;
                }
                if (cCol.ThisSOS.Count == 1)
                {
                    TopSeries.Add(cCol.ThisSOS[0]);
                }
            }
            foreach (card bm in xBottomMost)
            {
                foreach (series s in TopSeries)
                {
                    card tm = s.topCard;
                    if ((tm.rank + 1) == bm.rank)
                    {
                        card           bbm = bm;
                        cPossibleMoves cpm = new cPossibleMoves(ref tm, ref bbm);
                        ActualMoves.Add(cpm);
                    }
                }
            }

            foreach (cPossibleMoves cpm in ActualMoves)
            {
                if (cpm.bSameSuit)
                {
                    bAnySameSuit = true;
                    break;
                }
            }

            foreach (cPossibleMoves cpm in ActualMoves)
            {
                column        cCol;
                card          cCrd;
                board         nb;
                series        SOS;
                bool          bCan;
                List <series> ListSEQ;
                List <int>    yEmpties    = new List <int>();
                List <card>   yBottomMost = new List <card>();
                if (bAnySameSuit && !cpm.bSameSuit)
                {
                    continue;
                }
                nb = new board(ref tb);
                nb.AssignCompletedID(GlobalClass.TypeCompletedBy.ID_SOSET);
                CardsToMove.Clear();
                cCol    = nb.ThisColumn[cpm.From.iStack];
                SOS     = cCol.ThisSOS[0];
                ListSEQ = cCol.ThisSeries;    // the top cards in the SEQ are the ones to move in the SOS
                for (int i = 0; i < SOS.NumSubSeries; i++)
                {
                    cCrd = ListSEQ[i].topCard;
                    CardsToMove.Add(cCrd);
                }
                nb.tag = cpm.To.iStack;
                nb.CopyWorkingInts(ref yEmpties, GlobalClass.WorkingType.tEmpties);
                nb.CopyWorkingCards(ref yBottomMost, GlobalClass.WorkingType.tBottomMost);
                bCan = DisAssemble.bCanDisassembleSOS(SOS.NumSubSeries, ref nb, ref yEmpties, ref yBottomMost, ref CardsToMove);
                if (bCan)
                {
                    NewBoards.Add(nb);
                    nb.AssignCompletedID();
                }
            }
            return(NewBoards.Count);
        }