UCT Prior: Enable b19, cfgd by default
[pachi.git] / move.h
bloba8c93894bd1176954589262c731d729ab053a990
1 #ifndef ZZGO_MOVE_H
2 #define ZZGO_MOVE_H
4 #include <stdint.h>
5 #include <string.h>
7 #include "stone.h"
9 typedef int coord_t;
11 #define coord_raw(c) (c)
12 #define coord_x(c, b) ((c) % board_size(b))
13 #define coord_y(c, b) ((c) / board_size(b))
14 #define coord_eq(c1, c2) ((c1) == (c2))
16 static coord_t pass = -1;
17 static coord_t resign = -2;
18 #define is_pass(c) (coord_eq(c, pass))
19 #define is_resign(c) (coord_eq(c, resign))
21 /* Initialize existing coord */
22 #define coord_pos(coord, pos_, board) do { (coord) = (pos_); } while (0)
23 #define coord_xy(board, x, y) ((x) + (y) * board_size(board))
24 #define coord_xy_otf(x, y, board) coord_xy(board, x, y) // obsolete
26 #define coord_is_adjecent(c1, c2, b) (abs(c1 - c2) == 1 || abs(c1 - c2) == board_size(b))
27 #define coord_is_8adjecent(c1, c2, b) (abs(c1 - c2) == 1 || abs(abs(c1 - c2) - board_size(b)) < 2)
29 /* dyn allocated */
30 static coord_t *coord_init(int x, int y, int size);
31 static coord_t *coord_copy(coord_t c);
32 static coord_t *coord_pass(void);
33 static coord_t *coord_resign(void);
34 static void coord_done(coord_t *c);
36 struct board;
37 int coord_edge_distance(coord_t c, struct board *b);
38 char *coord2str(coord_t c, struct board *b);
39 char *coord2sstr(coord_t c, struct board *b);
40 coord_t *str2coord(char *str, int board_size);
43 struct move {
44 coord_t coord;
45 enum stone color;
50 static inline coord_t *
51 coord_init(int x, int y, int size)
53 coord_t *c = calloc(1, sizeof(coord_t));
54 *c = x + y * size;
55 return c;
58 static inline coord_t *
59 coord_copy(coord_t c)
61 coord_t *c2 = calloc(1, sizeof(coord_t));
62 memcpy(c2, &c, sizeof(c));
63 return c2;
66 static inline coord_t *
67 coord_pass()
69 return coord_copy(pass);
72 static inline coord_t *
73 coord_resign()
75 return coord_copy(resign);
78 static inline void
79 coord_done(coord_t *c)
81 free(c);
84 #endif