summaryrefslogtreecommitdiff
path: root/src/ctaklm.c
blob: 13427703333f757e02b40580a83501ef35e5d669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <3rd-party/linenoise.h>
#include <tak.h>

int main(int argc, char **argv) {
  reset_state(5);

  enum E_RESULT r = try_place(0, C_BLACK, STONE_FLAT);
  r = try_place(1, C_BLACK, STONE_FLAT);
  uint8_t drops[5] = {1,0,0,0,0};
  r = try_move(1, M_LEFT, 1, drops);

  uint8_t location;
  enum STONE_VARIANT stone;
  r = parse_place(5, "Cb3", &location, &stone);

  printf("Place <%d>: stone %d at (%d,%d)\n",r,stone,location%5,location/5);

  enum MOVE_DIRECTION direction;
  uint8_t steps;
  r = parse_move(5, "3c2+12", &location, &direction, &steps, drops);

  printf("Move  <%d>: from (%d,%d) step %d sequence [%d,%d,%d,%d,%d]\n",
         r,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);

  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);
    }
    free(line);
  }
  return 0;

}