bd_rules.c

filter: Statementstmt 98.0% 153 / 156 Branchbran 76.0% 105 / 138 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 87.7% 258 / 294 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Brandubh.xs ↑ Summary bd_search.c »
1 /* bd_rules.c - a game: a board, the moves that made it, and how it ends.
2 *
3 * PERL-FREE, as the other bd_*.c files are.
4 *
5 * THE RULES THIS FILE IMPLEMENTS, quoted from the source the distribution
6 * names in its documentation:
7 *
8 * 11. "The king wins the game on reaching any of the marked corner squares.
9 * The attackers win if they capture the king."
10 * 12. "The game is drawn if a position is repeated, if a player cannot move,
11 * or if the players otherwise agree it."
12 *
13 * and three decisions where that text is silent or would give a result nobody
14 * means:
15 *
16 * - "REPEATED" IS THE THIRD TIME, with the same side to move, as draughts
17 * and chess count it. bd_variant.repeat says which occurrence; the literal
18 * reading of the sentence is 2.
19 * - ATTACKERS WITH NO PIECE LEFT HAVE LOST. Read literally rule 12 draws
20 * that game, because a side with nothing "cannot move". The sentence is
21 * for a side that is blocked.
22 * - A GAME THAT WILL NOT END IS DRAWN AT A PLY CAP. The attackers can seal
23 * all four corners, and then nothing above ends the game.
24 *
25 * Agreement and resignation are not here. They are something two people do,
26 * and the caller records them.
27 *
28 * THE ORDER THE ENDINGS ARE ASKED IN IS PART OF THE RULE, because one move can
29 * satisfy two of them:
30 *
31 * 1. the win the move itself made: the king home, or the king taken
32 * 2. the attackers have no piece
33 * 3. the side to move has no legal move
34 * 4. the position has occurred for the Nth time
35 * 5. the ply cap
36 *
37 * So a king who reaches a corner on the move that also repeats a position has
38 * won, and taking the last attacker is a win and not a blocked side.
39 */
40  
41 #include <stdlib.h>
42 #include <string.h>
43 #include "bd_abi.h"
44  
45 100621653 static const struct bd_abi *E(void) { return bd_abi_table(); }
46  
47 /* ---- the game ------------------------------------------------------------------
48 *
49 * Everything about a ply is kept by its index: the key of the position after
50 * it, the outcome as it stood then, whether the move that made it captured,
51 * and the undo that takes it back. Index 0 is the starting position and has no
52 * move behind it.
53 *
54 * THE ARRAYS HOLD ply_cap + 1 ENTRIES AND CANNOT OVERFLOW: at the cap the
55 * outcome is a draw and game_do refuses, so the index never passes it.
56 */
57  
58 struct bd_game {
59 struct bd_board *board;
60 struct bd_variant variant;
61 int cap; /* the ply cap, as clamped */
62 int ply; /* moves made so far */
63 unsigned long long *key; /* [0 .. cap] */
64 int *outcome; /* [0 .. cap] */
65 unsigned char *captured; /* [0 .. cap], 1 if that move captured */
66 struct bd_undo *undo; /* [1 .. cap], undo[i] takes ply i back */
67 };
68  
69 static int GAMES_LIVE = 0;
70  
71 /* A rule set as a game will use it. A cap of nothing or less means the
72 * default, and so does a cap above what the arrays are allowed to be; a
73 * repeat below 2 would draw every game at its first position, and means 2. */
74 17076 static void variant_clamped(struct bd_variant *out, const struct bd_variant *v)
75 {
76 17076 ▶ if (v) *out = *v;
Branch: 1 branch
BranchTrueFalseTotal
if (v) *out = *v; 17076 0 17076
77 0 else (E())->variant_default(out);
78 17076 ▶ if (out->ply_cap <= 0 || out->ply_cap > BD_PLY_CAP_MAX) out->ply_cap = BD_PLY_CAP_DEFAULT;
Branch: 2 branches
BranchTrueFalseTotal
if (out->ply_cap <= 0 || out->ply_cap > BD_PLY_CAP_MAX) out->ply_cap = BD_PLY_CAP_DEFAULT; 17074 2 17076
if (out->ply_cap <= 0 || out->ply_cap > BD_PLY_CAP_MAX) out->ply_cap = BD_PLY_CAP_DEFAULT; 1 17073 17074
79 17076 ▶ if (out->repeat < 2) out->repeat = 2;
Branch: 1 branch
BranchTrueFalseTotal
if (out->repeat < 2) out->repeat = 2; 2 17074 17076
80 17076 }
81  
82 /* ---- repetition -----------------------------------------------------------------
83 *
84 * How many times the current position has occurred, this time included.
85 *
86 * THE WALK STOPS AT THE LAST CAPTURE. Pieces only ever leave the board, so a
87 * position from before a capture has more pieces on it than any after and
88 * cannot be the one on the board now. Stopping there changes no answer; it
89 * only means a long game does not search its whole length on every move.
90 *
91 * A KEY MATCH IS TRUSTED. Two different positions sharing a 64-bit key would
92 * be a draw called in error, and nothing here guards against it.
93 */
94 24665268 static int bd_repeats(const struct bd_game *g)
95 {
96 unsigned long long now;
97 24665268 int i, n = 0;
98 24665268 ▶ if (!g) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!g) return 0; 0 24665268 24665268
99 24665268 now = g->key[g->ply];
100 220900669 ▶ for (i = g->ply; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = g->ply; i >= 0; i--) { 212804064 8096605 220900669
101 212804064 ▶ if (g->key[i] == now) n++;
Branch: 1 branch
BranchTrueFalseTotal
if (g->key[i] == now) n++; 24702106 188101958 212804064
102 212804064 ▶ if (g->captured[i]) break;
Branch: 1 branch
BranchTrueFalseTotal
if (g->captured[i]) break; 16568663 196235401 212804064
103 }
104 24665268 return n;
105 }
106  
107 /* ---- the outcome ------------------------------------------------------------------ */
108  
109 8909 static int king_home_somewhere(const struct bd_game *g)
110 {
111 int f, r;
112 70069 ▶ for (r = 0; r < BD_SIZE; r++) {
Branch: 1 branch
BranchTrueFalseTotal
for (r = 0; r < BD_SIZE; r++) { 61460 8609 70069
113 490444 ▶ for (f = 0; f < BD_SIZE; f++) {
Branch: 1 branch
BranchTrueFalseTotal
for (f = 0; f < BD_SIZE; f++) { 429284 61160 490444
114 429284 int sq = (E())->square_of(f, r);
115 429284 ▶ int edge = f == 0 || r == 0 || f == BD_SIZE - 1 || r == BD_SIZE - 1;
Branch: 4 branches
BranchTrueFalseTotal
int edge = f == 0 || r == 0 || f == BD_SIZE - 1 || r == BD_SIZE - 1; 367824 61460 429284
int edge = f == 0 || r == 0 || f == BD_SIZE - 1 || r == BD_SIZE - 1; 314814 53010 367824
int edge = f == 0 || r == 0 || f == BD_SIZE - 1 || r == BD_SIZE - 1; 262345 52469 314814
int edge = f == 0 || r == 0 || f == BD_SIZE - 1 || r == BD_SIZE - 1; 43385 218960 262345
116 429284 ▶ if ((E())->at(g->board, sq) != BD_KING) continue;
Branch: 1 branch
BranchTrueFalseTotal
if ((E())->at(g->board, sq) != BD_KING) continue; 420357 8927 429284
117 8927 ▶ if ((E())->is_corner(sq) || (g->variant.escape_edge && edge)) return 1;
Branch: 3 branches
BranchTrueFalseTotal
if ((E())->is_corner(sq) || (g->variant.escape_edge && edge)) return 1; 8628 299 8927
if ((E())->is_corner(sq) || (g->variant.escape_edge && edge)) return 1; 312 8316 8628
if ((E())->is_corner(sq) || (g->variant.escape_edge && edge)) return 1; 1 311 312
118 }
119 }
120 8609 return 0;
121 }
122  
123 /* endings 2 to 5: the ones that are read off the position and its history and
124 * not off the move that was just made */
125 254917 static int judge_rest(const struct bd_game *g)
126 {
127 254917 ▶ if ((E())->count(g->board, BD_ATTACKER) == 0) return BD_BY_NO_PIECES;
Branch: 1 branch
BranchTrueFalseTotal
if ((E())->count(g->board, BD_ATTACKER) == 0) return BD_BY_NO_PIECES; 54 254863 254917
128 254863 ▶ if ((E())->gen_moves(g->board, &g->variant, NULL, 0) == 0) return BD_DRAW_NO_MOVE;
Branch: 1 branch
BranchTrueFalseTotal
if ((E())->gen_moves(g->board, &g->variant, NULL, 0) == 0) return BD_DRAW_NO_MOVE; 27 254836 254863
129 254836 ▶ if (bd_repeats(g) >= g->variant.repeat) return BD_DRAW_REPETITION;
Branch: 1 branch
BranchTrueFalseTotal
if (bd_repeats(g) >= g->variant.repeat) return BD_DRAW_REPETITION; 57 254779 254836
130 254779 ▶ if (g->ply >= g->cap) return BD_DRAW_PLY_CAP;
Branch: 1 branch
BranchTrueFalseTotal
if (g->ply >= g->cap) return BD_DRAW_PLY_CAP; 422 254357 254779
131 254357 return BD_ONGOING;
132 }
133  
134 /* A position nobody moved into, so there is no move to read a win from. No
135 * king on the board: he has been captured. A king standing where he wins: he
136 * has won. Otherwise it is judged like any other. */
137 8917 static int judge_start(const struct bd_game *g)
138 {
139 8917 ▶ if ((E())->count(g->board, BD_KING) == 0) return BD_BY_CAPTURE;
Branch: 1 branch
BranchTrueFalseTotal
if ((E())->count(g->board, BD_KING) == 0) return BD_BY_CAPTURE; 8 8909 8917
140 8909 ▶ if (king_home_somewhere(g)) return BD_BY_CORNER;
Branch: 1 branch
BranchTrueFalseTotal
if (king_home_somewhere(g)) return BD_BY_CORNER; 300 8609 8909
141 8609 return judge_rest(g);
142 }
143  
144 248999 static int judge_move(const struct bd_game *g, int flags)
145 {
146 248999 ▶ if (flags & BD_KING_HOME) return BD_BY_CORNER;
Branch: 1 branch
BranchTrueFalseTotal
if (flags & BD_KING_HOME) return BD_BY_CORNER; 1954 247045 248999
147 247045 ▶ if (flags & BD_KING_TAKEN) return BD_BY_CAPTURE;
Branch: 1 branch
BranchTrueFalseTotal
if (flags & BD_KING_TAKEN) return BD_BY_CAPTURE; 737 246308 247045
148 246308 return judge_rest(g);
149 }
150  
151 /* ---- lifecycle -------------------------------------------------------------------- */
152  
153 17076 static void bd_game_drop(struct bd_game *g)
154 {
155 17076 ▶ if (!g) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!g) return; 0 17076 17076
156 17076 ▶ if (g->board) (E())->board_drop(g->board);
Branch: 1 branch
BranchTrueFalseTotal
if (g->board) (E())->board_drop(g->board); 17076 0 17076
157 17076 free(g->key);
158 17076 free(g->outcome);
159 17076 free(g->captured);
160 17076 free(g->undo);
161 17076 free(g);
162 17076 GAMES_LIVE--;
163 }
164  
165 17076 static struct bd_game *game_alloc(const struct bd_variant *v)
166 {
167 17076 struct bd_game *g = (struct bd_game *) calloc(1, sizeof(struct bd_game));
168 size_t slots;
169 17076 ▶ if (!g) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!g) return NULL; 0 17076 17076
170 17076 GAMES_LIVE++;
171 17076 variant_clamped(&g->variant, v);
172 17076 g->cap = g->variant.ply_cap;
173 17076 slots = (size_t) g->cap + 1;
174 17076 g->key = (unsigned long long *) calloc(slots, sizeof(unsigned long long));
175 17076 g->outcome = (int *) calloc(slots, sizeof(int));
176 17076 g->captured = (unsigned char *) calloc(slots, 1);
177 17076 g->undo = (struct bd_undo *) calloc(slots, sizeof(struct bd_undo));
178 17076 ▶ if (!g->key || !g->outcome || !g->captured || !g->undo) {
Branch: 4 branches
BranchTrueFalseTotal
if (!g->key || !g->outcome || !g->captured || !g->undo) { 17076 0 17076
if (!g->key || !g->outcome || !g->captured || !g->undo) { 17076 0 17076
if (!g->key || !g->outcome || !g->captured || !g->undo) { 17076 0 17076
if (!g->key || !g->outcome || !g->captured || !g->undo) { 0 17076 17076
179 0 bd_game_drop(g);
180 0 return NULL;
181 }
182 17076 return g;
183 }
184  
185 /* A game from a copy of `b`, or from the set-up when `b` is NULL. The board
186 * handed in is left alone and may be dropped at once. */
187 8917 static struct bd_game *bd_game_new(const struct bd_board *b, const struct bd_variant *v)
188 {
189 8917 struct bd_game *g = game_alloc(v);
190 8917 ▶ if (!g) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!g) return NULL; 0 8917 8917
191 8917 ▶ g->board = b ? (E())->board_copy(b) : (E())->board_new();
Branch: 1 branch
BranchTrueFalseTotal
g->board = b ? (E())->board_copy(b) : (E())->board_new(); 7875 1042 8917
192 8917 ▶ if (!g->board) { bd_game_drop(g); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!g->board) { bd_game_drop(g); return NULL; } 0 8917 8917
193 8917 g->ply = 0;
194 8917 g->key[0] = (E())->key(g->board);
195 8917 g->captured[0] = 0;
196 8917 g->outcome[0] = judge_start(g);
197 8917 return g;
198 }
199  
200 8159 static struct bd_game *bd_game_copy(const struct bd_game *src)
201 {
202 struct bd_game *g;
203 size_t slots;
204 8159 ▶ if (!src) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!src) return NULL; 0 8159 8159
205 8159 g = game_alloc(&src->variant);
206 8159 ▶ if (!g) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!g) return NULL; 0 8159 8159
207 8159 g->board = (E())->board_copy(src->board);
208 8159 ▶ if (!g->board) { bd_game_drop(g); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!g->board) { bd_game_drop(g); return NULL; } 0 8159 8159
209 8159 slots = (size_t) src->cap + 1;
210 8159 g->ply = src->ply;
211 8159 memcpy(g->key, src->key, slots * sizeof(unsigned long long));
212 8159 memcpy(g->outcome, src->outcome, slots * sizeof(int));
213 8159 memcpy(g->captured, src->captured, slots);
214 8159 memcpy(g->undo, src->undo, slots * sizeof(struct bd_undo));
215 8159 return g;
216 }
217  
218 7 static int bd_games_live(void) { return GAMES_LIVE; }
219  
220 /* ---- reading a game --------------------------------------------------------------- */
221  
222 28841276 ▶static const struct bd_board *bd_game_board(const struct bd_game *g) { return g ? g->board : NULL; }
Branch: 1 branch
BranchTrueFalseTotal
static const struct bd_board *bd_game_board(const struct bd_game *g) { return g ? g->board : NULL; } 28841276 0 28841276
223 28059 ▶static int bd_game_ply(const struct bd_game *g) { return g ? g->ply : 0; }
Branch: 1 branch
BranchTrueFalseTotal
static int bd_game_ply(const struct bd_game *g) { return g ? g->ply : 0; } 28059 0 28059
224 6 ▶static int bd_game_cap(const struct bd_game *g) { return g ? g->cap : 0; }
Branch: 1 branch
BranchTrueFalseTotal
static int bd_game_cap(const struct bd_game *g) { return g ? g->cap : 0; } 6 0 6
225 25025253 ▶static int bd_game_outcome(const struct bd_game *g) { return g ? g->outcome[g->ply] : BD_ONGOING; }
Branch: 1 branch
BranchTrueFalseTotal
static int bd_game_outcome(const struct bd_game *g) { return g ? g->outcome[g->ply] : BD_ONGOING; } 25025253 0 25025253
226  
227 1808782 static void bd_game_variant(const struct bd_game *g, struct bd_variant *out)
228 {
229 1808782 ▶ if (g && out) *out = g->variant;
Branch: 2 branches
BranchTrueFalseTotal
if (g && out) *out = g->variant; 1808782 0 1808782
if (g && out) *out = g->variant; 1808782 0 1808782
230 1808782 }
231  
232 259813 static int bd_winner_of(int outcome)
233 {
234 259813 ▶ if (outcome == BD_BY_CAPTURE) return BD_ATTACKERS;
Branch: 1 branch
BranchTrueFalseTotal
if (outcome == BD_BY_CAPTURE) return BD_ATTACKERS; 112165 147648 259813
235 147648 ▶ if (outcome == BD_BY_CORNER || outcome == BD_BY_NO_PIECES) return BD_DEFENDERS;
Branch: 2 branches
BranchTrueFalseTotal
if (outcome == BD_BY_CORNER || outcome == BD_BY_NO_PIECES) return BD_DEFENDERS; 24425 123223 147648
if (outcome == BD_BY_CORNER || outcome == BD_BY_NO_PIECES) return BD_DEFENDERS; 55 24370 24425
236 24370 return -1;
237 }
238  
239 4188 static int bd_game_winner(const struct bd_game *g) { return bd_winner_of(bd_game_outcome(g)); }
240  
241 /* The key of the position after `ply` moves, or 0 for a ply the game has not
242 * reached. */
243 9 static unsigned long long bd_game_key_at(const struct bd_game *g, int ply)
244 {
245 9 ▶ if (!g || ply < 0 || ply > g->ply) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!g || ply < 0 || ply > g->ply) return 0; 9 0 9
if (!g || ply < 0 || ply > g->ply) return 0; 9 0 9
if (!g || ply < 0 || ply > g->ply) return 0; 0 9 9
246 9 return g->key[ply];
247 }
248  
249 /* The moves of the side to move, and NONE once the game is over: a finished
250 * game has no legal move, whatever the pieces could do. */
251 109119 static int bd_game_moves(const struct bd_game *g, int *out, int max)
252 {
253 109119 ▶ if (!g || g->outcome[g->ply] != BD_ONGOING) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!g || g->outcome[g->ply] != BD_ONGOING) return 0; 109119 0 109119
if (!g || g->outcome[g->ply] != BD_ONGOING) return 0; 252 108867 109119
254 108867 return (E())->gen_moves(g->board, &g->variant, out, max);
255 }
256  
257 /* ---- playing ----------------------------------------------------------------------
258 *
259 * game_do IS A RULES CALL, the first in this distribution that refuses. A
260 * move in a finished game is BD_PLAY_OVER; a move the side to move may not
261 * make is BD_PLAY_ILLEGAL; and in both cases the game is exactly as it was.
262 */
263 249030 static int bd_game_do(struct bd_game *g, int mv, int *flags_out)
264 {
265 int flags, at;
266 249030 ▶ if (flags_out) *flags_out = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (flags_out) *flags_out = 0; 249030 0 249030
267 249030 ▶ if (!g) return BD_PLAY_ILLEGAL;
Branch: 1 branch
BranchTrueFalseTotal
if (!g) return BD_PLAY_ILLEGAL; 0 249030 249030
268 249030 ▶ if (g->outcome[g->ply] != BD_ONGOING) return BD_PLAY_OVER;
Branch: 1 branch
BranchTrueFalseTotal
if (g->outcome[g->ply] != BD_ONGOING) return BD_PLAY_OVER; 25 249005 249030
269 249005 ▶ if (!(E())->is_legal(g->board, &g->variant, mv)) return BD_PLAY_ILLEGAL;
Branch: 1 branch
BranchTrueFalseTotal
if (!(E())->is_legal(g->board, &g->variant, mv)) return BD_PLAY_ILLEGAL; 6 248999 249005
270  
271 248999 at = g->ply + 1;
272 248999 flags = (E())->do_move(g->board, &g->variant, mv, &g->undo[at]);
273 248999 g->ply = at;
274 248999 g->key[at] = (E())->key(g->board);
275 248999 g->captured[at] = (flags & BD_DID_CAPTURE) ? 1 : 0;
276 248999 g->outcome[at] = judge_move(g, flags);
277  
278 248999 ▶ if (flags_out) *flags_out = flags;
Branch: 1 branch
BranchTrueFalseTotal
if (flags_out) *flags_out = flags; 248999 0 248999
279 248999 return BD_PLAY_OK;
280 }
281  
282 /* game_do with two questions left out, for a search: see the header. The
283 * outcome is judged in the same order with "no move" skipped, and a position
284 * that is both blocked and something else is a draw either way. */
285 24636250 static void bd_game_push(struct bd_game *g, int mv, int *flags_out)
286 {
287 int flags, at, outcome;
288 24636250 ▶ if (flags_out) *flags_out = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (flags_out) *flags_out = 0; 0 24636250 24636250
289 24636250 ▶ if (!g || g->ply >= g->cap) return;
Branch: 2 branches
BranchTrueFalseTotal
if (!g || g->ply >= g->cap) return; 24636250 0 24636250
if (!g || g->ply >= g->cap) return; 0 24636250 24636250
290  
291 24636250 at = g->ply + 1;
292 24636250 flags = (E())->do_move(g->board, &g->variant, mv, &g->undo[at]);
293 24636250 g->ply = at;
294 24636250 g->key[at] = (E())->key(g->board);
295 24636250 g->captured[at] = (flags & BD_DID_CAPTURE) ? 1 : 0;
296  
297 24636250 ▶ if (flags & BD_KING_HOME) outcome = BD_BY_CORNER;
Branch: 1 branch
BranchTrueFalseTotal
if (flags & BD_KING_HOME) outcome = BD_BY_CORNER; 120655 24515595 24636250
298 24515595 ▶ else if (flags & BD_KING_TAKEN) outcome = BD_BY_CAPTURE;
Branch: 1 branch
BranchTrueFalseTotal
else if (flags & BD_KING_TAKEN) outcome = BD_BY_CAPTURE; 111215 24404380 24515595
299 24404380 ▶ else if ((E())->count(g->board, BD_ATTACKER) == 0) outcome = BD_BY_NO_PIECES;
Branch: 1 branch
BranchTrueFalseTotal
else if ((E())->count(g->board, BD_ATTACKER) == 0) outcome = BD_BY_NO_PIECES; 0 24404380 24404380
300 24404380 ▶ else if (bd_repeats(g) >= g->variant.repeat) outcome = BD_DRAW_REPETITION;
Branch: 1 branch
BranchTrueFalseTotal
else if (bd_repeats(g) >= g->variant.repeat) outcome = BD_DRAW_REPETITION; 103 24404277 24404380
301 24404277 ▶ else if (g->ply >= g->cap) outcome = BD_DRAW_PLY_CAP;
Branch: 1 branch
BranchTrueFalseTotal
else if (g->ply >= g->cap) outcome = BD_DRAW_PLY_CAP; 23663 24380614 24404277
302 24380614 else outcome = BD_ONGOING;
303 24636250 g->outcome[at] = outcome;
304  
305 24636250 ▶ if (flags_out) *flags_out = flags;
Branch: 1 branch
BranchTrueFalseTotal
if (flags_out) *flags_out = flags; 0 24636250 24636250
306 }
307  
308 /* Takes the last move back. Everything kept for that ply is simply left
309 * behind: the index steps down and the entries above it are dead until a new
310 * move writes over them. Returns 0 when there is no move to take back. */
311 24659891 static int bd_game_undo(struct bd_game *g)
312 {
313 24659891 ▶ if (!g || g->ply == 0) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!g || g->ply == 0) return 0; 24659891 0 24659891
if (!g || g->ply == 0) return 0; 249 24659642 24659891
314 24659642 (E())->undo_move(g->board, &g->undo[g->ply]);
315 24659642 g->ply--;
316 24659642 return 1;
317 }
318  
319 /* ---- installed into the table by bd_engine.c ------------------------------------- */
320  
321 void bd_rules_install(struct bd_abi *t);
322  
323 59 void bd_rules_install(struct bd_abi *t)
324 {
325 59 t->game_new = bd_game_new;
326 59 t->game_copy = bd_game_copy;
327 59 t->game_drop = bd_game_drop;
328 59 t->games_live = bd_games_live;
329  
330 59 t->game_board = bd_game_board;
331 59 t->game_variant = bd_game_variant;
332 59 t->game_ply = bd_game_ply;
333 59 t->game_cap = bd_game_cap;
334 59 t->game_outcome = bd_game_outcome;
335 59 t->game_winner = bd_game_winner;
336 59 t->winner_of = bd_winner_of;
337 59 t->game_key_at = bd_game_key_at;
338 59 t->game_moves = bd_game_moves;
339 59 t->repeats = bd_repeats;
340  
341 59 t->game_do = bd_game_do;
342 59 t->game_undo = bd_game_undo;
343 59 t->game_push = bd_game_push;
344 59 }
« Brandubh.xs ↑ Summary bd_search.c »