private void MakeCompositeSinglePileMove(int first) { if (Diagnostics) { Utils.WriteLine("MCSPM"); } bool aborted = false; int offloadPile = -1; MoveStack.Clear(); for (int next = first; next != -1; next = SupplementaryList[next].Next) { int numberOfSpaces = Tableau.NumberOfSpaces; Move move = Tableau.Normalize(SupplementaryList[next]); if (move.Type == MoveType.Unload) { offloadPile = move.To; UnloadToSpaces(move.From, move.FromRow, -1); } else if (move.Type == MoveType.Reload) { if (Diagnostics) { Utils.WriteLine("RL:"); } while (MoveStack.Count != 0) { Move subMove = MoveStack.Pop(); int to = subMove.To != -1 ? subMove.To : move.To; MakeSimpleMove(subMove.From, subMove.FromRow, to); } offloadPile = -1; } else if (move.Flags.UndoHolding()) { TryMakeMoveUsingSpaces(move); } else { if (!TryMakeMoveUsingSpaces(move)) { // Things got messed up due to a discard. There might // be another pile with the same target. bool foundAlternative = false; Pile fromPile = Tableau[move.From]; if (move.From >= 0 && move.From < fromPile.Count) { Card fromCard = fromPile[move.FromRow]; for (int to = 0; to < NumberOfPiles; to++) { if (to == move.From) { continue; } Pile toPile = Tableau[to]; if (toPile.Count == 0) { continue; } if (!fromCard.IsSourceFor(toPile[toPile.Count - 1])) { continue; } if (TryMakeMoveUsingSpaces(new Move(move.From, move.FromRow, to))) { foundAlternative = true; } break; } } if (!foundAlternative) { // This move is hopelessly messed up. aborted = true; break; } } } } if (!aborted && MoveStack.Count != 0) { throw new Exception("missing reload move"); } }