Revert "Montecarlo: Support for showing 'second move' board stats"
[pachi.git] / move.h
bloba28637cfb3105f781cce958e6ea239ad933fc2f2
1 #ifndef ZZGO_MOVE_H
2 #define ZZGO_MOVE_H
4 #include <stdint.h>
5 #include <string.h>
7 #include "stone.h"
9 typedef struct coord {
10 uint16_t pos, size;
11 } coord_t;
13 #define coord_x(c) ((c).pos % (c).size)
14 #define coord_y(c) ((c).pos / (c).size)
15 #define coord_eq(c1, c2) ((c1).pos == (c2).pos)
17 static coord_t pass = { -1, 1 };
18 static coord_t resign = { -2, 1 };
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_t *c__ = &(coord); c__->size = (board)->size; c__->pos = (pos_); } while (0)
24 #define coord_xy(coord, x, y, board) coord_pos(coord, 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 char *coord2str(coord_t c);
34 coord_t *str2coord(char *str, int board_size);
37 struct move {
38 coord_t coord;
39 enum stone color;
44 static inline coord_t *
45 coord_init(int x, int y, int size)
47 coord_t *c = calloc(1, sizeof(coord_t));
48 c->size = size; c->pos = x + y * size;
49 return c;
52 static inline coord_t *
53 coord_copy(coord_t c)
55 coord_t *c2 = calloc(1, sizeof(coord_t));
56 memcpy(c2, &c, sizeof(c));
57 return c2;
60 static inline coord_t *
61 coord_pass()
63 return coord_copy(pass);
66 static inline coord_t *
67 coord_resign()
69 return coord_copy(resign);
72 static inline void
73 coord_done(coord_t *c)
75 free(c);
78 #endif