diff options
Diffstat (limited to '')
-rw-r--r-- | freecell.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/freecell.c b/freecell.c index da8729d..b7f6378 100644 --- a/freecell.c +++ b/freecell.c @@ -47,14 +47,14 @@ enum { static struct Stack stacks[StacksLen]; -static uint kingFace = Cards_KingRight; - static struct { bool avail; uint dst; uint src; } undo; +static uint kingFace = Cards_KingRight; + static void gameDeal(void) { for (uint i = 0; i < StacksLen; ++i) { stackClear(&stacks[i]); @@ -64,14 +64,11 @@ static void gameDeal(void) { stackPush(&deck, i); } stackShuffle(&deck); - for (uint i = Tableau1; i <= Tableau4; ++i) { - stackMoveTo(&stacks[i], &deck, 7); - } - for (uint i = Tableau5; i <= Tableau8; ++i) { - stackMoveTo(&stacks[i], &deck, 6); + for (uint i = Tableau1; i <= Tableau8; ++i) { + stackMoveTo(&stacks[i], &deck, (i < Tableau5 ? 7 : 6)); } - kingFace = Cards_KingRight; undo.avail = false; + kingFace = Cards_KingRight; } static bool gameWin(void) { @@ -81,25 +78,25 @@ static bool gameWin(void) { return true; } -static bool gameFind(uint *stack, uint *index, Card card) { +static bool gameFind(uint *stack, Card card) { for (*stack = 0; *stack < StacksLen; ++*stack) { - for (*index = 0; *index < stacks[*stack].len; ++*index) { - if (stacks[*stack].cards[*index] == card) return true; + for (uint i = 0; i < stacks[*stack].len; ++i) { + if (stacks[*stack].cards[i] == card) return true; } } return false; } static bool gameAvail(Card card) { - uint stack, index; - if (!gameFind(&stack, &index, card)) return false; - if (stack >= Foundation1 && stack <= Foundation4) return false; + uint stack; + assert(gameFind(&stack, card)); + if (stack <= Foundation4) return false; return card == stackTop(&stacks[stack]); } static bool gameMove(uint dst, Card card) { - uint src, index; - if (!gameFind(&src, &index, card)) return false; + uint src; + assert(gameFind(&src, card)); Card top = stackTop(&stacks[dst]); if (src == dst) return false; @@ -261,7 +258,7 @@ static bool keyDown(SDL_KeyboardEvent key) { static bool keyUp(SDL_KeyboardEvent key) { (void)key; if (!reveal.len) return false; - reveal.len = 0; + listClear(&reveal); return true; } @@ -279,7 +276,7 @@ static bool mouseButtonUp(SDL_MouseButtonEvent button) { if (button.button == SDL_BUTTON_RIGHT) { if (!reveal.len) return false; - reveal.len = 0; + listClear(&reveal); return true; } |