Add genmove.gtp for simple engine test
[pachi/peepo.git] / move.c
blob6443e8f04ee23e4aa32bd725f22a797c5cf9e5fd
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
6 #include "board.h"
7 #include "move.h"
10 /* The S_OFFBOARD margin is not addressable by coordinates. */
12 static char asdf[] = "abcdefghjklmnopqrstuvwxyz";
14 char *
15 coord2str(coord_t c, struct board *board)
17 return strdup(coord2sstr(c, board));
20 char *
21 coord2sstr(coord_t c, struct board *board)
23 static char b[4];
24 if (is_pass(c)) {
25 return "pass";
26 } else if (is_resign(c)) {
27 return "resign";
28 } else {
29 /* Some GTP servers are broken and won't grok lowercase coords */
30 snprintf(b, 4, "%c%d", toupper(asdf[coord_x(c, board) - 1]), coord_y(c, board));
31 return b;
35 /* No sanity checking */
36 coord_t *
37 str2coord(char *str, int size)
39 if (!strcasecmp(str, "pass")) {
40 return coord_pass();
41 } else if (!strcasecmp(str, "resign")) {
42 return coord_resign();
43 } else {
44 char xc = tolower(str[0]);
45 return coord_init(xc - 'a' - (xc > 'i') + 1, atoi(str + 1), size);