board_group_rmlib(): Zero out emptied spots in lib[]
[pachi.git] / move.h
blobc988dfcae12956a32c16dbcd907451ec82904b07
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(coord, x, y, board) coord_pos(coord, (x) + (y) * board_size(board), board)
24 #define coord_xy_otf(x, y, board) ((x) + (y) * board_size(board))
26 /* dyn allocated */
27 static coord_t *coord_init(int x, int y, int size);
28 static coord_t *coord_copy(coord_t c);
29 static coord_t *coord_pass(void);
30 static coord_t *coord_resign(void);
31 static void coord_done(coord_t *c);
33 struct board;
34 char *coord2str(coord_t c, struct board *b);
35 char *coord2sstr(coord_t c, struct board *b);
36 coord_t *str2coord(char *str, int board_size);
39 struct move {
40 coord_t coord;
41 enum stone color;
46 static inline coord_t *
47 coord_init(int x, int y, int size)
49 coord_t *c = calloc(1, sizeof(coord_t));
50 *c = x + y * size;
51 return c;
54 static inline coord_t *
55 coord_copy(coord_t c)
57 coord_t *c2 = calloc(1, sizeof(coord_t));
58 memcpy(c2, &c, sizeof(c));
59 return c2;
62 static inline coord_t *
63 coord_pass()
65 return coord_copy(pass);
68 static inline coord_t *
69 coord_resign()
71 return coord_copy(resign);
74 static inline void
75 coord_done(coord_t *c)
77 free(c);
80 #endif