From 7a8db1787bb5fdc814bdd7af173bdab1a0fe1ba1 Mon Sep 17 00:00:00 2001 From: girst Date: Mon, 21 Jan 2019 19:39:09 +0100 Subject: [PATCH] allow inverted moves --- README.md | 2 +- sol.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bee6164..9396857 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ play klondike and spider solitaire in your unicode terminal. ### P1 ### P2 * TODO: suggest moves (`h` => hint) - * TODO: inverted moves (if A->B doesn't work, try B->A) * TODO: cleanup: in `x2y()` functions there is a lot of replication and noise when calculating legal moves, top cards, etc. ### P3 @@ -68,6 +67,7 @@ play klondike and spider solitaire in your unicode terminal. ln -s sol.c. spider.c sed -i 's/^spider: sol.c/spider: spider.c/' Makefile * DONE: escape sequences (for real cursor keys) + * DONE: inverted moves (if A->B doesn't work, try B->A) ## Notes diff --git a/sol.c b/sol.c index 31ffbcb..0f60a14 100644 --- a/sol.c +++ b/sol.c @@ -97,6 +97,7 @@ newgame: } int sol(void) { + int ret; long seed = time(NULL); restart: free_undo(f.u); @@ -106,9 +107,12 @@ restart: for(;;) { switch (get_cmd(&from, &to, &opt)) { case CMD_MOVE: - switch (action[from][to](from,to,opt)) { + ret = action[from][to](from,to,opt); + if (ret == ERR) /* try again with from/to swapped: */ + ret = action[to][from](to,from,opt); + switch (ret) { case OK: break; - case ERR: visbell(); break; //TODO: try again with from/to swapped + case ERR: visbell(); break; case WON: return GAME_WON; } break; @@ -131,7 +135,6 @@ restart: void quit(void) { screen_setup(0); - /* free undo data structures: */ free_undo(f.u); } //}}} -- 2.39.3