ru_moves.c

filter: Statementstmt 0.0% 0 / 191 Branchbran 0.0% 0 / 172 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 363 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« ru_engine.c ↑ Summary ru_search.c »
1 /* ru_moves.c - what a roll allows.
2 *
3 * PERL-FREE, like ru_engine.c, and it reaches the board only through the
4 * table: this file does not know how a position is stored.
5 *
6 * THIS FILE'S SCOPE. The rule set as a struct, the moves a roll allows the
7 * side to move, a count of the positions a rule set has, and then a move MADE:
8 * apply and its undo, the forfeit, whose turn it is afterwards, and how a game
9 * ends.
10 */
11  
12 #include <stddef.h>
13 #include "ru_abi.h"
14  
15 static const struct ru_abi *RU = NULL;
16  
17 /* ---- the rule set ------------------------------------------------------------- */
18  
19 0 static int ru_rules_named(int name, struct ru_rules *r)
20 {
21 int i;
22 0 ▶ if (!r) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return 0; 0 0 0
23 0 ▶ for (i = 0; i < 4; i++) r->reserved[i] = 0;
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 4; i++) r->reserved[i] = 0; 0 0 0
24 0 ▶ if (name == RU_RULES_FINKEL) {
Branch: 1 branch
BranchTrueFalseTotal
if (name == RU_RULES_FINKEL) { 0 0 0
25 0 r->route = RU_ROUTE_SHORT;
26 0 r->dice = 4;
27 0 r->zero_rolls = 0;
28 0 r->safe_rosettes = 1;
29 0 r->pieces = 7;
30 0 return 1;
31 }
32 0 ▶ if (name == RU_RULES_MASTERS) {
Branch: 1 branch
BranchTrueFalseTotal
if (name == RU_RULES_MASTERS) { 0 0 0
33 0 r->route = RU_ROUTE_LONG;
34 0 r->dice = 3;
35 0 r->zero_rolls = 4;
36 0 r->safe_rosettes = 0;
37 0 r->pieces = 7;
38 0 return 1;
39 }
40 0 return 0;
41 }
42  
43 0 static int ru_rules_ok(const struct ru_rules *r)
44 {
45 0 ▶ if (!r) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return 0; 0 0 0
46 0 ▶ if (r->route != RU_ROUTE_SHORT && r->route != RU_ROUTE_LONG) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (r->route != RU_ROUTE_SHORT && r->route != RU_ROUTE_LONG) return 0; 0 0 0
if (r->route != RU_ROUTE_SHORT && r->route != RU_ROUTE_LONG) return 0; 0 0 0
47 0 ▶ if (r->dice != 3 && r->dice != 4) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (r->dice != 3 && r->dice != 4) return 0; 0 0 0
if (r->dice != 3 && r->dice != 4) return 0; 0 0 0
48 0 ▶ if (r->zero_rolls != 0 && r->zero_rolls != 4) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (r->zero_rolls != 0 && r->zero_rolls != 4) return 0; 0 0 0
if (r->zero_rolls != 0 && r->zero_rolls != 4) return 0; 0 0 0
49 0 ▶ if (r->safe_rosettes != 0 && r->safe_rosettes != 1) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (r->safe_rosettes != 0 && r->safe_rosettes != 1) return 0; 0 0 0
if (r->safe_rosettes != 0 && r->safe_rosettes != 1) return 0; 0 0 0
50 0 ▶ if (r->pieces < 1 || r->pieces > RU_PIECES_MAX) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (r->pieces < 1 || r->pieces > RU_PIECES_MAX) return 0; 0 0 0
if (r->pieces < 1 || r->pieces > RU_PIECES_MAX) return 0; 0 0 0
51 0 return 1;
52 }
53  
54 /* ---- the generator --------------------------------------------------------------
55 *
56 * The candidates are the hand, when it holds a piece, and then the side's
57 * pieces in ascending order of STEP. That order is part of the contract.
58 *
59 * For each, the landing step is the step it stands on plus the roll, and:
60 *
61 * past home no move: a piece leaves on an exact roll
62 * home a move
63 * a cell holding the side's own no move
64 * an enemy on a rosette that is safe no move
65 * an enemy anywhere else a move, and a capture
66 * an empty cell a move
67 *
68 * NOTHING BETWEEN THE TWO STEPS IS LOOKED AT. A piece passes over any piece of
69 * either side, an enemy on a safe rosette included: the rosette refuses a
70 * landing, it does not close the route.
71 *
72 * THE LANDING CELL IS ASKED OF THE MOVER'S ROUTE, and what stands on it is
73 * asked of the CELL. On the long route one cell is two different steps, one
74 * for each side, so "is there an enemy on my step 12" is not a question about
75 * the enemy's step 12.
76 */
77  
78 0 static int consider(const struct ru_board *b, const struct ru_rules *r, int side,
79 int from_step, int roll, struct ru_move *m)
80 {
81 0 int len = (RU->route_len)(r->route);
82 0 int to = from_step + roll;
83 int cell, standing;
84  
85 0 ▶ if (to > len + 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (to > len + 1) return 0; 0 0 0
86  
87 0 m->from_step = from_step;
88 0 m->to_step = to;
89 0 ▶ m->from_cell = from_step == 0 ? -1 : (RU->route_cell)(r->route, side, from_step);
Branch: 1 branch
BranchTrueFalseTotal
m->from_cell = from_step == 0 ? -1 : (RU->route_cell)(r->route, side, from_step); 0 0 0
90 0 m->to_cell = -1;
91 0 m->captures = 0;
92 0 m->rosette = 0;
93 0 m->home = 0;
94 0 m->reserved[0] = m->reserved[1] = 0;
95  
96 0 ▶ if (to == len + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (to == len + 1) { 0 0 0
97 0 m->home = 1;
98 0 return 1;
99 }
100  
101 0 cell = (RU->route_cell)(r->route, side, to);
102 0 standing = (RU->at)(b, cell);
103 0 ▶ if (standing == RU_PIECE_OF(side)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (standing == RU_PIECE_OF(side)) return 0; 0 0 0
104 0 ▶ if (standing == RU_PIECE_OF(RU_OTHER(side))) {
Branch: 2 branches
BranchTrueFalseTotal
if (standing == RU_PIECE_OF(RU_OTHER(side))) { 0 0 0
if (standing == RU_PIECE_OF(RU_OTHER(side))) { 0 0 0
105 0 ▶ if (r->safe_rosettes && (RU->is_rosette)(cell)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (r->safe_rosettes && (RU->is_rosette)(cell)) return 0; 0 0 0
if (r->safe_rosettes && (RU->is_rosette)(cell)) return 0; 0 0 0
106 0 m->captures = 1;
107 }
108 0 m->to_cell = cell;
109 0 m->rosette = (RU->is_rosette)(cell) ? 1 : 0;
110 0 return 1;
111 }
112  
113 0 static int ru_moves(const struct ru_board *b, const struct ru_rules *rules, int roll,
114 struct ru_move *out, int max)
115 {
116 struct ru_rules standard;
117 struct ru_move m;
118 0 int side, len, step, n = 0;
119  
120 0 ▶ if (!b) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) return -1; 0 0 0
121 0 ▶ if (roll < 0 || roll > RU_ROLL_MAX) return -1;
Branch: 2 branches
BranchTrueFalseTotal
if (roll < 0 || roll > RU_ROLL_MAX) return -1; 0 0 0
if (roll < 0 || roll > RU_ROLL_MAX) return -1; 0 0 0
122 0 ▶ if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; }
Branch: 1 branch
BranchTrueFalseTotal
if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; } 0 0 0
123 0 ▶ if (!ru_rules_ok(rules)) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!ru_rules_ok(rules)) return -1; 0 0 0
124 0 ▶ if (roll == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (roll == 0) return 0; 0 0 0
125  
126 0 side = (RU->side)(b);
127 0 len = (RU->route_len)(rules->route);
128  
129 0 ▶ if ((RU->hand)(b, side) > 0 && consider(b, rules, side, 0, roll, &m)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((RU->hand)(b, side) > 0 && consider(b, rules, side, 0, roll, &m)) { 0 0 0
if ((RU->hand)(b, side) > 0 && consider(b, rules, side, 0, roll, &m)) { 0 0 0
130 0 ▶ if (out && n < max) out[n] = m;
Branch: 2 branches
BranchTrueFalseTotal
if (out && n < max) out[n] = m; 0 0 0
if (out && n < max) out[n] = m; 0 0 0
131 0 n++;
132 }
133 0 ▶ for (step = 1; step <= len; step++) {
Branch: 1 branch
BranchTrueFalseTotal
for (step = 1; step <= len; step++) { 0 0 0
134 0 int cell = (RU->route_cell)(rules->route, side, step);
135 0 ▶ if ((RU->at)(b, cell) != RU_PIECE_OF(side)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if ((RU->at)(b, cell) != RU_PIECE_OF(side)) continue; 0 0 0
136 0 ▶ if (!consider(b, rules, side, step, roll, &m)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!consider(b, rules, side, step, roll, &m)) continue; 0 0 0
137 0 ▶ if (out && n < max) out[n] = m;
Branch: 2 branches
BranchTrueFalseTotal
if (out && n < max) out[n] = m; 0 0 0
if (out && n < max) out[n] = m; 0 0 0
138 0 n++;
139 }
140 0 return n;
141 }
142  
143 /* ---- how many positions a rule set has -------------------------------------------
144 *
145 * Every way of standing each side's pieces on cells of ITS OWN route, no two
146 * on one cell, with what is left split between hand and home, for each side to
147 * move. It is a count of positions that are consistent, not of positions play
148 * can reach, and a finished game is counted.
149 *
150 * Walked cell by cell and not computed, so that it can be held against a
151 * formula that was.
152 */
153  
154 0 static unsigned long long count_from(const struct ru_rules *r, int cell, int light, int dark)
155 {
156 unsigned long long total;
157 0 ▶ if (cell == RU_CELLS)
Branch: 1 branch
BranchTrueFalseTotal
if (cell == RU_CELLS) 0 0 0
158 0 return (unsigned long long) (r->pieces - light + 1)
159 0 * (unsigned long long) (r->pieces - dark + 1);
160 0 total = count_from(r, cell + 1, light, dark);
161 0 ▶ if (light < r->pieces && (RU->route_step)(r->route, RU_SIDE_LIGHT, cell) > 0)
Branch: 2 branches
BranchTrueFalseTotal
if (light < r->pieces && (RU->route_step)(r->route, RU_SIDE_LIGHT, cell) > 0) 0 0 0
if (light < r->pieces && (RU->route_step)(r->route, RU_SIDE_LIGHT, cell) > 0) 0 0 0
162 0 total += count_from(r, cell + 1, light + 1, dark);
163 0 ▶ if (dark < r->pieces && (RU->route_step)(r->route, RU_SIDE_DARK, cell) > 0)
Branch: 2 branches
BranchTrueFalseTotal
if (dark < r->pieces && (RU->route_step)(r->route, RU_SIDE_DARK, cell) > 0) 0 0 0
if (dark < r->pieces && (RU->route_step)(r->route, RU_SIDE_DARK, cell) > 0) 0 0 0
164 0 total += count_from(r, cell + 1, light, dark + 1);
165 0 return total;
166 }
167  
168 0 static unsigned long long ru_count_positions(const struct ru_rules *rules)
169 {
170 struct ru_rules standard;
171 0 ▶ if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; }
Branch: 1 branch
BranchTrueFalseTotal
if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; } 0 0 0
172 0 ▶ if (!ru_rules_ok(rules)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!ru_rules_ok(rules)) return 0; 0 0 0
173 0 return 2ULL * count_from(rules, 0, 0, 0);
174 }
175  
176 /* ---- a move made ------------------------------------------------------------------
177 *
178 * WHOSE TURN IT IS AFTERWARDS is decided here and nowhere else:
179 *
180 * a move to an ordinary cell the other side
181 * a move to a rosette the SAME side
182 * a capture on an ordinary cell the other side
183 * a capture on a rosette the same side
184 * a move home the other side: home is not a cell
185 * a forfeit the other side, always
186 *
187 * A CAPTURED PIECE GOES TO ITS OWNER'S HAND. Not to its owner's home, not to
188 * the mover's hand, and not back onto the board at its first step.
189 */
190  
191 0 static int ru_apply(struct ru_board *b, const struct ru_rules *rules,
192 const struct ru_move *m, struct ru_undo *u)
193 {
194 struct ru_undo local;
195 int side, enemy, i;
196  
197 (void) rules;
198 0 ▶ if (!u) u = &local;
Branch: 1 branch
BranchTrueFalseTotal
if (!u) u = &local; 0 0 0
199 0 u->kind = RU_UNDO_NONE;
200 0 ▶ for (i = 0; i < 4; i++) u->reserved[i] = 0;
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 4; i++) u->reserved[i] = 0; 0 0 0
201 0 ▶ if (!b || !m) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!b || !m) return 0; 0 0 0
if (!b || !m) return 0; 0 0 0
202  
203 0 side = (RU->side)(b);
204 0 enemy = RU_OTHER(side);
205  
206 0 ▶ if (m->from_step == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (m->from_step == 0) { 0 0 0
207 0 ▶ if ((RU->hand)(b, side) < 1) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ((RU->hand)(b, side) < 1) return 0; 0 0 0
208 }
209 0 ▶ else if ((RU->at)(b, m->from_cell) != RU_PIECE_OF(side)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
else if ((RU->at)(b, m->from_cell) != RU_PIECE_OF(side)) return 0; 0 0 0
210  
211 0 u->kind = RU_UNDO_MOVE;
212 0 u->side = side;
213 0 u->ply = (RU->ply)(b);
214 0 u->from_step = m->from_step;
215 0 ▶ u->from_cell = m->from_step == 0 ? -1 : m->from_cell;
Branch: 1 branch
BranchTrueFalseTotal
u->from_cell = m->from_step == 0 ? -1 : m->from_cell; 0 0 0
216 0 ▶ u->to_cell = m->home ? -1 : m->to_cell;
Branch: 1 branch
BranchTrueFalseTotal
u->to_cell = m->home ? -1 : m->to_cell; 0 0 0
217 0 u->captured = 0;
218  
219 0 ▶ if (m->from_step == 0) (RU->set_hand)(b, side, (RU->hand)(b, side) - 1);
Branch: 1 branch
BranchTrueFalseTotal
if (m->from_step == 0) (RU->set_hand)(b, side, (RU->hand)(b, side) - 1); 0 0 0
220 0 else (RU->lift)(b, m->from_cell);
221  
222 0 ▶ if (m->home) {
Branch: 1 branch
BranchTrueFalseTotal
if (m->home) { 0 0 0
223 0 (RU->set_home)(b, side, (RU->home)(b, side) + 1);
224 }
225 else {
226 0 ▶ if ((RU->at)(b, m->to_cell) == RU_PIECE_OF(enemy)) {
Branch: 1 branch
BranchTrueFalseTotal
if ((RU->at)(b, m->to_cell) == RU_PIECE_OF(enemy)) { 0 0 0
227 0 u->captured = 1;
228 0 (RU->set_hand)(b, enemy, (RU->hand)(b, enemy) + 1);
229 }
230 0 (RU->put)(b, m->to_cell, RU_PIECE_OF(side));
231 }
232  
233 0 ▶ if (m->home || !(RU->is_rosette)(m->to_cell)) (RU->set_side)(b, enemy);
Branch: 2 branches
BranchTrueFalseTotal
if (m->home || !(RU->is_rosette)(m->to_cell)) (RU->set_side)(b, enemy); 0 0 0
if (m->home || !(RU->is_rosette)(m->to_cell)) (RU->set_side)(b, enemy); 0 0 0
234 0 (RU->set_ply)(b, u->ply + 1);
235 0 return 1;
236 }
237  
238 0 static void ru_forfeit(struct ru_board *b, struct ru_undo *u)
239 {
240 struct ru_undo local;
241 int i;
242 0 ▶ if (!u) u = &local;
Branch: 1 branch
BranchTrueFalseTotal
if (!u) u = &local; 0 0 0
243 0 u->kind = RU_UNDO_NONE;
244 0 ▶ for (i = 0; i < 4; i++) u->reserved[i] = 0;
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 4; i++) u->reserved[i] = 0; 0 0 0
245 0 ▶ if (!b) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) return; 0 0 0
246 0 u->kind = RU_UNDO_FORFEIT;
247 0 u->side = (RU->side)(b);
248 0 u->ply = (RU->ply)(b);
249 0 u->from_step = 0;
250 0 u->from_cell = u->to_cell = -1;
251 0 u->captured = 0;
252 0 (RU->set_side)(b, RU_OTHER(u->side));
253 0 (RU->set_ply)(b, u->ply + 1);
254 }
255  
256 0 static void ru_unapply(struct ru_board *b, const struct ru_undo *u)
257 {
258 int side, enemy;
259 0 ▶ if (!b || !u || u->kind == RU_UNDO_NONE) return;
Branch: 3 branches
BranchTrueFalseTotal
if (!b || !u || u->kind == RU_UNDO_NONE) return; 0 0 0
if (!b || !u || u->kind == RU_UNDO_NONE) return; 0 0 0
if (!b || !u || u->kind == RU_UNDO_NONE) return; 0 0 0
260 0 side = u->side;
261 0 enemy = RU_OTHER(side);
262  
263 0 ▶ if (u->kind == RU_UNDO_MOVE) {
Branch: 1 branch
BranchTrueFalseTotal
if (u->kind == RU_UNDO_MOVE) { 0 0 0
264 0 ▶ if (u->to_cell < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (u->to_cell < 0) { 0 0 0
265 0 (RU->set_home)(b, side, (RU->home)(b, side) - 1);
266 }
267 0 ▶ else if (u->captured) {
Branch: 1 branch
BranchTrueFalseTotal
else if (u->captured) { 0 0 0
268 0 (RU->put)(b, u->to_cell, RU_PIECE_OF(enemy));
269 0 (RU->set_hand)(b, enemy, (RU->hand)(b, enemy) - 1);
270 }
271 else {
272 0 (RU->lift)(b, u->to_cell);
273 }
274 0 ▶ if (u->from_step == 0) (RU->set_hand)(b, side, (RU->hand)(b, side) + 1);
Branch: 1 branch
BranchTrueFalseTotal
if (u->from_step == 0) (RU->set_hand)(b, side, (RU->hand)(b, side) + 1); 0 0 0
275 0 else (RU->put)(b, u->from_cell, RU_PIECE_OF(side));
276 }
277 0 (RU->set_side)(b, side);
278 0 (RU->set_ply)(b, u->ply);
279 }
280  
281 /* ---- how a game stands --------------------------------------------------------------
282 *
283 * Asked in this order, because the move that brings the last piece home can
284 * also be the ply that reaches the cap: home first.
285 */
286  
287 0 static int ru_winner(const struct ru_board *b, const struct ru_rules *rules)
288 {
289 struct ru_rules standard;
290 0 ▶ if (!b) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) return -1; 0 0 0
291 0 ▶ if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; }
Branch: 1 branch
BranchTrueFalseTotal
if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; } 0 0 0
292 0 ▶ if ((RU->home)(b, RU_SIDE_LIGHT) >= rules->pieces) return RU_SIDE_LIGHT;
Branch: 1 branch
BranchTrueFalseTotal
if ((RU->home)(b, RU_SIDE_LIGHT) >= rules->pieces) return RU_SIDE_LIGHT; 0 0 0
293 0 ▶ if ((RU->home)(b, RU_SIDE_DARK) >= rules->pieces) return RU_SIDE_DARK;
Branch: 1 branch
BranchTrueFalseTotal
if ((RU->home)(b, RU_SIDE_DARK) >= rules->pieces) return RU_SIDE_DARK; 0 0 0
294 0 return -1;
295 }
296  
297 0 static int ru_how(const struct ru_board *b, const struct ru_rules *rules)
298 {
299 0 ▶ if (!b) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) return 0; 0 0 0
300 0 ▶ if (ru_winner(b, rules) >= 0) return RU_BY_HOME;
Branch: 1 branch
BranchTrueFalseTotal
if (ru_winner(b, rules) >= 0) return RU_BY_HOME; 0 0 0
301 0 ▶ if ((RU->ply)(b) >= RU_PLY_CAP) return RU_BY_PLY_CAP;
Branch: 1 branch
BranchTrueFalseTotal
if ((RU->ply)(b) >= RU_PLY_CAP) return RU_BY_PLY_CAP; 0 0 0
302 0 return 0;
303 }
304  
305 0 static int ru_status(const struct ru_board *b, const struct ru_rules *rules)
306 {
307 0 int how = ru_how(b, rules);
308 0 ▶ if (how == RU_BY_HOME) return RU_WON;
Branch: 1 branch
BranchTrueFalseTotal
if (how == RU_BY_HOME) return RU_WON; 0 0 0
309 0 ▶ if (how == RU_BY_PLY_CAP) return RU_DRAWN;
Branch: 1 branch
BranchTrueFalseTotal
if (how == RU_BY_PLY_CAP) return RU_DRAWN; 0 0 0
310 0 return RU_ONGOING;
311 }
312  
313 0 static int ru_ply_cap(void) { return RU_PLY_CAP; }
314  
315 /* ---- the walk ------------------------------------------------------------------------ */
316  
317 0 static unsigned long long ru_walk(struct ru_board *b, const struct ru_rules *rules, int depth)
318 {
319 struct ru_rules standard;
320 struct ru_move m[RU_MOVES_MAX];
321 struct ru_undo u;
322 0 unsigned long long total = 0;
323 int rolls, i, k, n, roll, weight, denominator;
324  
325 0 ▶ if (!b) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!b) return 0; 0 0 0
326 0 ▶ if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; }
Branch: 1 branch
BranchTrueFalseTotal
if (!rules) { ru_rules_named(RU_RULES_FINKEL, &standard); rules = &standard; } 0 0 0
327 0 ▶ if (!ru_rules_ok(rules)) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!ru_rules_ok(rules)) return 0; 0 0 0
328 0 ▶ if (depth <= 0 || ru_status(b, rules) != RU_ONGOING) return 1;
Branch: 2 branches
BranchTrueFalseTotal
if (depth <= 0 || ru_status(b, rules) != RU_ONGOING) return 1; 0 0 0
if (depth <= 0 || ru_status(b, rules) != RU_ONGOING) return 1; 0 0 0
329  
330 0 rolls = (RU->chance_count)(rules->dice, rules->zero_rolls);
331 0 ▶ for (i = 0; i < rolls; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < rolls; i++) { 0 0 0
332 0 (RU->chance)(rules->dice, rules->zero_rolls, i, &roll, &weight, &denominator);
333 0 n = ru_moves(b, rules, roll, m, RU_MOVES_MAX);
334 0 ▶ if (n <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (n <= 0) { 0 0 0
335 0 ru_forfeit(b, &u);
336 0 total += ru_walk(b, rules, depth - 1);
337 0 ru_unapply(b, &u);
338 0 continue;
339 }
340 0 ▶ for (k = 0; k < n; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < n; k++) { 0 0 0
341 0 ru_apply(b, rules, &m[k], &u);
342 0 total += ru_walk(b, rules, depth - 1);
343 0 ru_unapply(b, &u);
344 }
345 }
346 0 return total;
347 }
348  
349 /* ---- the table ------------------------------------------------------------------- */
350  
351 0 void ru_moves_install(struct ru_abi *t)
352 {
353 0 RU = t;
354 0 t->rules_named = ru_rules_named;
355 0 t->rules_ok = ru_rules_ok;
356 0 t->moves = ru_moves;
357 0 t->count_positions = ru_count_positions;
358 0 t->apply = ru_apply;
359 0 t->forfeit = ru_forfeit;
360 0 t->unapply = ru_unapply;
361 0 t->status = ru_status;
362 0 t->how = ru_how;
363 0 t->winner = ru_winner;
364 0 t->ply_cap = ru_ply_cap;
365 0 t->walk = ru_walk;
366 0 }
« ru_engine.c ↑ Summary ru_search.c »