summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ptn.c50
-rw-r--r--include/ptn.h10
2 files changed, 56 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;
+}
diff --git a/include/ptn.h b/include/ptn.h
index e780a70..0baed01 100644
--- a/include/ptn.h
+++ b/include/ptn.h
@@ -11,3 +11,13 @@ enum PTN_PARSE_RESULT
parse_move(const uint8_t board_size, char *ptn,
uint8_t *out_location, enum MOVE_DIRECTION *out_direction,
uint8_t *out_steps, uint8_t out_drops[5]);
+
+void
+generate_place(const uint8_t board_size, const uint8_t in_location,
+ const enum STONE_VARIANT in_stone, char out_ptn[4]);
+
+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]);