From 77de899d5b1abfabe40371f2f6fa4517ace0e28c Mon Sep 17 00:00:00 2001 From: tslil Date: Wed, 30 Dec 2020 18:39:20 -0500 Subject: Corrected PTN move parsing --- include/tak.c | 21 ++++++--------------- include/tak.h | 6 ++++++ 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) - -#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]' as - // '11' for convenience + // Handle the case 'n' as + // 'nn' 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]; -- cgit v1.2.3