coord_edge_distance(): Implement
[pachi.git] / move.h
blob973bf04662e768380a9ba262b700050e751e2b46
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;
10 struct board;
12 #define coord_raw(c) (c)
13 #define coord_x(c, b) ((c) % board_size(b))
14 #define coord_y(c, b) ((c) / board_size(b))
15 #define coord_eq(c1, c2) ((c1) == (c2))
17 static coord_t pass = -1;
18 static coord_t resign = -2;
19 #define is_pass(c) (coord_eq(c, pass))
20 #define is_resign(c) (coord_eq(c, resign))
22 /* Initialize existing coord */
23 #define coord_pos(coord, pos_, board) do { (coord) = (pos_); } while (0)
24 #define coord_xy(board, x, y) ((x) + (y) * board_size(board))
25 #define coord_xy_otf(x, y, board) coord_xy(board, x, y) // obsolete
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);
33 int coord_edge_distance(coord_t c, struct board *b);
35 struct board;
36 char *coord2str(coord_t c, struct board *b);
37 char *coord2sstr(coord_t c, struct board *b);
38 coord_t *str2coord(char *str, int board_size);
41 struct move {
42 coord_t coord;
43 enum stone color;
48 static inline coord_t *
49 coord_init(int x, int y, int size)
51 coord_t *c = calloc(1, sizeof(coord_t));
52 *c = x + y * size;
53 return c;
56 static inline coord_t *
57 coord_copy(coord_t c)
59 coord_t *c2 = calloc(1, sizeof(coord_t));
60 memcpy(c2, &c, sizeof(c));
61 return c2;
64 static inline coord_t *
65 coord_pass()
67 return coord_copy(pass);
70 static inline coord_t *
71 coord_resign()
73 return coord_copy(resign);
76 static inline void
77 coord_done(coord_t *c)
79 free(c);
82 #endif