From 0eb8c7dcf744f9d4b711dcb7319d01efab1249d4 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 4 Apr 2019 01:26:45 -0400 Subject: Add listClear --- freecell.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'freecell.c') 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; } -- cgit 1.4.1 h=1.2&id=82acea5dfa260fa7b4f6257f4502b9a9a2eeabaa&ofs=150&showmsg=1&follow=1'>Expand)Author 2020-02-12Simplify transpose swapJune McEnroe 2020-02-12Add C-t transposeJune McEnroe 2020-02-12Add C-v and M-vJune McEnroe 2020-02-12Allow for arguments to open/copy utilitiesJune McEnroe 2020-02-12Handle RPL_AWAYJune McEnroe 2020-02-11Support monochromatic terminalsJune McEnroe 2020-02-11Add .gz to chroot-man scriptJune McEnroe 2020-02-11Add -R restricted flagJune McEnroe 2020-02-11Add chroot targetJune McEnroe 2020-02-11Exit focus and paste modes on err exitJune McEnroe 2020-02-11Add startup GPLv3 note and URLJune McEnroe 2020-02-11Make sure -D_GNU_SOURCE ends up in CFLAGS on LinuxJune McEnroe 2020-02-11Add note about setting PKG_CONFIG_PATHJune McEnroe 2020-02-11Rename query ID on nick changeJune McEnroe 2020-02-11Call completeClear when closing a windowJune McEnroe 2020-02-11Don't insert color codes for non-mentionsJune McEnroe 2020-02-11Take first two words in colorMentionsJune McEnroe 2020-02-11Use time_t for save signatureJune McEnroe 2020-02-11Set self.nick to * initiallyJune McEnroe 2020-02-11Define ColorCap instead of hardcoding 100June McEnroe 2020-02-11Move hash to top of chat.hJune McEnroe 2020-02-11Move base64 out of chat.hJune McEnroe 2020-02-11Move XDG_SUBDIR out of chat.hJune McEnroe 2020-02-11Fix whois idle unit calculationJune McEnroe 2020-02-11Cast towupper to wchar_tJune McEnroe 2020-02-11Cast set but unused variables to voidJune McEnroe 2020-02-11Declare strlcatJune McEnroe 2020-02-11Check if VDSUSP existsJune McEnroe 2020-02-11Fix completeReplace iterationJune McEnroe 2020-02-11Use pkg(8) to configure on FreeBSDJune McEnroe 2020-02-11Remove legacy codeJune McEnroe 2020-02-11Add INSTALLING section to READMEJune McEnroe