/// <summary> /// Prints the field to Console.Out /// </summary> public void DumpToConsole() { var toprow = FinishStacks.Cast<CardStack>() .Concat(new[] { Stock }); DumpRows(toprow); DumpRows(PlayStacks.ToArray()); }
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); }
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; }
/// <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>()); }