summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2020-12-30 18:39:20 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit77de899d5b1abfabe40371f2f6fa4517ace0e28c (patch)
tree078c92cc29467654dfa803f915ca22477bf6cf4e
parent9e926c41c05daae9dd8e6e4af20131d55cf2de03 (diff)
Corrected PTN move parsing
-rw-r--r--include/tak.c21
-rw-r--r--include/tak.h6
2 files changed, 12 insertions, 15 deletions
diff --git a/include/tak.c b/include/tak.c
index 1970fca..6bb11ec 100644
--- a/include/tak.c
+++ b/include/tak.c
@@ -3,18 +3,11 @@
// -------------------------------------------------------------------
// Helpers
-#define NUM_SHIFT 4
#define NUM_INC (0x1<<NUM_SHIFT) // 0b00010000
#define NUM_MASK (0xF<<NUM_SHIFT) // 0b11110000
-#define STONE_MASK 0b00000011
#define DFS_MASK 0b00001100
#define USED_MASK 0b11110011
-#define STONE_AT(l) (celldat[(l)] & STONE_MASK)
-#define COUNT_AT(l) (celldat[(l)] >> NUM_SHIFT)
-
-#define THE_COORDS(x,y) ((x)+(y)*board_size)
-
// -------------------------------------------------------------------
// General state stuff
@@ -389,15 +382,13 @@ parse_move(const uint8_t board_size, char *ptn,
}
ptn++;
- // Handle the case '[1]<column><row><direction>' as
- // '1<column><row><direction>1' for convenience
+ // Handle the case 'n<column><row><direction>' as
+ // 'n<column><row><direction>n' for convenience, if n is omitted
+ // assume n = 1
if (*ptn == 0) {
- if (picked_up == 1) {
- *out_steps = 1;
- out_drops[0] = 1;
- } else {
- return PTN_INVALID;
- }
+ *out_steps = picked_up;
+ out_drops[0] = picked_up;
+ return PTN_VALID;
}
*out_steps = 0;
diff --git a/include/tak.h b/include/tak.h
index c703943..d161640 100644
--- a/include/tak.h
+++ b/include/tak.h
@@ -16,6 +16,12 @@ enum MOVE_DIRECTION { M_UP, M_DOWN, M_LEFT, M_RIGHT };
typedef uint8_t data_t;
typedef uint16_t colour_stack_t;
+#define NUM_SHIFT 4
+#define STONE_MASK 0b00000011
+#define STONE_AT(l) (celldat[(l)] & STONE_MASK)
+#define COUNT_AT(l) (celldat[(l)] >> NUM_SHIFT)
+#define THE_COORDS(x,y) ((x)+(y)*board_size)
+
uint8_t board_size;
data_t celldat[36];
colour_stack_t colours[36];