gtp.c: time_sub() now has an extra parameter.
[pachi/pachi-r6144.git] / move.h
blob94f7957942d26d4d5b43287cb686c631073c50bc
1 #ifndef ZZGO_MOVE_H
2 #define ZZGO_MOVE_H
4 #include <stdint.h>
5 #include <string.h>
7 #include "util.h"
8 #include "stone.h"
10 typedef int coord_t;
12 #define coord_xy(board, x, y) ((x) + (y) * board_size(board))
13 #define coord_x(c, b) ((b)->coord[c][0])
14 #define coord_y(c, b) ((b)->coord[c][1])
15 /* TODO: Smarter way to do this? */
16 #define coord_dx(c1, c2, b) (coord_x(c1, b) - coord_x(c2, b))
17 #define coord_dy(c1, c2, b) (coord_y(c1, b) - coord_y(c2, b))
19 static coord_t pass = -1;
20 static coord_t resign = -2;
21 #define is_pass(c) (c == pass)
22 #define is_resign(c) (c == resign)
24 #define coord_is_adjecent(c1, c2, b) (abs(c1 - c2) == 1 || abs(c1 - c2) == board_size(b))
25 #define coord_is_8adjecent(c1, c2, b) (abs(c1 - c2) == 1 || abs(abs(c1 - c2) - board_size(b)) < 2)
27 /* dyn allocated */
28 static coord_t *coord_init(int x, int y, int size);
29 static coord_t *coord_copy(coord_t c);
30 static coord_t *coord_pass(void);
31 static coord_t *coord_resign(void);
32 static void coord_done(coord_t *c);
34 struct board;
35 /* Return coordinate string in a dynamically allocated buffer. Thread-safe. */
36 char *coord2str(coord_t c, struct board *b);
37 /* Return coordinate string in a static buffer; multiple buffers are shuffled
38 * to enable use for multiple printf() parameters, but it is NOT safe for
39 * anything but debugging - in particular, it is NOT thread-safe! */
40 char *coord2sstr(coord_t c, struct board *b);
41 coord_t *str2coord(char *str, int board_size);
44 struct move {
45 coord_t coord;
46 enum stone color;
51 static inline coord_t *
52 coord_init(int x, int y, int size)
54 coord_t *c = calloc2(1, sizeof(coord_t));
55 *c = x + y * size;
56 return c;
59 static inline coord_t *
60 coord_copy(coord_t c)
62 coord_t *c2 = calloc2(1, sizeof(coord_t));
63 memcpy(c2, &c, sizeof(c));
64 return c2;
67 static inline coord_t *
68 coord_pass()
70 return coord_copy(pass);
73 static inline coord_t *
74 coord_resign()
76 return coord_copy(resign);
79 static inline void
80 coord_done(coord_t *c)
82 free(c);
85 #endif