diff options
| author | tslil <tslil@posteo.de> | 2020-12-29 19:33:00 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | e57746530836b24b6d8d20e41239e955fa9e20d4 (patch) | |
| tree | 1118f87c57de6cc3798f1b29a5cefb982084b379 /include/ptn.c | |
| parent | 4a8e687b14b50e3a2a4a3632f6553872f4c301d5 (diff) | |
Output PTN as well
Diffstat (limited to 'include/ptn.c')
| -rw-r--r-- | include/ptn.c | 50 |
1 files changed, 46 insertions, 4 deletions
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 '<column><row><direction>' as + // Handle the case '[1]<column><row><direction>' as // '1<column><row><direction>1' 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<in_steps; k++) total+=in_drops[k]; + if (total > 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; +} |
