summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-01-23 21:52:53 -0500
committerJune McEnroe <june@causal.agency>2018-01-23 21:52:53 -0500
commitfe82240f95853426750fcd751e72f739d466b7d7 (patch)
tree458373ac77edd7645836462160e4a12eeadbf523 /bin
parentAdd control to klon (diff)
downloadsrc-fe82240f95853426750fcd751e72f739d466b7d7.tar.gz
src-fe82240f95853426750fcd751e72f739d466b7d7.zip
Add autoFound
Still messy though.
Diffstat (limited to 'bin')
-rw-r--r--bin/klon.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/bin/klon.c b/bin/klon.c
index 8267b25a..0e0e3d4c 100644
--- a/bin/klon.c
+++ b/bin/klon.c
@@ -155,6 +155,13 @@ static bool canTable(const struct Stack *table, uint8_t card) {
     return (card & MASK_RANK) == (get(table, 0) & MASK_RANK) - 1;
 }
 
+static struct Stack *autoFound(uint8_t card) {
+    for (int i = 0; i < 4; ++i) {
+        if (canFound(&g.found[i], card)) return &g.found[i];
+    }
+    return NULL;
+}
+
 enum {
     PAIR_EMPTY = 1,
     PAIR_BACK,
@@ -241,7 +248,7 @@ static void render(void) {
     x = 2;
     for (int i = 0; i < 7; ++i) {
         y = 5;
-        // FIXME: Render empty.
+        renderCard(y, x, 0);
         for (int j = len(&g.table[i]); j > 0; --j) {
             renderCard(y, x, get(&g.table[i], j - 1));
             y++;
@@ -275,8 +282,6 @@ static void cancel(void) {
     depth = 0;
 }
 
-#define ESC (0x1B)
-
 int main() {
     curse();
 
@@ -299,6 +304,15 @@ int main() {
                 } else {
                     cancel();
                 }
+            } else if ((c == 'f' || c == '\n') && depth == 1) {
+                struct Stack *found = autoFound(get(src, 0));
+                if (found) {
+                    transfer(found, src, depth);
+                    src = NULL;
+                    depth = 0;
+                } else {
+                    cancel();
+                }
             } else if (c >= '1' && c <= '7') {
                 if (src == &g.table[c - '1']) {
                     deepen();