From f5726995eb7f4c6ff2cf5564e19f9737f0f6fabd Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 5 Jan 2019 20:46:43 +0100 Subject: [PATCH] comments on the undo feature --- README.md | 18 ++++++++++++++++++ sol.c | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e3c413..c11e142 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,24 @@ 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.n` as index. (similar for foundation: overload `f.u.n` as foundation id) + - turning over cards: this needs to be encoded, because the card might + be consecutive and there's no way to tell what its previous state was. + at least 3 methods possible: + * indicate that a card was turned (can be at most 1) by negating u.n + pros: no wasted space, negation pattern already used for closed cards + cons: dirty C hack, less obvious than in other places, no need to + conserve memory this tightly + - another flag in f.u (.c for was-closed?) + pros: a little bit more obvious + cons: seems like a clutch to me, won't do anything in most cases + - two undo structures (where .f == .t for example; auto-apply both) + pros: no need to modify structures + cons: more burden on changing x2y(), need to check if we need to + execute two undos (or redos) at once everytime + will use the starred method (negating), because a) the code is + hackish aleady b) further cements the idea that .n is not just a + 'number of cards' but an argument that changes form depending on the + context. also, c) i don't like the other two options, because reasons. * TODO: cleanup: in `x2y()` functions there is a lot of replication and noise when calculating legal moves, top cards, etc. ### P3 diff --git a/sol.c b/sol.c index b439809..a2e4f33 100644 --- a/sol.c +++ b/sol.c @@ -827,13 +827,16 @@ fin: //}}} // undo related {{{ -void append_undo (int n, int f, int t) { +void append_undo (int f, int t, int n) { (void)n;(void)f;(void)t; //check if we have to free redo buffer (.next) //malloc //update pointers //TODO: undo; needs operations to be written by x2y() } +//TODO: free_undo(struct undo* l); //frees the list from here to then end (keeping .prev intact) // NOTE: this probably means we need to add a sentinel at the beginning (e.g. when deal()ing) +//TODO: apply_undo(struct undo* u); //undoes the operation pointed to by *u and moves the pointer one item back +//TODO: rename append->push, apply->pop (technically peek) //}}} // initialization stuff {{{ -- 2.39.3