is_selfatari(): Allow multiple captures contribute liberties
[pachi.git] / move.c
blobfc922dcf40b79370eda0bb2446201634eaf7b3bb
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;
24 static char bl[10][4];
25 static int bi;
26 if (is_pass(c)) {
27 return "pass";
28 } else if (is_resign(c)) {
29 return "resign";
30 } else {
31 /* Some GTP servers are broken and won't grok lowercase coords */
32 b = bl[bi]; bi = (bi + 1) % 10;
33 snprintf(b, 4, "%c%d", toupper(asdf[coord_x(c, board) - 1]), coord_y(c, board));
34 return b;
38 /* No sanity checking */
39 coord_t *
40 str2coord(char *str, int size)
42 if (!strcasecmp(str, "pass")) {
43 return coord_pass();
44 } else if (!strcasecmp(str, "resign")) {
45 return coord_resign();
46 } else {
47 char xc = tolower(str[0]);
48 return coord_init(xc - 'a' - (xc > 'i') + 1, atoi(str + 1), size);