From ae303c2aefa2585c86c223083ce406e1134ee118 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 19 Jan 2019 17:37:02 +0100 Subject: [PATCH] fix foundation rendering (SPIDER) by using a static int to store the foundation index, it couldn't be reset when a new game was started. this caused the first pile to be e.g. to end up on the second foundation if the game before had 1 completed. --- sol.c | 19 ++++++++++--------- sol.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/sol.c b/sol.c index 707bebc..c208271 100644 --- a/sol.c +++ b/sol.c @@ -309,9 +309,6 @@ int t2t(int from, int to, int opt) { /* tableu to tableu */ } #elif defined SPIDER int remove_if_complete (int pileno) { //cleanup! - static int foundation = 0; - if (pileno == -1) return foundation--; /* for undo_pop() */ - card_t* pile = f.t[pileno]; /* test if K...A complete; move to foundation if so */ int top_from = find_top(pile); @@ -321,12 +318,12 @@ int remove_if_complete (int pileno) { //cleanup! if (i+RANK_K == top_from /* if ace to king: remove it */ && get_rank(pile[top_from-RANK_K]) == RANK_K) { for(int i=top_from, j=0; i>top_from-NUM_RANKS; i--,j++){ - f.f[foundation][j] = pile[i]; + f.f[f.w][j] = pile[i]; pile[i] = NO_CARD; } - undo_push(pileno, FOUNDATION, foundation, + undo_push(pileno, FOUNDATION, f.w, turn_over(pile)); - foundation++; + f.w++; return 1; } } @@ -666,7 +663,11 @@ void deal(void) { } /* rest of the cards to the stock; NOTE: assert(avail==50) for spider */ for (f.z = 0; avail; f.z++) f.s[f.z] = deck[--avail]; - f.w = -1; /* @start: nothing on waste (no waste in spider -> const) */ +#ifdef KLONDIKE + f.w = -1; /* @start: nothing on waste */ +#elif defined SPIDER + f.w = 0; /* number of used foundations */ +#endif f.u = &undo_sentinel; } @@ -921,8 +922,8 @@ void undo_pop (struct undo* u) { f.t[u->f][++top] = f.f[u->n][i]; f.f[u->n][i] = NO_CARD; } - /* decrement complete-foundation-counter: */ - remove_if_complete(-1); + f.w--; /* decrement complete-foundation-counter */ + } else { /* tableu -> tableu */ int top_f = find_top(f.t[u->f]); diff --git a/sol.h b/sol.h index 1157458..ee60d5f 100644 --- a/sol.h +++ b/sol.h @@ -123,7 +123,7 @@ typedef signed char card_t; struct playfield { card_t s[MAX_STOCK]; /* stock */ int z; /* stock size */ - int w; /* waste; index into stock (const -1 in spider) */ + int w; /* waste; index into stock (used foundations in spider) */ card_t f[NUM_DECKS*NUM_SUITS][PILE_SIZE]; /* foundation */ card_t t[NUM_PILES][PILE_SIZE]; /* tableu piles */ struct undo { -- 2.39.3