Пример #1
0
 private static void tryPopDeck(SolitaireState SolitaireState, List <SolitaireState> cache)
 {
     if (SolitaireState.Deck.Length > 0)
     {
         var s = new SolitaireState(SolitaireState);
         s.CopyDiscard();
         s.CopyDeck();
         var l = Utilities.RemoveLast(ref s.Deck);
         if (s.Deck.Length == 0)
         {
             s.DeckLast = Utilities.CardDefault;
         }
         else
         {
             s.DeckLast = s.Deck[s.Deck.Length - 1];
         }
         Utilities.Add(ref s.DeckDiscard, l);
         s.DeckDiscardLast = l;
         cache.Add(s);
     }
     else
     {
         var s = new SolitaireState(SolitaireState);
         s.CopyDiscard();
         s.CopyDeck();
         s.ResetCount++;
         s.Deck = s.DeckDiscard;
         Array.Resize(ref s.DeckDiscard, 0);
         s.DeckLast        = s.Deck[s.Deck.Length - 1];
         s.DeckDiscardLast = Utilities.CardDefault;
         cache.Add(s);
     }
 }
Пример #2
0
        private static void tryMoveFromDiscard(SolitaireState SolitaireState, List <SolitaireState> cache)
        {
            if (SolitaireState.DeckDiscard.Length == 0)
            {
                return;
            }
            var topCard = SolitaireState.DeckDiscardLast;

            for (int index = 0; index < 7; index++)
            {
                if (cardFits(SolitaireState.PilesLast[index], topCard))
                {
                    var s = new SolitaireState(SolitaireState);

                    s.CopyDiscard();
                    s.CopyPile(index);

                    var top = Utilities.RemoveLast(ref s.DeckDiscard);

                    if (s.DeckDiscard.Length == 0)
                    {
                        s.DeckDiscardLast = Utilities.CardDefault;
                    }
                    else
                    {
                        s.DeckDiscardLast = s.DeckDiscard[s.DeckDiscard.Length - 1];
                    }

                    Utilities.Add(ref s.Piles[index], top);
                    s.PilesLast[index] = top;
                    cache.Add(s);
                }
            }
        }
Пример #3
0
        private static void tryMoveToTop(SolitaireState SolitaireState, List <SolitaireState> cache)
        {
            byte l;

            for (int index = 0; index < 7; index++)
            {
                var pile = SolitaireState.Piles[index];
                if (pile.Length == 0)
                {
                    continue;
                }
                l = SolitaireState.PilesLast[index];

                var type = l / 13;
                if (cardFitsTop(SolitaireState.TopLast[type], type, l))
                {
                    var s = new SolitaireState(SolitaireState);
                    s.CopyPile(index);
                    s.CopyTop(type);

                    var p     = Utilities.RemoveLast(ref s.Piles[index]);
                    var items = s.Piles[index];
                    if (items.Length == 0)
                    {
                        s.PilesLast[index] = Utilities.CardDefault;
                    }
                    else
                    {
                        s.PilesLast[index] = items[items.Length - 1];
                    }

                    if (items.Length > 0)
                    {
                        s.PileFaceDown[index] = (byte)(items.Length - 1);
                    }

                    Utilities.Add(ref s.Top[type], p);
                    s.TopLast[type] = p;

                    cache.Add(s);
                }
            }
            if (SolitaireState.DeckDiscard.Length > 0)
            {
                l = SolitaireState.DeckDiscardLast;
                var type = l / 13;
                if (cardFitsTop(SolitaireState.TopLast[type], type, l))
                {
                    var s = new SolitaireState(SolitaireState);
                    s.CopyDiscard();
                    s.CopyTop(type);

                    var p = Utilities.RemoveLast(ref s.DeckDiscard);
                    if (s.DeckDiscard.Length == 0)
                    {
                        s.DeckDiscardLast = Utilities.CardDefault;
                    }
                    else
                    {
                        s.DeckDiscardLast = s.DeckDiscard[s.DeckDiscard.Length - 1];
                    }
                    Utilities.Add(ref s.Top[type], p);
                    s.TopLast[type] = p;

                    cache.Add(s);
                }
            }
        }