Пример #1
0
        private int FormCostToComplete(ref board tb, int suit)
        {
            List <series> SortedSEQ = tb.BuildSortedSEQ(1 << suit, GlobalClass.eSortedSEQtype.SortByRank);

            SortedSEQ.Sort(delegate(series s1, series s2)
            {
                return(Comparer <int> .Default.Compare(s2.topCard.rank, s1.topCard.rank));
            });
            tb.SuitedSEQ.Clear();
            if (SortedSEQ == null || SortedSEQ.Count < 2)
            {
                return(0);
            }
            int    cost = 0, rank;
            series ThisSEQ, PrevSEQ;

            ThisSEQ = sGetKing(ref SortedSEQ, ref cost);
            tb.SuitedSEQ.Add(ThisSEQ);
            rank = ThisSEQ.bottomCard.rank - 1;
            while (rank > 0)
            {
                PrevSEQ = ThisSEQ;
                if (SortedSEQ == null || SortedSEQ.Count < 2)
                {
                    return(1);
                }
                ThisSEQ = sGetNext(ref tb, ref SortedSEQ, rank, ref cost);
                PrevSEQ.AssemblyLink = ThisSEQ.AssemblyLink;
                tb.SuitedSEQ.Add(ThisSEQ);
                rank = ThisSEQ.bottomCard.rank - 1;
            }
            ThisSEQ.AssemblyLink = null;
            return(cost);
        }
Пример #2
0
        // suits must be completable and some empties available BEFORE calling
        // call CombineLikeSuits before calling this.
        public bool SpinSuitedJoinables(ref List <board> WorkingSeries)
        {
            bool  bAny          = false;
            int   Total         = 0;
            int   OriginalCount = WorkingSeries.Count;
            int   BoardBeingWorked;
            board tb;

            if (cSC.bTrigger)
            {
                Console.WriteLine(MethodBase.GetCurrentMethod().Name);
            }
            for (BoardBeingWorked = 0; BoardBeingWorked < WorkingSeries.Count; BoardBeingWorked++)
            {
                tb = WorkingSeries[BoardBeingWorked];
                if (tb.dead)
                {
                    continue;
                }
                if (tb.BuildingThisSuit == 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        // just want several empty columns right now
                        //if (tb.bSuitsCompletable[i])
                        {
                            do
                            {
                                board nb = new board(ref tb);
                                nb.SuitedSEQ.Clear();
                                // sorting by rank puts the biggest first and no need to swap order to get
                                // find a card that fits under the first card
                                nb.SuitedSEQ        = nb.BuildSortedSEQ(1 << i, GlobalClass.eSortedSEQtype.SortByRank);
                                nb.BuildingThisSuit = i + 1;
                                bAny = JoinAnyLikeSuits(ref nb);
                                if (bAny)
                                {
                                    Total++;
                                    WorkingSeries.Add(nb);
                                }
                            } while (bAny);
                        }
                    }
                }
            }
            return(Total > 0);
        }
Пример #3
0
        // this joins suited sequences that can be swapped (ie: reversible moves)
        public bool JoinAllSuitedWhenRankable(ref board tb)
        {
            if (cSC.bTrigger)
            {
                Console.WriteLine(MethodBase.GetCurrentMethod().Name);
            }
            if (tb.NumEmptyColumns < 1)
            {
                return(false);
            }
            bool bAny = false, bResults = false;

            do
            {
                tb.BuildSortedSEQ(0xf, GlobalClass.eSortedSEQtype.SortByRank);
                bResults = cSC.JoinSuited.JoinSuitedWhenRankable(ref tb);
                bAny    |= bResults;
                tb.ReScoreBoard();
            } while (bResults);
            return(bAny);
        }