From 40f0a0fedc2e6e3eb48b8ff3bd5629f5051324ae Mon Sep 17 00:00:00 2001 From: girst Date: Mon, 5 Nov 2018 16:35:14 +0100 Subject: [PATCH] fix SEGV in spider waste was defined as 11, but action[][] is only 10 wide. m( --- README.md | 2 +- sol.c | 17 +++++++---------- sol.h | 5 +++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4cd944f..c86ef11 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ play klondike and spider solitaire in your unicode terminal. - insert append_undo() in x2y() functions - to encode stack position we need to overload f.u.f. can't do negative (-0), so +128 it is. - * TODO: sigint, sigcont handler! + * TODO: sigint, sigcont handler! atexit() to avoid inconsistent term state * TODO: cleanup: in `x2y()` functions there is a lot of replication and noise when calculating legal moves, top cards, etc. * TODO: some input functions are in `x2y()` -- move them to `get_cmd()` (req. diff --git a/sol.c b/sol.c index b84072f..ad27a44 100644 --- a/sol.c +++ b/sol.c @@ -31,19 +31,18 @@ ((get_suit(card) ^ get_suit(card)>>1) & 1) struct playfield { - //TODO: stock and waste are incompatible with undo{} card_t s[MAX_STOCK]; /* stock */ int z; /* stock size */ int w; /* waste; index into stock (const -1 in spider) */ - card_t f[NUM_DECKS*NUM_SUITS][PILE_SIZE]; /* foundation (XXX@spider:complete set gets put on seperate pile, so undo is easy) */ + card_t f[NUM_DECKS*NUM_SUITS][PILE_SIZE]; /* foundation */ card_t t[NUM_PILES][PILE_SIZE]; /* tableu piles */ struct undo { - int from; /* pile cards were taken from */ - int to; /* pile cards were moved to */ + int f; /* pile cards were taken from (overloaded:128+n=stock) */ + int t; /* pile cards were moved to */ int n; /* number of cards moved */ struct undo* prev; struct undo* next; - } u; + }* u; } f; struct opts { #ifdef SPIDER @@ -253,7 +252,7 @@ int t2t(int from, int to) { /* tableu to tableu */ } #elif defined SPIDER void remove_if_complete (card_t* pile) { //TODO: cleanup - static int foundation = 0; /* foundation to put pile onto */ + static int foundation = 0; /* where to put pile onto (1 set per stack)*/ /* test if K...A complete; move to foundation if so */ int top_from = find_top(pile); if (get_rank(pile[top_from]) != RANK_A) return; @@ -283,14 +282,12 @@ void remove_if_complete (card_t* pile) { //TODO: cleanup int t2t(int from, int to) { //TODO: in dire need of cleanup //TODO: segfaulted once on large column //TODO: sometimes moving doesn't work (ERR when it should be OK) XXX - (from < 0) && (from = 9); /* '0' is tenth ([9]) pile */ - (to < 0) && (to = 9); /* ditto */ int top_from = find_top(f.t[from]); int top_to = find_top(f.t[to]); int empty_to = -1; //awful, nondescriptive name :/ if (top_to < 0) { /* empty pile? */ - printf ("\rup to (a23456789xjqk): "); //TODO: automatically do it if only 1 card movable XXX: cant move ace + printf ("\rup to (a23456789xjqk): "); //TODO: automatically do it if only 1 card movable empty_to = getchar(); switch (empty_to) { case 'a': case 'A': empty_to = RANK_A; break; @@ -347,7 +344,7 @@ int nop(int from, int to) { (void)from;(void)to; return ERR; } int get_cmd (int* from, int* to) { //returns 0 on success or an error code indicating game quit, new game,... - //TODO: check validity, escape sequences (mouse, cursor keys) + //TODO: escape sequences (mouse, cursor keys) int f, t; f = getchar(); diff --git a/sol.h b/sol.h index e351002..490b906 100644 --- a/sol.h +++ b/sol.h @@ -67,10 +67,11 @@ enum field_places { TAB_8, TAB_9, TAB_10, -#endif + STOCK, +#define WASTE 0; /* need it for get_cmd(), but don't count it in NUM_PLACES */ +#elif defined KLONDIKE STOCK, WASTE, -#ifdef KLONDIKE FOUNDATION, #endif NUM_PLACES, -- 2.39.3