-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathmove.h
More file actions
77 lines (61 loc) · 2.37 KB
/
Copy pathmove.h
File metadata and controls
77 lines (61 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef PACHI_MOVE_H
#define PACHI_MOVE_H
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include "util.h"
#include "stone.h"
typedef int coord_t;
#define offset_horiz (1)
#define offset_vert (the_board_stride())
/* Swap offset: horizontal <-> vertical.
* Handles negative input also (-offset_horiz / -offset_vert),
* so can be used on neighbor coords delta to find the other direction:
* other_offset(c2 - c1)
* gives perpendicular offset to c1 -> c2 offset. */
#define other_offset(offset) (offset_horiz + offset_vert - abs(offset));
#define offset_left (-offset_horiz)
#define offset_right (offset_horiz)
#define offset_down (-offset_vert)
#define offset_up (offset_vert)
// XXX board_size() instead of board_statics.size
#define coord_xy(x, y) ((x) + (y) * the_board_stride())
#define coord_x(c) (board_statics.coord[c][0])
#define coord_y(c) (board_statics.coord[c][1])
/* TODO: Smarter way to do this? */
#define coord_dx(c1, c2) (coord_x(c1) - coord_x(c2))
#define coord_dy(c1, c2) (coord_y(c1) - coord_y(c2))
#define pass -1
#define resign -2
#define is_pass(c) (c == pass)
#define is_resign(c) (c == resign)
#define coord_is_adjecent(c1, c2) (abs(c1 - c2) == offset_horiz || abs(c1 - c2) == offset_vert)
#define coord_is_8adjecent(c1, c2) (abs(c1 - c2) == offset_horiz || abs(abs(c1 - c2) - offset_vert) < 2)
char *coord2bstr(char *buf, coord_t c);
/* Return coordinate string in a dynamically allocated buffer. Thread-safe. */
char *coord2str(coord_t c);
/* Return coordinate string in a static buffer; multiple buffers are shuffled
* to enable use for multiple printf() parameters, but it is NOT safe for
* anything but debugging - in particular, it is NOT thread-safe! */
char *coord2sstr(coord_t c);
coord_t str2coord(char *str);
coord_t str2coord_for(char *str, int size);
/* Rotate coordinate according to rot: [0-7] for 8 board symmetries. */
coord_t rotate_coord(coord_t c, int rot);
/* Check string coord is valid for current board. */
bool valid_coord(char *s);
/* Check coord doesn't lie outside (board + offboard margin) area. */
#define sane_coord(c) ((c) >= 0 && (c) < board_statics.max_coords)
typedef struct {
coord_t coord;
enum stone color;
} move_t;
#define move(coord, color) { coord, color }
static inline int
move_cmp(move_t *m1, move_t *m2)
{
if (m1->color != m2->color)
return m1->color - m2->color;
return m1->coord - m2->coord;
}
#endif