diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ctaklm.c | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/src/ctaklm.c b/src/ctaklm.c index dee1855..ad8ab6e 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -19,7 +19,7 @@ char *rst = "\033[0m"; #define CHAR_STN '/' #define CHAR_CAP '*' -void +static void put_stone(const enum STONE_VARIANT stone, const enum COLOUR colour, const uint8_t top, const uint8_t beyond_carry_limit) { if (beyond_carry_limit) { @@ -40,7 +40,7 @@ put_stone(const enum STONE_VARIANT stone, const enum COLOUR colour, fputs(rst,stdout); } -void +static void print_cell_line(const uint8_t line, const uint8_t col, const uint8_t row) { @@ -71,7 +71,7 @@ print_cell_line(const uint8_t line, } } -void +static void print_board_line(const uint8_t line) { const uint8_t mod = line % (SQUARE_H + 1), row = board_size - line/(SQUARE_H + 1) - 1; @@ -89,7 +89,7 @@ print_board_line(const uint8_t line) { if (line < board_size*(SQUARE_H+1)) { for (uint8_t x = 0; x < board_size; x++) { putchar('|'); - print_cell_line(line - 1 , x, row); + print_cell_line(mod - 1 , x, row); } puts("|"); } else { @@ -103,7 +103,14 @@ print_board_line(const uint8_t line) { } } -void +static void +print_board(void) { + for (uint8_t k = 0; k<=board_size*(SQUARE_H+1)+1; k++) { + print_board_line(k); + } +} + +static void print_square(const uint8_t col, const uint8_t row) { if (row < board_size && col < board_size) { printf("%c%c: ",'a'+col,'1'+row); @@ -129,55 +136,50 @@ int main(int argc, char **argv) { reset_state(5); - enum E_RESULT r = try_place(THE_COORDS(0, 4), C_WHITE, STONE_STANDING); print_square(0, 4); - r = try_place(THE_COORDS(1, 4), C_BLACK, STONE_CAPSTONE); print_square(1, 4); - uint8_t drops[5] = {1,0,0,0,0}; - r = try_move(THE_COORDS(1, 4), M_LEFT, 1, drops); print_square(0, 4); - - uint8_t location; - enum STONE_VARIANT stone; - r = parse_place(5, "Cb3", &location, &stone); - - printf("Place <%d>: stone %d at (%d,%d)\n",r != PTN_VALID,stone,location%5,location/5); - - enum MOVE_DIRECTION direction; - uint8_t steps; - r = parse_move(5, "1c2+", &location, &direction, &steps, drops); - - printf("Move <%d>: from (%d,%d) step %d sequence [%d,%d,%d,%d,%d]\n", - r != PTN_VALID,location%5,location/5, - steps,drops[0],drops[1],drops[2],drops[3],drops[4]); - - char buf[10]; - generate_move(5, 2+5*1, M_UP, 1, drops, buf); - printf("Generated move: %s\n",buf); - - generate_place(5,1+5*2, STONE_CAPSTONE, buf); - printf("Generated place: %s\n",buf); - - for (uint8_t k = 0; k<=board_size*(SQUARE_H+1)+1; k++) { - print_board_line(k); + for (uint8_t k = 0; k<board_size; k++) { + try_place(THE_COORDS(1, k), C_WHITE, STONE_FLAT); + if (k+1<board_size) + try_place(THE_COORDS(0, k), C_BLACK, STONE_FLAT); } - return 0; + check_win(); + + enum E_RESULT r; char *line; - while((line = linenoise("hello> ")) != NULL) { - /* Do something with the string. */ - if (line[0] != '\0' && line[0] != '/') { - printf("echo: '%s'\n", line); - linenoiseHistoryAdd(line); /* Add to the history. */ - /* linenoiseHistorySave("history.txt"); /\* Save the history on disk. *\/ */ - } else if (!strncmp(line,"/historylen",11)) { - /* The "/historylen" command will change the history len. */ - int len = atoi(line+11); - linenoiseHistorySetMaxLen(len); - } else if (!strncmp(line, "/mask", 5)) { - linenoiseMaskModeEnable(); - } else if (!strncmp(line, "/unmask", 7)) { - linenoiseMaskModeDisable(); - } else if (line[0] == '/') { - printf("Unreconized command: %s\n", line); + while((line = linenoise("ctaklm> ")) != NULL) { + if (!strncmp(line,"board",6)) { + print_board(); + } else if (!strncmp(line,"square",6)) { + if (strnlen(line, 9) >= 9 + && line[7] >= 'a' && line[7] <= '`'+board_size + && line[8] >= '1' && line[8] <= '0'+board_size) { + print_square(line[7]-'a', line[8]-'1'); + } else { + printf("Usage: square [a-%c][1-%c]\n",'`'+board_size,'0'+board_size); + } + } else { + r = do_ptn(line); + printf("%d\n",r); + print_board(); } + + /* /\* Do something with the string. *\/ */ + /* if (line[0] != '\0' && line[0] != '/') { */ + /* printf("echo: '%s'\n", line); */ + /* linenoiseHistoryAdd(line); /\* Add to the history. *\/ */ + /* /\* linenoiseHistorySave("history.txt"); /\\* Save the history on disk. *\\/ *\/ */ + /* } else if (!strncmp(line,"/historylen",11)) { */ + /* /\* The "/historylen" command will change the history len. *\/ */ + /* int len = atoi(line+11); */ + /* linenoiseHistorySetMaxLen(len); */ + /* } else if (!strncmp(line, "/mask", 5)) { */ + /* linenoiseMaskModeEnable(); */ + /* } else if (!strncmp(line, "/unmask", 7)) { */ + /* linenoiseMaskModeDisable(); */ + /* } else if (line[0] == '/') { */ + /* printf("Unreconized command: %s\n", line); */ + /* } */ + free(line); } return 0; |
