From e57746530836b24b6d8d20e41239e955fa9e20d4 Mon Sep 17 00:00:00 2001 From: tslil Date: Tue, 29 Dec 2020 19:33:00 -0500 Subject: Output PTN as well --- include/ptn.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'include/ptn.c') diff --git a/include/ptn.c b/include/ptn.c index 1a333d7..66b4ad8 100644 --- a/include/ptn.c +++ b/include/ptn.c @@ -42,7 +42,7 @@ parse_move(const uint8_t board_size, char *ptn, ASSERT_NONEMPTY; - uint8_t picked_up = 0; + uint8_t picked_up = 1; if ( (*ptn >= '1') && (*ptn <= '0' + board_size)) { picked_up = *ptn - '0'; @@ -68,10 +68,10 @@ parse_move(const uint8_t board_size, char *ptn, } ptn++; - // Handle the case '' as + // Handle the case '[1]' as // '11' for convenience if (*ptn == 0) { - if (picked_up == 0) { + if (picked_up == 1) { *out_steps = 1; out_drops[0] = 1; } else { @@ -94,7 +94,49 @@ parse_move(const uint8_t board_size, char *ptn, ptn++; } - if ( (picked_up > 0) && (total != picked_up) ) return PTN_INVALID; + if ( total != picked_up ) return PTN_INVALID; return PTN_VALID; } + +void +generate_place(const uint8_t board_size, const uint8_t in_location, + const enum STONE_VARIANT in_stone, char out_ptn[4]) { + switch (in_stone) { + case STONE_FLAT: { break; } + case STONE_STANDING: { *out_ptn = 'S'; out_ptn++; break; } + case STONE_CAPSTONE: { *out_ptn = 'C'; out_ptn++; break; } + } + *out_ptn = 'a' + (in_location % board_size); out_ptn++; + *out_ptn = '1' + (in_location / board_size); out_ptn++; + *out_ptn = 0; +} + +void +generate_move(const uint8_t board_size, const uint8_t in_location, + const enum MOVE_DIRECTION in_direction, + const uint8_t in_steps, const uint8_t in_drops[5], + char out_ptn[10]) { + uint8_t total = 0; + for (uint8_t k = 0; k 1) { + *out_ptn = '0' + total; out_ptn++; + } + + *out_ptn = 'a' + (in_location % board_size); out_ptn++; + *out_ptn = '1' + (in_location / board_size); out_ptn++; + + switch (in_direction) { + case M_UP: { *out_ptn = '+'; break; } + case M_DOWN: { *out_ptn = '-'; break; } + case M_LEFT: { *out_ptn = '<'; break; } + case M_RIGHT: { *out_ptn = '>'; break; } + }; out_ptn++; + + + for (uint8_t k = 0; (total > 1) && (k < in_steps); k++) { + *out_ptn = '0' + in_drops[k]; out_ptn++; + } + + *out_ptn = 0; +} -- cgit v1.3.1