From 9bbc25438e55b3d25cc4762311c3810352d25da7 Mon Sep 17 00:00:00 2001 From: girst Date: Wed, 20 Apr 2022 18:39:29 +0200 Subject: [PATCH] freecell: fix direct addressing 'take from cell' the 'no take from empty stock/cell' rule had a bug that only checked the first cell when accessed with '9'. this is because with direct addressing mode, active.opt stays at its initial value of 0. this check was split in two parts: - direct addressing: only abort when all cells are empty - other: check that struct cursor active was actually modified. a third test was then added to make this work with mouse addressing also. --- sol.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sol.c b/sol.c index 487e309..154be36 100644 --- a/sol.c +++ b/sol.c @@ -1084,9 +1084,20 @@ from_l: print_table(&active, &inactive); default: return CMD_INVAL; } inactive.pile = *from; /* for direct addressing highlighting */ + + /* prevent taking from empty tableu pile: */ if (is_tableu(*from) && f.t[*from][0] == NO_CARD) return CMD_INVAL; + #ifdef FREECELL - if (*from == STOCK && f.s[active.opt] == NO_CARD) return CMD_INVAL; + /* basic test and direct addressing: */ + if (*from == STOCK && !(f.s[0]||f.s[1]||f.s[2]||f.s[3])) + return CMD_INVAL; + /* cursor keys addressing: */ + if (active.pile == STOCK && f.s[active.opt] == NO_CARD) + return CMD_INVAL; + /* mouse addressing: */ + if (inactive.pile == STOCK && inactive.opt > -1 && f.s[inactive.opt] == NO_CARD) + return CMD_INVAL; #endif #ifndef FREECELL -- 2.39.3