diff options
Diffstat (limited to '')
-rw-r--r-- | sol.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/sol.c b/sol.c index f16c7b6..5622395 100644 --- a/sol.c +++ b/sol.c @@ -82,28 +82,26 @@ static bool gameUndo(void) { static void gameDeal(void) { undo.fn = NULL; for (uint i = 0; i < StacksLen; ++i) { - stackClear(&stacks[i]); + clear(&stacks[i]); } - for (Card i = 1; i <= 52; ++i) { - stackPush(&stacks[Stock], -i); - } - stackShuffle(&stacks[Stock]); + stacks[Stock] = Deck; + shuffle(&stacks[Stock]); for (uint i = Tableau1; i <= Tableau7; ++i) { - stackMoveTo(&stacks[i], &stacks[Stock], i - Tableau1); - stackFlipTo(&stacks[i], &stacks[Stock], 1); + moveTo(&stacks[i], &stacks[Stock], i - Tableau1); + flipTo(&stacks[i], &stacks[Stock], 1); } } static void gameDraw(void) { - stackMoveTo(&stacks[Waste1], &stacks[Waste3], stacks[Waste3].len); + moveTo(&stacks[Waste1], &stacks[Waste3], stacks[Waste3].len); if (stacks[Stock].len) { if (game.draw > 1) { - gameDo(stackFlipTo, Waste3, Stock, game.draw); + gameDo(flipTo, Waste3, Stock, game.draw); } else { - gameDo(stackFlipTo, Waste1, Stock, 1); + gameDo(flipTo, Waste1, Stock, 1); } } else { - gameDo(stackFlipTo, Stock, Waste1, stacks[Waste1].len); + gameDo(flipTo, Stock, Waste1, stacks[Waste1].len); } } @@ -121,7 +119,7 @@ static bool gameAvail(Card card) { if (card < 0) return false; if (!gameFind(&stack, &index, card)) return false; - bool top = (card == stackTop(&stacks[stack])); + bool top = (card == peek(&stacks[stack])); if (stack == Waste1) { return top && !stacks[Waste3].len; } else if (stack == Waste3) { @@ -139,9 +137,9 @@ static bool gameReveal(Card card) { uint stack, index; if (!gameFind(&stack, &index, card)) return false; if (stack < Tableau1 || stack > Tableau7) return false; - if (card != stackTop(&stacks[stack])) return false; + if (card != peek(&stacks[stack])) return false; if (card > 0) return false; - gameDo(stackFlipTo, stack, stack, 1); + gameDo(flipTo, stack, stack, 1); return true; } @@ -151,22 +149,22 @@ static bool gameMove(uint dest, Card card) { if (source == dest) return false; uint count = stacks[source].len - index; - Card destTop = stackTop(&stacks[dest]); + Card destTop = peek(&stacks[dest]); if (dest >= Foundation1 && dest <= Foundation4) { if (count > 1) return false; - if (!destTop && cardRank(card) != Cards_A) return false; - if (destTop && cardSuit(card) != cardSuit(destTop)) return false; - if (destTop && cardRank(card) != cardRank(destTop) + 1) return false; - gameDo(stackMoveTo, dest, source, 1); + if (!destTop && rank(card) != Cards_A) return false; + if (destTop && suit(card) != suit(destTop)) return false; + if (destTop && rank(card) != rank(destTop) + 1) return false; + gameDo(moveTo, dest, source, 1); return true; } if (dest >= Tableau1 && dest <= Tableau7) { - if (!destTop && cardRank(card) != Cards_K) return false; - if (destTop && cardColor(card) == cardColor(destTop)) return false; - if (destTop && cardRank(card) != cardRank(destTop) - 1) return false; - gameDo(stackMoveTo, dest, source, count); + if (!destTop && rank(card) != Cards_K) return false; + if (destTop && color(card) == color(destTop)) return false; + if (destTop && rank(card) != rank(destTop) - 1) return false; + gameDo(moveTo, dest, source, count); return true; } |