-
Notifications
You must be signed in to change notification settings - Fork 117
/
stone.h
50 lines (42 loc) · 1 KB
/
stone.h
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
#ifndef PACHI_STONE_H
#define PACHI_STONE_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);
char *stone2str(enum stone s); /* static string */
enum stone str2stone(char *str);
static enum stone stone_other(enum stone s);
static inline char
stone2char(enum stone s)
{
/* Hack: stone2char(S_MAX) = ' '
* Allow S_MAX here so can blank-out parts of the
* board in board_print() (see spatial_print()) */
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;
}
return S_NONE; // XXX
}
/* Curiously, gcc is reluctant to inline this; I have cofirmed
* there is performance benefit. */
static inline enum stone __attribute__((always_inline))
stone_other(enum stone s)
{
static const enum stone o[S_MAX] = { S_NONE, S_WHITE, S_BLACK, S_OFFBOARD };
return o[s];
}
#endif