10 /* The S_OFFBOARD margin is not addressable by coordinates. */
12 static char asdf
[] = "abcdefghjklmnopqrstuvwxyz";
15 coord2str(coord_t c
, struct board
*board
)
17 return strdup(coord2sstr(c
, board
));
21 coord2sstr(coord_t c
, struct board
*board
)
24 static char bl
[10][4];
28 } else if (is_resign(c
)) {
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
));
38 /* No sanity checking */
40 str2coord(char *str
, int size
)
42 if (!strcasecmp(str
, "pass")) {
44 } else if (!strcasecmp(str
, "resign")) {
45 return coord_resign();
47 char xc
= tolower(str
[0]);
48 return coord_init(xc
- 'a' - (xc
> 'i') + 1, atoi(str
+ 1), size
);
54 coord_edge_distance(coord_t c
, struct board
*b
)
56 int x
= coord_x(c
, b
), y
= coord_y(c
, b
);
57 int dx
= x
> board_size(b
) / 2 ? board_size(b
) - x
: x
;
58 int dy
= y
> board_size(b
) / 2 ? board_size(b
) - y
: y
;
59 return (dx
< dy
? dx
: dy
) - 1 /* S_OFFBOARD */;