예제 #1
0
 /// <summary>
 /// Prints the field to Console.Out
 /// </summary>
 public void DumpToConsole()
 {
     var toprow = FinishStacks.Cast<CardStack>()
         .Concat(new[] { Stock });
     DumpRows(toprow);
     DumpRows(PlayStacks.ToArray());
 }
예제 #2
0
 private bool IsSafeToPlay(Card card)
 {   // this move does never block a solution since it 
     // cannot block another card: 
     // all cards that can go on top of this card, 
     // can also enter their finish stack.
     if (card.Value == Value.Ace) return true;
     return FinishStacks.Select(f => GetValue(f.Top)).All(
                             value => value >= GetValue(card) - 2);
 }
예제 #3
0
 public PatienceField DoTrivialMoves()
 {
     // Try the tops of the playstacks
     foreach (var stack in PlayStacks)
     {
         if (stack.Count == 0) continue;
         var card = stack.Top;
         if (IsSafeToPlay(card))
         {
             foreach (var dest in FinishStacks.Where(s => s.CanAccept(card, stack)))
             {
                 return Move(card, stack, dest).DoTrivialMoves();
             }
         }
     }
     // Try all stock cards
     foreach (var stockcard in Stock.Where(IsSafeToPlay))
         foreach (var dest in FinishStacks.Where(s => s.CanAccept(stockcard, Stock)))
         {
             return Move(stockcard, Stock, dest).DoTrivialMoves();
         }
     return this;
 }
예제 #4
0
 /// <summary>
 /// Gets valid destination stacks, from least to most likely to lead to a solution
 /// </summary>
 /// <returns></returns>
 public IEnumerable<CardStack> GetDestinationStacks()
 {
     return PlayStacks.Cast<CardStack>()
         .Concat(FinishStacks.Cast<CardStack>());
 }