12 #include "playout/moggy.h"
15 #include "uct/prior.h"
17 #define PLDEBUGL(n) DEBUGL_(p->debug_level, n)
20 /* Note that the context can be shared by multiple threads! */
23 bool ladders
, ladderassess
, borderladders
, assess_local
;
24 int lcapturerate
, atarirate
, capturerate
, patternrate
;
27 /* Whether to look for patterns around second-to-last move. */
30 struct pattern3s patterns
;
41 /* Below, we keep track of each trait for each |color_to_play */
42 int capturable_ready
:2; // is @capturable meaningful?
45 int can_countercapture_ready
:2;
46 int can_countercapture
:2;
49 /* Cache of evaluation of various board features. */
53 struct group_state
*groups
; /* [board_size2()], indexed by group_t */
54 unsigned char *groups_known
; /* Bitmap of known groups. */
57 /* Using board cache: this turns out to be actually a 10% slowdown,
58 * since we reuse data in the cache only very little within single
60 // #define CACHE_STATE
61 /* Reusing board cache across moves if they are successive on the
62 * board; only cache entries within cfg distance 2 of the last move
64 // #define PERSISTENT_STATE
67 static __thread
struct board_state
*ss
;
70 board_state_reuse(struct board_state
*s
, struct board
*b
)
72 /* Decide how much of the board state we can reuse. */
73 /* We do not cache ladder decisions, so we don't have
74 * to worry about this. */
75 coord_t c
= b
->last_move
.coord
;
77 if (unlikely(is_pass(c
))) {
78 /* Passes don't change anything. */
82 if (unlikely(board_at(b
, c
) == S_NONE
)) {
83 /* Suicide is hopeless. */
87 /* XXX: we can make some moves self-atari. */
89 if (neighbor_count_at(b
, c
, S_BLACK
) + neighbor_count_at(b
, c
, S_WHITE
) == 0) {
90 /* We are not taking off liberties of any other stones. */
97 static inline struct board_state
*
98 board_state_init(struct board
*b
)
101 if (ss
->bsize2
!= board_size2(b
)) {
103 free(ss
->groups_known
);
106 #ifdef PERSISTENT_STATE
107 /* Only one stone added to the board, nothing removed. */
108 else if (ss
->hash
== (b
->hash
^ hash_at(b
, b
->last_move
.coord
, b
->last_move
.color
))) {
110 if (likely(board_state_reuse(ss
, b
)))
116 ss
= malloc(sizeof(*ss
));
117 ss
->bsize2
= board_size2(b
);
118 ss
->groups
= malloc(board_size2(b
) * sizeof(*ss
->groups
));
119 ss
->groups_known
= malloc(board_size2(b
) / 8 + 1);
122 memset(ss
->groups_known
, 0, board_size2(b
) / 8 + 1);
126 #define group_is_known(s, g) (s->groups_known[g >> 3] & (1 << (g & 7)))
127 #define group_set_known(s, g) (s->groups_known[g >> 3] |= (1 << (g & 7)))
128 #define group_trait_ready(s, g, color, gstat, trait) do { \
129 if (!group_is_known(s, g)) { \
130 memset(&s->groups[g], 0, sizeof(s->groups[g])); \
131 group_set_known(s, g); \
133 s->groups[g].status = gstat; \
134 s->groups[g].trait ## _ready |= color; \
136 #define group_trait_is_ready(s, g, color, trait) (s->groups[g].trait ## _ready & color)
137 #define group_trait_set(s, g, color, trait, val) s->groups[g].trait = (s->groups[g].trait & ~color) | (!!val * color)
138 #define group_trait_get(s, g, color, trait) (s->groups[g].trait & color)
142 #define board_state_init(b) NULL
143 #define group_is_known(s, g) false
144 #define group_set_known(s, g)
145 #define group_trait_ready(s, g, color, gstat, trait)
146 #define group_trait_is_ready(s, g, color, trait) false
147 #define group_trait_set(s, g, color, trait, val)
148 #define group_trait_get(s, g, color, trait) false
152 static char moggy_patterns_src
[][11] = {
153 /* hane pattern - enclosing hane */
157 /* hane pattern - non-cutting hane */
161 /* hane pattern - magari */
165 /* hane pattern - thin hane */
169 /* generic pattern - katatsuke or diagonal attachment; similar to magari */
173 /* cut1 pattern (kiri) - unprotected cut */
177 /* cut1 pattern (kiri) - peeped cut */
181 /* cut2 pattern (de) */
185 /* cut keima (not in Mogo) */
188 "???", /* o?? has some pathological tsumego cases */
189 /* side pattern - chase */
193 /* side pattern - weirdness (SUSPICIOUS) */
197 /* side pattern - sagari (SUSPICIOUS) */
199 "x.x" /* Mogo has "x.?" */
200 "###" /* Mogo has "X" */,
201 /* side pattern - throw-in (SUSPICIOUS) */
207 /* side pattern - cut (SUSPICIOUS) */
210 "###" /* Mogo has "X" */,
212 #define moggy_patterns_src_n sizeof(moggy_patterns_src) / sizeof(moggy_patterns_src[0])
215 apply_pattern_here(struct playout_policy
*p
,
216 struct board
*b
, struct move
*m
, struct move_queue
*q
)
218 struct moggy_policy
*pp
= p
->data
;
219 if (test_pattern3_here(&pp
->patterns
, b
, m
))
223 /* Check if we match any pattern around given move (with the other color to play). */
225 apply_pattern(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct move
*mm
)
230 /* Suicides do not make any patterns and confuse us. */
231 if (board_at(b
, m
->coord
) == S_NONE
|| board_at(b
, m
->coord
) == S_OFFBOARD
)
234 foreach_8neighbor(b
, m
->coord
) {
235 struct move m2
; m2
.coord
= c
; m2
.color
= stone_other(m
->color
);
236 if (board_is_valid_move(b
, &m2
))
237 apply_pattern_here(p
, b
, &m2
, &q
);
238 } foreach_8neighbor_end
;
240 if (mm
) { /* Second move for pattern searching */
241 foreach_8neighbor(b
, mm
->coord
) {
242 if (coord_is_8adjecent(m
->coord
, c
, b
))
244 struct move m2
; m2
.coord
= c
; m2
.color
= stone_other(m
->color
);
245 if (board_is_valid_move(b
, &m2
))
246 apply_pattern_here(p
, b
, &m2
, &q
);
247 } foreach_8neighbor_end
;
251 mq_print(&q
, b
, "Pattern");
258 can_play_on_lib(struct playout_policy
*p
, struct board_state
*s
,
259 struct board
*b
, group_t g
, enum stone to_play
)
261 if (group_is_known(s
, g
) && group_trait_is_ready(s
, g
, to_play
, capturable
)) {
262 /* We have already seen this group. */
263 assert(s
->groups
[g
].status
== G_ATARI
);
264 if (group_trait_get(s
, g
, to_play
, capturable
))
270 /* Cache miss. Set up cache entry, default at capturable = false. */
271 group_trait_ready(s
, g
, to_play
, G_ATARI
, capturable
);
273 coord_t capture
= board_group_info(b
, g
).lib
[0];
275 fprintf(stderr
, "can capture group %d (%s)?\n",
276 g
, coord2sstr(capture
, b
));
277 /* Does playing on the liberty usefully capture the group? */
278 struct move m
; m
.color
= to_play
; m
.coord
= capture
;
279 if (board_is_valid_move(b
, &m
) && !is_bad_selfatari(b
, to_play
, capture
)) {
280 group_trait_set(s
, g
, to_play
, capturable
, true);
287 /* For given position @c, decide if this is a group that is in danger from
288 * @capturer and @to_play can do anything about it (play at the last
289 * liberty to either capture or escape). */
290 /* Note that @to_play is important; e.g. consider snapback, it's good
291 * to play at the last liberty by attacker, but not defender. */
292 static __attribute__((always_inline
)) bool
293 capturable_group(struct playout_policy
*p
, struct board_state
*s
,
294 struct board
*b
, enum stone capturer
, coord_t c
,
297 group_t g
= group_at(b
, c
);
298 if (likely(board_at(b
, c
) != stone_other(capturer
)
299 || board_group_info(b
, g
).libs
> 1))
302 return can_play_on_lib(p
, s
, b
, g
, to_play
);
305 /* For given atari group @group owned by @owner, decide if @to_play
306 * can save it / keep it in danger by dealing with one of the
307 * neighboring groups. */
309 can_countercapture(struct playout_policy
*p
, struct board_state
*s
,
310 struct board
*b
, enum stone owner
, group_t g
,
311 enum stone to_play
, struct move_queue
*q
)
315 if (group_is_known(s
, g
) && group_trait_is_ready(s
, g
, to_play
, can_countercapture
)) {
316 /* We have already seen this group. */
317 assert(s
->groups
[g
].status
== G_ATARI
);
318 if (group_trait_get(s
, g
, to_play
, can_countercapture
)) {
319 if (q
) { /* Scan for countercapture liberties. */
328 /* Cache miss. Set up cache entry, default at can_countercapture = true. */
329 group_trait_ready(s
, g
, to_play
, G_ATARI
, can_countercapture
);
330 group_trait_set(s
, g
, to_play
, can_countercapture
, true);
333 int qmoves_prev
= q
? q
->moves
: 0;
335 foreach_in_group(b
, g
) {
336 foreach_neighbor(b
, c
, {
337 if (!capturable_group(p
, s
, b
, owner
, c
, to_play
))
343 mq_add(q
, board_group_info(b
, group_at(b
, c
)).lib
[0]);
346 } foreach_in_group_end
;
348 bool can
= q
? q
->moves
> qmoves_prev
: false;
349 group_trait_set(s
, g
, to_play
, can_countercapture
, can
);
354 can_be_rescued(struct playout_policy
*p
, struct board_state
*s
,
355 struct board
*b
, group_t group
, enum stone color
)
357 /* Does playing on the liberty rescue the group? */
358 if (can_play_on_lib(p
, s
, b
, group
, color
))
361 /* Then, maybe we can capture one of our neighbors? */
362 return can_countercapture(p
, s
, b
, color
, group
, color
, NULL
);
366 group_atari_check(struct playout_policy
*p
, struct board
*b
, group_t group
, enum stone to_play
,
367 struct move_queue
*q
, coord_t
*ladder
, struct board_state
*s
)
369 struct moggy_policy
*pp
= p
->data
;
370 int qmoves_prev
= q
->moves
;
372 /* We don't use @to_play almost anywhere since any moves here are good
373 * for both defender and attacker. */
375 enum stone color
= board_at(b
, group_base(group
));
376 coord_t lib
= board_group_info(b
, group
).lib
[0];
378 assert(color
!= S_OFFBOARD
&& color
!= S_NONE
);
380 fprintf(stderr
, "[%s] atariiiiiiiii %s of color %d\n",
381 coord2sstr(group
, b
), coord2sstr(lib
, b
), color
);
382 assert(board_at(b
, lib
) == S_NONE
);
384 /* Do not bother with kos. */
385 if (group_is_onestone(b
, group
)
386 && neighbor_count_at(b
, lib
, color
) + neighbor_count_at(b
, lib
, S_OFFBOARD
) == 4)
389 /* Can we capture some neighbor? */
390 can_countercapture(p
, s
, b
, color
, group
, to_play
, q
);
392 /* Do not suicide... */
393 if (!can_play_on_lib(p
, s
, b
, group
, to_play
))
395 /* Do not remove group that cannot be saved by the opponent. */
396 if (to_play
!= color
&& !can_be_rescued(p
, s
, b
, group
, color
))
399 fprintf(stderr
, "...escape route valid\n");
401 /* ...or play out ladders. */
402 if (is_ladder(b
, lib
, group
, pp
->borderladders
, pp
->ladders
)) {
403 /* Sometimes we want to keep the ladder move in the
404 * queue in order to discourage it. */
411 fprintf(stderr
, "...no ladder\n");
413 if (to_play
!= color
) {
414 /* We are the attacker! In that case, throw away the moves
415 * that defend our groups, since we can capture the culprit. */
416 q
->moves
= qmoves_prev
;
424 global_atari_check(struct playout_policy
*p
, struct board
*b
, enum stone to_play
, struct board_state
*s
)
432 int g_base
= fast_random(b
->clen
);
433 for (int g
= g_base
; g
< b
->clen
; g
++) {
434 group_atari_check(p
, b
, group_at(b
, group_base(b
->c
[g
])), to_play
, &q
, NULL
, s
);
438 for (int g
= 0; g
< g_base
; g
++) {
439 group_atari_check(p
, b
, group_at(b
, group_base(b
->c
[g
])), to_play
, &q
, NULL
, s
);
447 local_atari_check(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct board_state
*s
)
452 /* Did the opponent play a self-atari? */
453 if (board_group_info(b
, group_at(b
, m
->coord
)).libs
== 1) {
454 group_atari_check(p
, b
, group_at(b
, m
->coord
), stone_other(m
->color
), &q
, NULL
, s
);
457 foreach_neighbor(b
, m
->coord
, {
458 group_t g
= group_at(b
, c
);
459 if (!g
|| board_group_info(b
, g
).libs
!= 1)
461 group_atari_check(p
, b
, g
, stone_other(m
->color
), &q
, NULL
, s
);
465 mq_print(&q
, b
, "Local atari");
471 miai_2lib(struct board
*b
, group_t group
, enum stone color
)
473 bool can_connect
= false, can_pull_out
= false;
474 /* We have miai if we can either connect on both libs,
475 * or connect on one lib and escape on another. (Just
476 * having two escape routes can be risky.) */
477 foreach_neighbor(b
, board_group_info(b
, group
).lib
[0], {
478 enum stone cc
= board_at(b
, c
);
479 if (cc
== S_NONE
&& cc
!= board_group_info(b
, group
).lib
[1]) {
481 } else if (cc
!= color
) {
485 group_t cg
= group_at(b
, c
);
486 if (cg
&& cg
!= group
&& board_group_info(b
, cg
).libs
> 1)
489 foreach_neighbor(b
, board_group_info(b
, group
).lib
[1], {
490 enum stone cc
= board_at(b
, c
);
491 if (cc
== S_NONE
&& cc
!= board_group_info(b
, group
).lib
[0] && can_connect
) {
493 } else if (cc
!= color
) {
497 group_t cg
= group_at(b
, c
);
498 if (cg
&& cg
!= group
&& board_group_info(b
, cg
).libs
> 1)
499 return (can_connect
|| can_pull_out
);
505 check_group_atari(struct board
*b
, group_t group
, enum stone owner
,
506 enum stone to_play
, struct move_queue
*q
)
508 for (int i
= 0; i
< 2; i
++) {
509 coord_t lib
= board_group_info(b
, group
).lib
[i
];
510 assert(board_at(b
, lib
) == S_NONE
);
511 struct move m
; m
.color
= to_play
; m
.coord
= lib
;
512 if (!board_is_valid_move(b
, &m
))
515 /* Don't play at the spot if it is extremely short
517 /* XXX: This looks harmful, could significantly
518 * prefer atari to throwin:
524 if (neighbor_count_at(b
, lib
, stone_other(owner
)) + immediate_liberty_count(b
, lib
) < 2)
528 /* If the owner can't play at the spot, we don't want
529 * to bother either. */
530 if (is_bad_selfatari(b
, owner
, lib
))
533 /* Of course we don't want to play bad selfatari
534 * ourselves, if we are the attacker... */
535 if (to_play
!= owner
&& is_bad_selfatari(b
, to_play
, lib
))
538 /* Tasty! Crispy! Good! */
545 group_2lib_check(struct playout_policy
*p
, struct board
*b
, group_t group
, enum stone to_play
,
546 struct move_queue
*q
, struct board_state
*s
)
548 enum stone color
= board_at(b
, group_base(group
));
549 assert(color
!= S_OFFBOARD
&& color
!= S_NONE
);
552 fprintf(stderr
, "[%s] 2lib check of color %d\n",
553 coord2sstr(group
, b
), color
);
555 /* Do not try to atari groups that cannot be harmed. */
556 if (miai_2lib(b
, group
, color
))
559 check_group_atari(b
, group
, color
, to_play
, q
);
561 /* Can we counter-atari another group, if we are the defender? */
562 if (to_play
!= color
)
564 foreach_in_group(b
, group
) {
565 foreach_neighbor(b
, c
, {
566 if (board_at(b
, c
) != stone_other(color
))
568 group_t g2
= group_at(b
, c
);
569 if (board_group_info(b
, g2
).libs
!= 2)
571 check_group_atari(b
, group
, color
, to_play
, q
);
573 } foreach_in_group_end
;
577 local_2lib_check(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct board_state
*s
)
582 /* Does the opponent have just two liberties? */
583 if (board_group_info(b
, group_at(b
, m
->coord
)).libs
== 2) {
584 group_2lib_check(p
, b
, group_at(b
, m
->coord
), stone_other(m
->color
), &q
, s
);
586 /* We always prefer to take off an enemy chain liberty
587 * before pulling out ourselves. */
588 /* XXX: We aren't guaranteed to return to that group
591 return q
.move
[fast_random(q
.moves
)];
595 /* Then he took a third liberty from neighboring chain? */
596 foreach_neighbor(b
, m
->coord
, {
597 group_t g
= group_at(b
, c
);
598 if (!g
|| board_group_info(b
, g
).libs
!= 2)
600 group_2lib_check(p
, b
, g
, stone_other(m
->color
), &q
, s
);
604 mq_print(&q
, b
, "Local 2lib");
610 playout_moggy_choose(struct playout_policy
*p
, struct board
*b
, enum stone to_play
)
612 struct moggy_policy
*pp
= p
->data
;
615 struct board_state
*s
= board_state_init(b
);
618 board_print(b
, stderr
);
621 if (!is_pass(b
->last_move
.coord
)) {
622 /* Local group in atari? */
623 if (pp
->lcapturerate
> fast_random(100)) {
624 c
= local_atari_check(p
, b
, &b
->last_move
, s
);
629 /* Local group can be PUT in atari? */
630 if (pp
->atarirate
> fast_random(100)) {
631 c
= local_2lib_check(p
, b
, &b
->last_move
, s
);
636 /* Check for patterns we know */
637 if (pp
->patternrate
> fast_random(100)) {
638 c
= apply_pattern(p
, b
, &b
->last_move
,
639 pp
->pattern2
&& b
->last_move2
.coord
>= 0 ? &b
->last_move2
: NULL
);
647 /* Any groups in atari? */
648 if (pp
->capturerate
> fast_random(100)) {
649 c
= global_atari_check(p
, b
, to_play
, s
);
655 int fbtries
= b
->flen
/ 8;
656 for (int i
= 0; i
< (fbtries
< pp
->fillboardtries
? fbtries
: pp
->fillboardtries
); i
++) {
657 coord_t coord
= b
->f
[fast_random(b
->flen
)];
658 if (is_pass(coord
) || immediate_liberty_count(b
, coord
) != 4)
660 foreach_diag_neighbor(b
, coord
) {
661 if (board_at(b
, c
) != S_NONE
)
663 } foreach_diag_neighbor_end
;
673 assess_local_bonus(struct playout_policy
*p
, struct board
*board
, coord_t a
, coord_t b
, int games
)
675 struct moggy_policy
*pp
= p
->data
;
676 if (!pp
->assess_local
)
679 int dx
= abs(coord_x(a
, board
) - coord_x(b
, board
));
680 int dy
= abs(coord_y(a
, board
) - coord_y(b
, board
));
681 /* adjecent move, directly or diagonally? */
682 if (dx
+ dy
<= 1 + (dx
&& dy
))
689 playout_moggy_assess_group(struct playout_policy
*p
, struct prior_map
*map
, group_t g
, int games
,
690 struct board_state
*s
)
692 struct moggy_policy
*pp
= p
->data
;
693 struct board
*b
= map
->b
;
694 struct move_queue q
; q
.moves
= 0;
696 if (board_group_info(b
, g
).libs
> 2)
700 fprintf(stderr
, "ASSESS of group %s:\n", coord2sstr(g
, b
));
701 board_print(b
, stderr
);
704 if (board_group_info(b
, g
).libs
== 2) {
707 group_2lib_check(p
, b
, g
, map
->to_play
, &q
, s
);
709 coord_t coord
= q
.move
[q
.moves
];
711 fprintf(stderr
, "1.0: 2lib %s\n", coord2sstr(coord
, b
));
712 int assess
= assess_local_bonus(p
, b
, b
->last_move
.coord
, coord
, games
) / 2;
713 add_prior_value(map
, coord
, 1, assess
);
718 /* This group, sir, is in atari! */
720 if (!pp
->capturerate
&& !pp
->lcapturerate
&& !pp
->ladderassess
)
723 coord_t ladder
= pass
;
724 group_atari_check(p
, b
, g
, map
->to_play
, &q
, &ladder
, s
);
726 coord_t coord
= q
.move
[q
.moves
];
728 /* _Never_ play here if this move plays out
729 * a caught ladder. */
730 if (coord
== ladder
&& !board_playing_ko_threat(b
)) {
731 /* Note that the opposite is not guarded against;
732 * we do not advise against capturing a laddered
733 * group (but we don't encourage it either). Such
734 * a move can simplify tactical situations if we
736 if (!pp
->ladderassess
|| map
->to_play
!= board_at(b
, g
))
738 /* FIXME: We give the malus even if this move
739 * captures another group. */
741 fprintf(stderr
, "0.0: ladder %s\n", coord2sstr(coord
, b
));
742 add_prior_value(map
, coord
, 0, games
);
746 if (!pp
->capturerate
&& !pp
->lcapturerate
)
750 fprintf(stderr
, "1.0: atari %s\n", coord2sstr(coord
, b
));
751 int assess
= assess_local_bonus(p
, b
, b
->last_move
.coord
, coord
, games
) * 2;
752 add_prior_value(map
, coord
, 1, assess
);
757 playout_moggy_assess_one(struct playout_policy
*p
, struct prior_map
*map
, coord_t coord
, int games
)
759 struct moggy_policy
*pp
= p
->data
;
760 struct board
*b
= map
->b
;
763 fprintf(stderr
, "ASSESS of move %s:\n", coord2sstr(coord
, b
));
764 board_print(b
, stderr
);
767 /* Is this move a self-atari? */
768 if (pp
->selfatarirate
) {
769 if (!board_playing_ko_threat(b
) && is_bad_selfatari(b
, map
->to_play
, coord
)) {
771 fprintf(stderr
, "0.0: self-atari\n");
772 add_prior_value(map
, coord
, 0, games
);
778 if (pp
->patternrate
) {
779 struct move m
= { .color
= map
->to_play
, .coord
= coord
};
780 if (test_pattern3_here(&pp
->patterns
, b
, &m
)) {
782 fprintf(stderr
, "1.0: pattern\n");
783 int assess
= assess_local_bonus(p
, b
, b
->last_move
.coord
, coord
, games
);
784 add_prior_value(map
, coord
, 1, assess
);
792 playout_moggy_assess(struct playout_policy
*p
, struct prior_map
*map
, int games
)
794 struct moggy_policy
*pp
= p
->data
;
796 struct board_state
*s
= board_state_init(map
->b
);
798 /* First, go through all endangered groups. */
799 if (pp
->lcapturerate
|| pp
->capturerate
|| pp
->atarirate
|| pp
->ladderassess
)
800 for (group_t g
= 1; g
< board_size2(map
->b
); g
++)
801 if (group_at(map
->b
, g
) == g
)
802 playout_moggy_assess_group(p
, map
, g
, games
, s
);
804 /* Then, assess individual moves. */
805 if (!pp
->patternrate
&& !pp
->selfatarirate
)
807 foreach_point(map
->b
) {
808 if (map
->consider
[c
])
809 playout_moggy_assess_one(p
, map
, c
, games
);
814 playout_moggy_permit(struct playout_policy
*p
, struct board
*b
, struct move
*m
)
816 struct moggy_policy
*pp
= p
->data
;
818 /* The idea is simple for now - never allow self-atari moves.
819 * They suck in general, but this also permits us to actually
820 * handle seki in the playout stage. */
822 if (fast_random(100) >= pp
->selfatarirate
) {
824 fprintf(stderr
, "skipping sar test\n");
827 bool selfatari
= is_bad_selfatari(b
, m
->color
, m
->coord
);
828 if (PLDEBUGL(5) && selfatari
)
829 fprintf(stderr
, "__ Prohibiting self-atari %s %s\n",
830 stone2str(m
->color
), coord2sstr(m
->coord
, b
));
835 struct playout_policy
*
836 playout_moggy_init(char *arg
)
838 struct playout_policy
*p
= calloc(1, sizeof(*p
));
839 struct moggy_policy
*pp
= calloc(1, sizeof(*pp
));
841 p
->choose
= playout_moggy_choose
;
842 p
->assess
= playout_moggy_assess
;
843 p
->permit
= playout_moggy_permit
;
847 pp
->lcapturerate
= pp
->atarirate
= pp
->capturerate
= pp
->patternrate
= pp
->selfatarirate
= -1;
848 pp
->ladders
= pp
->borderladders
= true;
849 pp
->ladderassess
= true;
852 char *optspec
, *next
= arg
;
855 next
+= strcspn(next
, ":");
856 if (*next
) { *next
++ = 0; } else { *next
= 0; }
858 char *optname
= optspec
;
859 char *optval
= strchr(optspec
, '=');
860 if (optval
) *optval
++ = 0;
862 if (!strcasecmp(optname
, "lcapturerate") && optval
) {
863 pp
->lcapturerate
= atoi(optval
);
864 } else if (!strcasecmp(optname
, "atarirate") && optval
) {
865 pp
->atarirate
= atoi(optval
);
866 } else if (!strcasecmp(optname
, "capturerate") && optval
) {
867 pp
->capturerate
= atoi(optval
);
868 } else if (!strcasecmp(optname
, "patternrate") && optval
) {
869 pp
->patternrate
= atoi(optval
);
870 } else if (!strcasecmp(optname
, "selfatarirate") && optval
) {
871 pp
->selfatarirate
= atoi(optval
);
872 } else if (!strcasecmp(optname
, "rate") && optval
) {
874 } else if (!strcasecmp(optname
, "fillboardtries")) {
875 pp
->fillboardtries
= atoi(optval
);
876 } else if (!strcasecmp(optname
, "ladders")) {
877 pp
->ladders
= optval
&& *optval
== '0' ? false : true;
878 } else if (!strcasecmp(optname
, "borderladders")) {
879 pp
->borderladders
= optval
&& *optval
== '0' ? false : true;
880 } else if (!strcasecmp(optname
, "ladderassess")) {
881 pp
->ladderassess
= optval
&& *optval
== '0' ? false : true;
882 } else if (!strcasecmp(optname
, "assess_local")) {
883 pp
->assess_local
= optval
&& *optval
== '0' ? false : true;
884 } else if (!strcasecmp(optname
, "pattern2")) {
885 pp
->pattern2
= optval
&& *optval
== '0' ? false : true;
887 fprintf(stderr
, "playout-moggy: Invalid policy argument %s or missing value\n", optname
);
892 if (pp
->lcapturerate
== -1) pp
->lcapturerate
= rate
;
893 if (pp
->atarirate
== -1) pp
->atarirate
= rate
;
894 if (pp
->capturerate
== -1) pp
->capturerate
= rate
;
895 if (pp
->patternrate
== -1) pp
->patternrate
= rate
;
896 if (pp
->selfatarirate
== -1) pp
->selfatarirate
= rate
;
898 pattern3s_init(&pp
->patterns
, moggy_patterns_src
, moggy_patterns_src_n
);