Moggy assess: Do not advise against capturing laddered groups
[pachi/json.git] / playout / moggy.c
blob2bcab64af4b5dda15a4b24859ec8548006b9638d
1 #include <assert.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #define DEBUG
7 #include "board.h"
8 #include "debug.h"
9 #include "playout.h"
10 #include "playout/moggy.h"
11 #include "random.h"
13 #define PLDEBUGL(n) DEBUGL_(p->debug_level, n)
16 struct moggy_policy {
17 bool ladders, ladderassess, borderladders;
18 int lcapturerate, capturerate, patternrate;
19 int selfatarirate;
22 #define MQL 64
23 struct move_queue {
24 int moves;
25 coord_t move[MQL];
28 static void
29 mq_nodup(struct move_queue *q)
31 if ((q->moves > 1 && q->move[q->moves - 2] == q->move[q->moves - 1])
32 || (q->moves > 2 && q->move[q->moves - 3] == q->move[q->moves - 1])
33 || (q->moves > 3 && q->move[q->moves - 4] == q->move[q->moves - 1]))
34 q->moves--;
38 /* Pattern encoding:
39 * X: black; O: white; .: empty; #: edge
40 * x: !black; o: !white; ?: any
42 * extra X: pattern valid only for one side;
43 * middle point ignored. */
45 static char moggy_patterns_src[][11] = {
46 /* hane pattern - enclosing hane */
47 "XOX"
48 "..."
49 "???",
50 /* hane pattern - non-cutting hane */
51 "XO."
52 "..."
53 "?.?",
54 /* hane pattern - magari */
55 "XO?"
56 "X.."
57 "x.?",
58 /* hane pattern - thin hane */
59 "XOO"
60 "..."
61 "?.?" "X",
62 /* generic pattern - katatsuke or diagonal attachment; similar to magari */
63 ".O."
64 "X.."
65 "...",
66 /* cut1 pattern (kiri) - unprotected cut */
67 "XO?"
68 "O.o"
69 "?o?",
70 /* cut1 pattern (kiri) - peeped cut */
71 "XO?"
72 "O.X"
73 "???",
74 /* cut2 pattern (de) */
75 "?X?"
76 "O.O"
77 "ooo",
78 /* cut keima (not in Mogo) */
79 "OX?"
80 "o.O"
81 "o??",
82 /* side pattern - chase */
83 "X.?"
84 "O.?"
85 "##?",
86 /* side pattern - weirdness (SUSPICIOUS) */
87 "?X?"
88 "X.O"
89 "###",
90 /* side pattern - sagari (SUSPICIOUS) */
91 "?XO"
92 "x.x" /* Mogo has "x.?" */
93 "###" /* Mogo has "X" */,
94 /* side pattern - weirdcut (SUSPICIOUS) */
95 #if 0
96 "?OX"
97 "?.O"
98 "?##" "X",
99 #endif
100 /* side pattern - cut (SUSPICIOUS) */
101 "?OX"
102 "X.O"
103 "###" /* Mogo has "X" */,
105 #define moggy_patterns_src_n sizeof(moggy_patterns_src) / sizeof(moggy_patterns_src[0])
107 /* Hashtable: 2*8 bits (ignore middle point, 2 bits per intersection) */
108 /* Value: 0: no pattern, 1: black pattern, 2: white pattern, 3: both patterns */
109 static char moggy_patterns[65536];
111 static void
112 _record_pattern(char *table, char *str, int pat, int fixed_color)
114 /* Original color assignment */
115 table[pat] = fixed_color ? fixed_color : 3;
116 //fprintf(stderr, "[%s] %04x %d\n", str, pat, fixed_color);
118 /* Reverse color assignment - achieved by swapping odd and even bits */
119 pat = ((pat >> 1) & 0x5555) | ((pat & 0x5555) << 1);
120 table[pat] = fixed_color ? 2 - (fixed_color == 2) : 3;
121 //fprintf(stderr, "[%s] %04x %d\n", str, pat, fixed_color);
124 static int
125 _pat_vmirror(int pat)
127 /* V mirror pattern; reverse order of 3-2-3 chunks */
128 return ((pat & 0xfc00) >> 10) | (pat & 0x03c0) | ((pat & 0x003f) << 10);
131 static int
132 _pat_hmirror(int pat)
134 /* H mirror pattern; reverse order of 2-bit values within the chunks */
135 #define rev3(p) ((p >> 4) | (p & 0xc) | ((p & 0x3) << 4))
136 #define rev2(p) ((p >> 2) | ((p & 0x3) << 2))
137 return (rev3((pat & 0xfc00) >> 10) << 10)
138 | (rev2((pat & 0x03c0) >> 6) << 6)
139 | rev3((pat & 0x003f));
140 #undef rev3
141 #undef rev2
144 static int
145 _pat_90rot(int pat)
147 /* Rotate by 90 degrees:
148 * 5 6 7 7 4 2
149 * 3 4 -> 6 1
150 * 0 1 2 5 3 0 */
151 /* I'm too lazy to optimize this :) */
152 int vals[8];
153 for (int i = 0; i < 8; i++)
154 vals[i] = (pat >> (i * 2)) & 0x3;
155 int vals2[8];
156 vals2[0] = vals[5]; vals2[1] = vals[3]; vals2[2] = vals[0];
157 vals2[3] = vals[6]; vals2[4] = vals[1];
158 vals2[5] = vals[7]; vals2[6] = vals[4]; vals2[7] = vals[2];
159 int p2 = 0;
160 for (int i = 0; i < 8; i++)
161 p2 |= vals2[i] << (i * 2);
162 return p2;
165 static void
166 _gen_pattern(char *table, int pat, char *src, int srclen, int fixed_color)
168 for (; srclen > 0; src++, srclen--) {
169 if (srclen == 5)
170 continue;
171 int patofs = (srclen > 5 ? srclen - 1 : srclen) - 1;
172 switch (*src) {
173 case '?':
174 *src = '.'; _gen_pattern(table, pat, src, srclen, fixed_color);
175 *src = 'X'; _gen_pattern(table, pat, src, srclen, fixed_color);
176 *src = 'O'; _gen_pattern(table, pat, src, srclen, fixed_color);
177 *src = '#'; _gen_pattern(table, pat, src, srclen, fixed_color);
178 *src = '?'; // for future recursions
179 return;
180 case 'x':
181 *src = '.'; _gen_pattern(table, pat, src, srclen, fixed_color);
182 *src = 'O'; _gen_pattern(table, pat, src, srclen, fixed_color);
183 *src = '#'; _gen_pattern(table, pat, src, srclen, fixed_color);
184 *src = 'x'; // for future recursions
185 return;
186 case 'o':
187 *src = '.'; _gen_pattern(table, pat, src, srclen, fixed_color);
188 *src = 'X'; _gen_pattern(table, pat, src, srclen, fixed_color);
189 *src = '#'; _gen_pattern(table, pat, src, srclen, fixed_color);
190 *src = 'o'; // for future recursions
191 return;
192 case '.': /* 0 */ break;
193 case 'X': pat |= S_BLACK << (patofs * 2); break;
194 case 'O': pat |= S_WHITE << (patofs * 2); break;
195 case '#': pat |= S_OFFBOARD << (patofs * 2); break;
199 /* Original pattern, all transpositions and rotations */
200 _record_pattern(table, src - 9, pat, fixed_color);
201 _record_pattern(table, src - 9, _pat_vmirror(pat), fixed_color);
202 _record_pattern(table, src - 9, _pat_hmirror(pat), fixed_color);
203 _record_pattern(table, src - 9, _pat_vmirror(_pat_hmirror(pat)), fixed_color);
204 _record_pattern(table, src - 9, _pat_90rot(pat), fixed_color);
205 _record_pattern(table, src - 9, _pat_90rot(_pat_vmirror(pat)), fixed_color);
206 _record_pattern(table, src - 9, _pat_90rot(_pat_hmirror(pat)), fixed_color);
207 _record_pattern(table, src - 9, _pat_90rot(_pat_vmirror(_pat_hmirror(pat))), fixed_color);
210 static void __attribute__((constructor))
211 _init_patterns(void)
213 for (int i = 0; i < moggy_patterns_src_n; i++) {
214 int fixed_color = 0;
215 switch (moggy_patterns_src[i][9]) {
216 case 'X': fixed_color = S_BLACK; break;
217 case 'O': fixed_color = S_WHITE; break;
219 //fprintf(stderr, "** %s **\n", moggy_patterns_src[i]);
220 _gen_pattern(moggy_patterns, 0, moggy_patterns_src[i], 9, fixed_color);
225 /* Check if we match any pattern centered on given move. */
226 static bool
227 test_pattern_here(struct playout_policy *p, char *hashtable,
228 struct board *b, struct move *m)
230 int pat = 0;
231 int x = coord_x(m->coord, b), y = coord_y(m->coord, b);
232 pat |= (board_atxy(b, x - 1, y - 1) << 14)
233 | (board_atxy(b, x, y - 1) << 12)
234 | (board_atxy(b, x + 1, y - 1) << 10);
235 pat |= (board_atxy(b, x - 1, y) << 8)
236 | (board_atxy(b, x + 1, y) << 6);
237 pat |= (board_atxy(b, x - 1, y + 1) << 4)
238 | (board_atxy(b, x, y + 1) << 2)
239 | (board_atxy(b, x + 1, y + 1));
240 //fprintf(stderr, "(%d,%d) hashtable[%04x] = %d\n", x, y, pat, hashtable[pat]);
241 return (hashtable[pat] & m->color) && !is_selfatari(b, m->color, m->coord);
244 static void
245 apply_pattern_here(struct playout_policy *p, char *hashtable,
246 struct board *b, struct move *m, struct move_queue *q)
248 if (test_pattern_here(p, hashtable, b, m))
249 q->move[q->moves++] = m->coord;
252 /* Check if we match any pattern around given move (with the other color to play). */
253 static coord_t
254 apply_pattern(struct playout_policy *p, struct board *b, struct move *m)
256 //struct moggy_policy *pp = p->data;
257 struct move_queue q;
258 q.moves = 0;
260 /* Suicides do not make any patterns and confuse us. */
261 if (board_at(b, m->coord) == S_NONE || board_at(b, m->coord) == S_OFFBOARD)
262 return pass;
264 foreach_neighbor(b, m->coord, {
265 struct move m2; m2.coord = c; m2.color = stone_other(m->color);
266 if (board_at(b, c) == S_NONE)
267 apply_pattern_here(p, moggy_patterns, b, &m2, &q);
269 foreach_diag_neighbor(b, m->coord) {
270 struct move m2; m2.coord = c; m2.color = stone_other(m->color);
271 if (board_at(b, c) == S_NONE)
272 apply_pattern_here(p, moggy_patterns, b, &m2, &q);
273 } foreach_diag_neighbor_end;
275 if (PLDEBUGL(5)) {
276 fprintf(stderr, "Pattern candidate moves: ");
277 for (int i = 0; i < q.moves; i++) {
278 fprintf(stderr, "%s ", coord2sstr(q.move[i], b));
280 fprintf(stderr, "\n");
283 int i = fast_random(q.moves);
284 return q.moves ? q.move[i] : pass;
289 /* Is this ladder breaker friendly for the one who catches ladder. */
290 static bool
291 ladder_catcher(struct board *b, int x, int y, enum stone laddered)
293 enum stone breaker = board_atxy(b, x, y);
294 return breaker == stone_other(laddered) || breaker == S_OFFBOARD;
297 static bool
298 ladder_catches(struct playout_policy *p, struct board *b, coord_t coord, group_t laddered)
300 struct moggy_policy *pp = p->data;
302 /* This is very trivial and gets a lot of corner cases wrong.
303 * We need this to be just very fast. One important point is
304 * that we sometimes might not notice a ladder but if we do,
305 * it should always work; thus we can use this for strong
306 * negative hinting safely. */
307 //fprintf(stderr, "ladder check\n");
309 enum stone lcolor = board_at(b, group_base(laddered));
310 int x = coord_x(coord, b), y = coord_y(coord, b);
312 /* First, special-case first-line "ladders". This is a huge chunk
313 * of ladders we actually meet and want to play. */
314 if (pp->borderladders
315 && neighbor_count_at(b, coord, S_OFFBOARD) == 1
316 && neighbor_count_at(b, coord, lcolor) == 1) {
317 if (PLDEBUGL(5))
318 fprintf(stderr, "border ladder\n");
319 /* Direction along border; xd is horiz. border, yd vertical. */
320 int xd = 0, yd = 0;
321 if (board_atxy(b, x + 1, y) == S_OFFBOARD || board_atxy(b, x - 1, y) == S_OFFBOARD)
322 yd = 1;
323 else
324 xd = 1;
325 /* Direction from the border; -1 is above/left, 1 is below/right. */
326 int dd = (board_atxy(b, x + yd, y + xd) == S_OFFBOARD) ? 1 : -1;
327 if (PLDEBUGL(6))
328 fprintf(stderr, "xd %d yd %d dd %d\n", xd, yd, dd);
329 /* | ? ?
330 * | . O #
331 * | c X #
332 * | . O #
333 * | ? ? */
334 /* This is normally caught, unless we have friends both above
335 * and below... */
336 if (board_atxy(b, x + xd * 2, y + yd * 2) == lcolor
337 && board_atxy(b, x - xd * 2, y - yd * 2) == lcolor)
338 return false;
339 /* ...or can't block where we need because of shortage
340 * of liberties. */
341 int libs1 = board_group_info(b, group_atxy(b, x + xd - yd * dd, y + yd - xd * dd)).libs;
342 int libs2 = board_group_info(b, group_atxy(b, x - xd - yd * dd, y - yd - xd * dd)).libs;
343 if (PLDEBUGL(6))
344 fprintf(stderr, "libs1 %d libs2 %d\n", libs1, libs2);
345 if (libs1 < 2 && libs2 < 2)
346 return false;
347 if (board_atxy(b, x + xd * 2, y + yd * 2) == lcolor && libs1 < 3)
348 return false;
349 if (board_atxy(b, x - xd * 2, y - yd * 2) == lcolor && libs2 < 3)
350 return false;
351 return true;
354 /* Figure out the ladder direction */
355 int xd, yd;
356 xd = board_atxy(b, x + 1, y) == S_NONE ? 1 : board_atxy(b, x - 1, y) == S_NONE ? -1 : 0;
357 yd = board_atxy(b, x, y + 1) == S_NONE ? 1 : board_atxy(b, x, y - 1) == S_NONE ? -1 : 0;
359 /* We do only tight ladders, not loose ladders. Furthermore,
360 * the ladders need to be simple:
361 * . X . . . X
362 * c O X supported . c O unsupported
363 * X # # X O #
366 /* For given (xd,yd), we have two possibilities where to move
367 * next. Consider (-1,1):
368 * n X . n c X
369 * c O X X O #
370 * X # # . X #
372 if (!xd || !yd || !(ladder_catcher(b, x - xd, y, lcolor) ^ ladder_catcher(b, x, y - yd, lcolor))) {
373 /* Silly situation, probably non-simple ladder or suicide. */
374 /* TODO: In case of basic non-simple ladder, play out both variants. */
375 if (PLDEBUGL(5))
376 fprintf(stderr, "non-simple ladder\n");
377 return false;
380 #define ladder_check(xd1_, yd1_, xd2_, yd2_) \
381 if (board_atxy(b, x, y) != S_NONE) { \
382 /* Did we hit a stone when playing out ladder? */ \
383 if (ladder_catcher(b, x, y, lcolor)) \
384 return true; /* ladder works */ \
385 if (board_group_info(b, group_atxy(b, x, y)).lib[0] > 0) \
386 return false; /* friend that's not in atari himself */ \
387 } else { \
388 /* No. So we are at new position. \
389 * We need to check indirect ladder breakers. */ \
390 /* . 2 x . . \
391 * . x o O 1 <- only at O we can check for o at 2 \
392 * x o o x . otherwise x at O would be still deadly \
393 * o o x . . \
394 * We check for o and x at 1, these are vital. \
395 * We check only for o at 2; x at 2 would mean we \
396 * need to fork (one step earlier). */ \
397 enum stone s1 = board_atxy(b, x + (xd1_), y + (yd1_)); \
398 if (s1 == lcolor) return false; \
399 if (s1 == stone_other(lcolor)) return true; \
400 enum stone s2 = board_atxy(b, x + (xd2_), y + (yd2_)); \
401 if (s2 == lcolor) return false; \
403 #define ladder_horiz do { if (PLDEBUGL(6)) fprintf(stderr, "%d,%d horiz step %d\n", x, y, xd); x += xd; ladder_check(xd, 0, -2 * xd, yd); } while (0)
404 #define ladder_vert do { if (PLDEBUGL(6)) fprintf(stderr, "%d,%d vert step %d\n", x, y, yd); y += yd; ladder_check(0, yd, xd, -2 * yd); } while (0)
406 if (ladder_catcher(b, x - xd, y, lcolor))
407 ladder_horiz;
408 do {
409 ladder_vert;
410 ladder_horiz;
411 } while (1);
415 static void
416 group_atari_check(struct playout_policy *p, struct board *b, group_t group, struct move_queue *q)
418 struct moggy_policy *pp = p->data;
420 /* Do not bother with kos. */
421 if (group_is_onestone(b, group))
422 return;
424 enum stone color = board_at(b, group_base(group));
425 coord_t lib = board_group_info(b, group).lib[0];
427 assert(color != S_OFFBOARD && color != S_NONE);
428 if (PLDEBUGL(5))
429 fprintf(stderr, "atariiiiiiiii %s of color %d\n", coord2sstr(lib, b), color);
430 assert(board_at(b, lib) == S_NONE);
432 /* Can we capture some neighbor? */
433 foreach_in_group(b, group) {
434 foreach_neighbor(b, c, {
435 if (board_at(b, c) != stone_other(color)
436 || board_group_info(b, group_at(b, c)).libs > 1)
437 continue;
438 if (PLDEBUGL(6))
439 fprintf(stderr, "can capture group %d\n", group_at(b, c));
440 /* If we are saving our group, capture! */
441 if (b->last_move.color == stone_other(color))
442 q->move[q->moves++] = board_group_info(b, group_at(b, c)).lib[0];
443 else /* If we chase the group, capture it now! */
444 q->move[q->moves++] = lib;
445 /* Make sure capturing the group will actually
446 * expand our liberties if we are filling our
447 * last liberty. */
448 if (q->move[q->moves - 1] == lib && is_selfatari(b, color, lib))
449 q->moves--;
450 else
451 mq_nodup(q);
453 } foreach_in_group_end;
455 /* Do not suicide... */
456 if (is_selfatari(b, color, lib))
457 return;
458 if (PLDEBUGL(6))
459 fprintf(stderr, "...escape route valid\n");
461 /* ...or play out ladders. */
462 if (pp->ladders && ladder_catches(p, b, lib, group)) {
463 return;
465 if (PLDEBUGL(6))
466 fprintf(stderr, "...no ladder\n");
468 q->move[q->moves++] = lib;
469 mq_nodup(q);
472 static coord_t
473 global_atari_check(struct playout_policy *p, struct board *b)
475 struct move_queue q;
476 q.moves = 0;
478 if (b->clen == 0)
479 return pass;
481 int g_base = fast_random(b->clen);
482 for (int g = g_base; g < b->clen; g++) {
483 group_atari_check(p, b, group_at(b, group_base(b->c[g])), &q);
484 if (q.moves > 0)
485 return q.move[fast_random(q.moves)];
487 for (int g = 0; g < g_base; g++) {
488 group_atari_check(p, b, group_at(b, group_base(b->c[g])), &q);
489 if (q.moves > 0)
490 return q.move[fast_random(q.moves)];
492 return pass;
495 static coord_t
496 local_atari_check(struct playout_policy *p, struct board *b, struct move *m)
498 struct move_queue q;
499 q.moves = 0;
501 /* Did the opponent play a self-atari? */
502 if (board_group_info(b, group_at(b, m->coord)).libs == 1) {
503 group_atari_check(p, b, group_at(b, m->coord), &q);
506 foreach_neighbor(b, m->coord, {
507 group_t g = group_at(b, c);
508 if (!g || board_group_info(b, g).libs != 1)
509 continue;
510 group_atari_check(p, b, g, &q);
513 if (PLDEBUGL(5)) {
514 fprintf(stderr, "Local atari candidate moves: ");
515 for (int i = 0; i < q.moves; i++) {
516 fprintf(stderr, "%s ", coord2sstr(q.move[i], b));
518 fprintf(stderr, "\n");
521 int i = fast_random(q.moves);
522 return q.moves ? q.move[i] : pass;
525 coord_t
526 playout_moggy_choose(struct playout_policy *p, struct board *b, enum stone to_play)
528 struct moggy_policy *pp = p->data;
529 coord_t c;
531 if (PLDEBUGL(5))
532 board_print(b, stderr);
534 /* Local checks */
535 if (!is_pass(b->last_move.coord)) {
536 /* Local group in atari? */
537 if (pp->lcapturerate > fast_random(100)) {
538 c = local_atari_check(p, b, &b->last_move);
539 if (!is_pass(c))
540 return c;
543 /* Check for patterns we know */
544 if (pp->patternrate > fast_random(100)) {
545 c = apply_pattern(p, b, &b->last_move);
546 if (!is_pass(c))
547 return c;
551 /* Global checks */
553 /* Any groups in atari? */
554 if (pp->capturerate > fast_random(100)) {
555 c = global_atari_check(p, b);
556 if (!is_pass(c))
557 return c;
560 return pass;
563 float
564 playout_moggy_assess(struct playout_policy *p, struct board *b, struct move *m)
566 struct moggy_policy *pp = p->data;
568 if (is_pass(m->coord))
569 return NAN;
571 if (PLDEBUGL(5)) {
572 fprintf(stderr, "ASSESS of %s:\n", coord2sstr(m->coord, b));
573 board_print(b, stderr);
576 /* Are we dealing with atari? */
577 if (pp->lcapturerate || pp->capturerate) {
578 bool ladder = false;
580 foreach_neighbor(b, m->coord, {
581 group_t g = group_at(b, c);
582 if (!g || board_group_info(b, g).libs != 1)
583 continue;
585 struct move_queue q; q.moves = 0;
586 group_atari_check(p, b, g, &q);
587 while (q.moves--)
588 if (q.move[q.moves] == m->coord) {
589 if (PLDEBUGL(5))
590 fprintf(stderr, "1.0: atari\n");
591 return 1.0;
594 /* _Never_ play here if this move plays out
595 * a caught ladder. (Unless it captures another
596 * group. :-) */
597 if (pp->ladderassess && ladder_catches(p, b, m->coord, g)) {
598 /* Note that the opposite is not guarded against;
599 * we do not advise against capturing a laddered
600 * group (but we don't encourage it either). Such
601 * a move can simplify tactical situations if we
602 * can afford it. */
603 if (m->color == board_at(b, c))
604 ladder = true;
608 if (ladder) {
609 if (PLDEBUGL(5))
610 fprintf(stderr, "0.0: ladder\n");
611 return 0.0;
615 /* Pattern check */
616 if (pp->patternrate) {
617 if (test_pattern_here(p, moggy_patterns, b, m)) {
618 if (PLDEBUGL(5))
619 fprintf(stderr, "1.0: pattern\n");
620 return 1.0;
624 return NAN;
627 bool
628 playout_moggy_permit(struct playout_policy *p, struct board *b, struct move *m)
630 struct moggy_policy *pp = p->data;
632 /* The idea is simple for now - never allow self-atari moves.
633 * They suck in general, but this also permits us to actually
634 * handle seki in the playout stage. */
635 /* FIXME: We must allow self-atari in some basic nakade shapes. */
636 #if 0
637 if (is_selfatari(b, m->color, m->coord))
638 fprintf(stderr, "__ Prohibiting self-atari %s %s\n", stone2str(m->color), coord2sstr(m->coord, b));
639 #endif
640 return fast_random(100) >= pp->selfatarirate || !is_selfatari(b, m->color, m->coord);
644 struct playout_policy *
645 playout_moggy_init(char *arg)
647 struct playout_policy *p = calloc(1, sizeof(*p));
648 struct moggy_policy *pp = calloc(1, sizeof(*pp));
649 p->data = pp;
650 p->choose = playout_moggy_choose;
651 p->assess = playout_moggy_assess;
652 p->permit = playout_moggy_permit;
654 pp->lcapturerate = 90;
655 pp->capturerate = 90;
656 pp->patternrate = 90;
657 pp->selfatarirate = 90;
658 pp->ladders = pp->borderladders = true;
659 pp->ladderassess = true;
661 if (arg) {
662 char *optspec, *next = arg;
663 while (*next) {
664 optspec = next;
665 next += strcspn(next, ":");
666 if (*next) { *next++ = 0; } else { *next = 0; }
668 char *optname = optspec;
669 char *optval = strchr(optspec, '=');
670 if (optval) *optval++ = 0;
672 if (!strcasecmp(optname, "lcapturerate") && optval) {
673 pp->lcapturerate = atoi(optval);
674 } else if (!strcasecmp(optname, "capturerate") && optval) {
675 pp->capturerate = atoi(optval);
676 } else if (!strcasecmp(optname, "patternrate") && optval) {
677 pp->patternrate = atoi(optval);
678 } else if (!strcasecmp(optname, "selfatarirate") && optval) {
679 pp->selfatarirate = atoi(optval);
680 } else if (!strcasecmp(optname, "ladders")) {
681 pp->ladders = optval && *optval == '0' ? false : true;
682 } else if (!strcasecmp(optname, "borderladders")) {
683 pp->borderladders = optval && *optval == '0' ? false : true;
684 } else if (!strcasecmp(optname, "ladderassess")) {
685 pp->ladderassess = optval && *optval == '0' ? false : true;
686 } else {
687 fprintf(stderr, "playout-moggy: Invalid policy argument %s or missing value\n", optname);
692 return p;