-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathstone.h
More file actions
54 lines (44 loc) · 979 Bytes
/
Copy pathstone.h
File metadata and controls
54 lines (44 loc) · 979 Bytes
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
#ifndef PACHI_STONE_H
#define PACHI_STONE_H
#include <assert.h>
enum stone {
S_NONE,
S_BLACK,
S_WHITE,
S_OFFBOARD,
S_MAX,
};
static char stone2char(enum stone s);
static enum stone char2stone(char s);
bool valid_color(char *s);
char *stone2str(enum stone s); /* static string */
enum stone str2stone(char *str);
static enum stone stone_other(enum stone s);
#define is_player_color(color) ((color) == S_BLACK || (color) == S_WHITE)
static inline char
stone2char(enum stone s)
{
return ".XO#"[s];
}
static inline enum stone
char2stone(char s)
{
switch (s) {
case '.': return S_NONE;
case 'X': return S_BLACK;
case 'O': return S_WHITE;
case '#': return S_OFFBOARD;
}
assert(0);
}
/* Curiously, gcc is reluctant to inline this; I have confirmed
* there is performance benefit. */
static inline enum stone __attribute__((always_inline))
stone_other(enum stone s)
{
#ifdef EXTRA_CHECKS
assert(is_player_color(s));
#endif
return (S_OFFBOARD - s);
}
#endif