1 /* Heuristical playout (and tree prior) policy modelled primarily after
2 * the description of the Mogo engine. */
12 #include "joseki/base.h"
16 #include "playout/moggy.h"
18 #include "tactics/1lib.h"
19 #include "tactics/2lib.h"
20 #include "tactics/nlib.h"
21 #include "tactics/ladder.h"
22 #include "tactics/nakade.h"
23 #include "tactics/selfatari.h"
24 #include "uct/prior.h"
26 #define PLDEBUGL(n) DEBUGL_(p->debug_level, n)
29 /* In case "seqchoose" move picker is enabled (i.e. no "fullchoose"
30 * parameter passed), we stochastically apply fixed set of decision
31 * rules in given order.
33 * In "fullchoose" mode, we instead build a move queue of variously
34 * tagged candidates, then consider a probability distribution over
35 * them and pick a move from that. */
37 /* Move queue tags. Some may be even undesirable - these moves then
38 * receive a penalty; penalty tags should be used only when it is
39 * certain the move would be considered anyway. */
53 /* Note that the context can be shared by multiple threads! */
56 unsigned int lcapturerate
, atarirate
, nlibrate
, capturerate
, patternrate
, korate
, josekirate
, nakaderate
;
57 unsigned int selfatarirate
, alwaysccaprate
;
58 unsigned int fillboardtries
;
60 /* Whether to look for patterns around second-to-last move. */
62 /* Whether, when self-atari attempt is detected, to play the other
63 * group's liberty if that is non-self-atari. */
65 /* Whether to always pick from moves capturing all groups in
66 * global_atari_check(). */
69 bool atari_def_no_hopeless
;
74 struct joseki_dict
*jdict
;
75 struct pattern3s patterns
;
77 /* Gamma values for queue tags - correspond to probabilities. */
79 double mq_prob
[MQ_MAX
], tenuki_prob
;
83 static char moggy_patterns_src
[][11] = {
84 /* hane pattern - enclosing hane */
88 /* hane pattern - non-cutting hane */
92 /* hane pattern - magari */
96 /* hane pattern - thin hane */
100 /* generic pattern - katatsuke or diagonal attachment; similar to magari */
104 /* cut1 pattern (kiri) - unprotected cut */
108 /* cut1 pattern (kiri) - peeped cut */
112 /* cut2 pattern (de) */
116 /* cut keima (not in Mogo) */
119 "???", /* o?? has some pathological tsumego cases */
120 /* side pattern - chase */
124 /* side pattern - block side cut */
128 /* side pattern - block side connection */
132 /* side pattern - sagari (SUSPICIOUS) */
134 "x.x" /* Mogo has "x.?" */
135 "###" /* Mogo has "X" */,
136 /* side pattern - throw-in (SUSPICIOUS) */
142 /* side pattern - cut (SUSPICIOUS) */
145 "###" /* Mogo has "X" */,
146 /* side pattern - eye piercing:
157 #define moggy_patterns_src_n sizeof(moggy_patterns_src) / sizeof(moggy_patterns_src[0])
160 test_pattern3_here(struct playout_policy
*p
, struct board
*b
, struct move
*m
)
162 struct moggy_policy
*pp
= p
->data
;
163 /* Check if 3x3 pattern is matched by given move... */
164 if (!pattern3_move_here(&pp
->patterns
, b
, m
))
166 /* ...and the move is not obviously stupid. */
167 if (is_bad_selfatari(b
, m
->color
, m
->coord
))
169 /* Ladder moves are stupid. */
170 group_t atari_neighbor
= board_get_atari_neighbor(b
, m
->coord
, m
->color
);
171 if (atari_neighbor
&& is_ladder(b
, m
->coord
, atari_neighbor
))
177 apply_pattern_here(struct playout_policy
*p
, struct board
*b
, coord_t c
, enum stone color
, struct move_queue
*q
)
179 struct move m2
= { .coord
= c
, .color
= color
};
180 if (board_is_valid_move(b
, &m2
) && test_pattern3_here(p
, b
, &m2
))
181 mq_add(q
, c
, 1<<MQ_PAT3
);
184 /* Check if we match any pattern around given move (with the other color to play). */
186 apply_pattern(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct move
*mm
, struct move_queue
*q
)
188 /* Suicides do not make any patterns and confuse us. */
189 if (board_at(b
, m
->coord
) == S_NONE
|| board_at(b
, m
->coord
) == S_OFFBOARD
)
192 foreach_8neighbor(b
, m
->coord
) {
193 apply_pattern_here(p
, b
, c
, stone_other(m
->color
), q
);
194 } foreach_8neighbor_end
;
196 if (mm
) { /* Second move for pattern searching */
197 foreach_8neighbor(b
, mm
->coord
) {
198 if (coord_is_8adjecent(m
->coord
, c
, b
))
200 apply_pattern_here(p
, b
, c
, stone_other(m
->color
), q
);
201 } foreach_8neighbor_end
;
205 mq_print(q
, b
, "Pattern");
210 joseki_check(struct playout_policy
*p
, struct board
*b
, enum stone to_play
, struct move_queue
*q
)
212 struct moggy_policy
*pp
= p
->data
;
216 for (int i
= 0; i
< 4; i
++) {
217 hash_t h
= b
->qhash
[i
] & joseki_hash_mask
;
218 coord_t
*cc
= pp
->jdict
->patterns
[h
].moves
[to_play
];
220 for (; !is_pass(*cc
); cc
++) {
221 if (coord_quadrant(*cc
, b
) != i
)
223 mq_add(q
, *cc
, 1<<MQ_JOSEKI
);
227 if (q
->moves
> 0 && PLDEBUGL(5))
228 mq_print(q
, b
, "Joseki");
232 global_atari_check(struct playout_policy
*p
, struct board
*b
, enum stone to_play
, struct move_queue
*q
)
237 struct moggy_policy
*pp
= p
->data
;
238 if (pp
->capcheckall
) {
239 for (int g
= 0; g
< b
->clen
; g
++)
240 group_atari_check(pp
->alwaysccaprate
, b
, group_at(b
, group_base(b
->c
[g
])), to_play
, q
, NULL
, 1<<MQ_GATARI
);
242 mq_print(q
, b
, "Global atari");
246 int g_base
= fast_random(b
->clen
);
247 for (int g
= g_base
; g
< b
->clen
; g
++) {
248 group_atari_check(pp
->alwaysccaprate
, b
, group_at(b
, group_base(b
->c
[g
])), to_play
, q
, NULL
, 1<<MQ_GATARI
);
250 /* XXX: Try carrying on. */
252 mq_print(q
, b
, "Global atari");
256 for (int g
= 0; g
< g_base
; g
++) {
257 group_atari_check(pp
->alwaysccaprate
, b
, group_at(b
, group_base(b
->c
[g
])), to_play
, q
, NULL
, 1<<MQ_GATARI
);
259 /* XXX: Try carrying on. */
261 mq_print(q
, b
, "Global atari");
269 local_atari_check(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct move_queue
*q
)
271 struct moggy_policy
*pp
= p
->data
;
273 /* Did the opponent play a self-atari? */
274 if (board_group_info(b
, group_at(b
, m
->coord
)).libs
== 1) {
275 group_atari_check(pp
->alwaysccaprate
, b
, group_at(b
, m
->coord
), stone_other(m
->color
), q
, NULL
, 1<<MQ_LATARI
);
278 foreach_neighbor(b
, m
->coord
, {
279 group_t g
= group_at(b
, c
);
280 if (!g
|| board_group_info(b
, g
).libs
!= 1)
282 group_atari_check(pp
->alwaysccaprate
, b
, g
, stone_other(m
->color
), q
, NULL
, 1<<MQ_LATARI
);
286 mq_print(q
, b
, "Local atari");
291 local_2lib_check(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct move_queue
*q
)
293 struct moggy_policy
*pp
= p
->data
;
295 /* Does the opponent have just two liberties? */
296 if (board_group_info(b
, group_at(b
, m
->coord
)).libs
== 2) {
297 group_2lib_check(b
, group_at(b
, m
->coord
), stone_other(m
->color
), q
, 1<<MQ_L2LIB
, pp
->atari_miaisafe
, pp
->atari_def_no_hopeless
);
299 /* We always prefer to take off an enemy chain liberty
300 * before pulling out ourselves. */
301 /* XXX: We aren't guaranteed to return to that group
304 return q
->move
[fast_random(q
->moves
)];
308 /* Then he took a third liberty from neighboring chain? */
309 foreach_neighbor(b
, m
->coord
, {
310 group_t g
= group_at(b
, c
);
311 if (!g
|| board_group_info(b
, g
).libs
!= 2)
313 group_2lib_check(b
, g
, stone_other(m
->color
), q
, 1<<MQ_L2LIB
, pp
->atari_miaisafe
, pp
->atari_def_no_hopeless
);
317 mq_print(q
, b
, "Local 2lib");
321 local_nlib_check(struct playout_policy
*p
, struct board
*b
, struct move
*m
, struct move_queue
*q
)
323 struct moggy_policy
*pp
= p
->data
;
324 enum stone color
= stone_other(m
->color
);
326 /* Attacking N-liberty groups in general is probably
327 * not feasible. What we are primarily concerned about is
328 * counter-attacking groups that have two physical liberties,
329 * but three effective liberties:
338 * The time for this to come is when the opponent took a liberty
339 * of ours, making a few-liberty group. Therefore, we focus
342 * There is a tradeoff - down to how many liberties we need to
343 * be to start looking? nlib_count=3 will work for the left black
344 * group (2lib-solver will suggest connecting the false eye), but
345 * not for top black group (it is too late to start playing 3-3
346 * capturing race). Also, we cannot prevent stupidly taking an
347 * outside liberty ourselves; the higher nlib_count, the higher
348 * the chance we withstand this.
350 * However, higher nlib_count means that we will waste more time
351 * checking non-urgent or alive groups, and we will play silly
352 * or wasted moves around alive groups. */
355 foreach_8neighbor(b
, m
->coord
) {
356 group_t g
= group_at(b
, c
);
357 if (!g
|| group2
== g
|| board_at(b
, c
) != color
)
359 if (board_group_info(b
, g
).libs
< 3 || board_group_info(b
, g
).libs
> pp
->nlib_count
)
361 group_nlib_defense_check(b
, g
, color
, q
, 1<<MQ_LNLIB
);
362 group2
= g
; // prevent trivial repeated checks
363 } foreach_8neighbor_end
;
366 mq_print(q
, b
, "Local nlib");
370 nakade_check(struct playout_policy
*p
, struct board
*b
, struct move
*m
, enum stone to_play
)
372 coord_t empty
= pass
;
373 foreach_neighbor(b
, m
->coord
, {
374 if (board_at(b
, c
) != S_NONE
)
376 if (is_pass(empty
)) {
380 if (!coord_is_8adjecent(c
, empty
, b
)) {
381 /* Seems like impossible nakade
386 assert(!is_pass(empty
));
388 coord_t nakade
= nakade_point(b
, empty
, stone_other(to_play
));
389 if (PLDEBUGL(5) && !is_pass(nakade
))
390 fprintf(stderr
, "Nakade: %s\n", coord2sstr(nakade
, b
));
395 fillboard_check(struct playout_policy
*p
, struct board
*b
)
397 struct moggy_policy
*pp
= p
->data
;
398 unsigned int fbtries
= b
->flen
/ 8;
399 if (pp
->fillboardtries
< fbtries
)
400 fbtries
= pp
->fillboardtries
;
402 for (unsigned int i
= 0; i
< fbtries
; i
++) {
403 coord_t coord
= b
->f
[fast_random(b
->flen
)];
404 if (immediate_liberty_count(b
, coord
) != 4)
406 foreach_diag_neighbor(b
, coord
) {
407 if (board_at(b
, c
) != S_NONE
)
409 } foreach_diag_neighbor_end
;
418 playout_moggy_seqchoose(struct playout_policy
*p
, struct playout_setup
*s
, struct board
*b
, enum stone to_play
)
420 struct moggy_policy
*pp
= p
->data
;
423 board_print(b
, stderr
);
426 if (!is_pass(b
->last_ko
.coord
) && is_pass(b
->ko
.coord
)
427 && b
->moves
- b
->last_ko_age
< pp
->koage
428 && pp
->korate
> fast_random(100)) {
429 if (board_is_valid_play(b
, to_play
, b
->last_ko
.coord
)
430 && !is_bad_selfatari(b
, to_play
, b
->last_ko
.coord
))
431 return b
->last_ko
.coord
;
435 if (!is_pass(b
->last_move
.coord
)) {
437 if (pp
->nakaderate
> fast_random(100)
438 && immediate_liberty_count(b
, b
->last_move
.coord
) > 0) {
439 coord_t nakade
= nakade_check(p
, b
, &b
->last_move
, to_play
);
440 if (!is_pass(nakade
))
444 /* Local group in atari? */
445 if (pp
->lcapturerate
> fast_random(100)) {
446 struct move_queue q
; q
.moves
= 0;
447 local_atari_check(p
, b
, &b
->last_move
, &q
);
452 /* Local group can be PUT in atari? */
453 if (pp
->atarirate
> fast_random(100)) {
454 struct move_queue q
; q
.moves
= 0;
455 local_2lib_check(p
, b
, &b
->last_move
, &q
);
460 /* Local group reduced some of our groups to 3 libs? */
461 if (pp
->nlibrate
> fast_random(100)) {
462 struct move_queue q
; q
.moves
= 0;
463 local_nlib_check(p
, b
, &b
->last_move
, &q
);
468 /* Check for patterns we know */
469 if (pp
->patternrate
> fast_random(100)) {
470 struct move_queue q
; q
.moves
= 0;
471 apply_pattern(p
, b
, &b
->last_move
,
472 pp
->pattern2
&& b
->last_move2
.coord
>= 0 ? &b
->last_move2
: NULL
,
481 /* Any groups in atari? */
482 if (pp
->capturerate
> fast_random(100)) {
483 struct move_queue q
; q
.moves
= 0;
484 global_atari_check(p
, b
, to_play
, &q
);
490 if (pp
->josekirate
> fast_random(100)) {
491 struct move_queue q
; q
.moves
= 0;
492 joseki_check(p
, b
, to_play
, &q
);
498 if (pp
->fillboardtries
> 0) {
499 coord_t c
= fillboard_check(p
, b
);
507 /* Pick a move from queue q, giving different likelihoods to moves
508 * based on their tags. */
510 mq_tagged_choose(struct playout_policy
*p
, struct board
*b
, enum stone to_play
, struct move_queue
*q
)
512 struct moggy_policy
*pp
= p
->data
;
514 /* First, merge all entries for a move. */
515 /* We use a naive O(N^2) since the average length of the queue
517 for (unsigned int i
= 0; i
< q
->moves
; i
++) {
518 for (unsigned int j
= i
+ 1; j
< q
->moves
; j
++) {
519 if (q
->move
[i
] != q
->move
[j
])
521 q
->tag
[i
] |= q
->tag
[j
];
523 q
->tag
[j
] = q
->tag
[q
->moves
];
524 q
->move
[j
] = q
->move
[q
->moves
];
528 /* Now, construct a probdist. */
531 for (unsigned int i
= 0; i
< q
->moves
; i
++) {
533 assert(q
->tag
[i
] != 0);
534 for (int j
= 0; j
< MQ_MAX
; j
++)
535 if (q
->tag
[i
] & (1<<j
)) {
536 //fprintf(stderr, "%s(%x) %d %f *= %f\n", coord2sstr(q->move[i], b), q->tag[i], j, val, pp->mq_prob[j]);
537 val
*= pp
->mq_prob
[j
];
539 pd
[i
] = double_to_fixp(val
);
542 total
+= double_to_fixp(pp
->tenuki_prob
);
544 /* Finally, pick a move! */
545 fixp_t stab
= fast_irandom(total
);
546 for (unsigned int i
= 0; i
< q
->moves
; i
++) {
547 //fprintf(stderr, "%s(%x) %f (%f/%f)\n", coord2sstr(q->move[i], b), q->tag[i], fixp_to_double(stab), fixp_to_double(pd[i]), fixp_to_double(total));
554 assert(stab
< double_to_fixp(pp
->tenuki_prob
));
559 playout_moggy_fullchoose(struct playout_policy
*p
, struct playout_setup
*s
, struct board
*b
, enum stone to_play
)
561 struct moggy_policy
*pp
= p
->data
;
562 struct move_queue q
; q
.moves
= 0;
565 board_print(b
, stderr
);
568 if (!is_pass(b
->last_ko
.coord
) && is_pass(b
->ko
.coord
)
569 && b
->moves
- b
->last_ko_age
< pp
->koage
) {
570 if (board_is_valid_play(b
, to_play
, b
->last_ko
.coord
)
571 && !is_bad_selfatari(b
, to_play
, b
->last_ko
.coord
))
572 mq_add(&q
, b
->last_ko
.coord
, 1<<MQ_KO
);
576 if (!is_pass(b
->last_move
.coord
)) {
578 if (immediate_liberty_count(b
, b
->last_move
.coord
) > 0) {
579 coord_t nakade
= nakade_check(p
, b
, &b
->last_move
, to_play
);
580 if (!is_pass(nakade
))
581 mq_add(&q
, nakade
, 1<<MQ_NAKADE
);
584 /* Local group in atari? */
585 local_atari_check(p
, b
, &b
->last_move
, &q
);
587 /* Local group can be PUT in atari? */
588 local_2lib_check(p
, b
, &b
->last_move
, &q
);
590 /* Local group reduced some of our groups to 3 libs? */
591 local_nlib_check(p
, b
, &b
->last_move
, &q
);
593 /* Check for patterns we know */
594 apply_pattern(p
, b
, &b
->last_move
,
595 pp
->pattern2
&& b
->last_move2
.coord
>= 0 ? &b
->last_move2
: NULL
,
601 /* Any groups in atari? */
602 global_atari_check(p
, b
, to_play
, &q
);
605 joseki_check(p
, b
, to_play
, &q
);
608 /* Average length of the queue is 1.4 move. */
609 printf("MQL %d ", q
.moves
);
610 for (unsigned int i
= 0; i
< q
.moves
; i
++)
611 printf("%s ", coord2sstr(q
.move
[i
], b
));
616 return mq_tagged_choose(p
, b
, to_play
, &q
);
619 if (pp
->fillboardtries
> 0) {
620 coord_t c
= fillboard_check(p
, b
);
630 playout_moggy_assess_group(struct playout_policy
*p
, struct prior_map
*map
, group_t g
, int games
)
632 struct moggy_policy
*pp
= p
->data
;
633 struct board
*b
= map
->b
;
634 struct move_queue q
; q
.moves
= 0;
636 if (board_group_info(b
, g
).libs
> pp
->nlib_count
)
640 fprintf(stderr
, "ASSESS of group %s:\n", coord2sstr(g
, b
));
641 board_print(b
, stderr
);
644 if (board_group_info(b
, g
).libs
> 2) {
647 if (board_at(b
, g
) != map
->to_play
)
648 return; // we do only defense
649 group_nlib_defense_check(b
, g
, map
->to_play
, &q
, 0);
651 coord_t coord
= q
.move
[q
.moves
];
653 fprintf(stderr
, "1.0: nlib %s\n", coord2sstr(coord
, b
));
654 int assess
= games
/ 2;
655 add_prior_value(map
, coord
, 1, assess
);
660 if (board_group_info(b
, g
).libs
== 2) {
663 group_2lib_check(b
, g
, map
->to_play
, &q
, 0, pp
->atari_miaisafe
, pp
->atari_def_no_hopeless
);
665 coord_t coord
= q
.move
[q
.moves
];
667 fprintf(stderr
, "1.0: 2lib %s\n", coord2sstr(coord
, b
));
668 int assess
= games
/ 2;
669 add_prior_value(map
, coord
, 1, assess
);
674 /* This group, sir, is in atari! */
676 coord_t ladder
= pass
;
677 group_atari_check(pp
->alwaysccaprate
, b
, g
, map
->to_play
, &q
, &ladder
, 0);
679 coord_t coord
= q
.move
[q
.moves
];
681 /* _Never_ play here if this move plays out
682 * a caught ladder. */
683 if (coord
== ladder
&& !board_playing_ko_threat(b
)) {
684 /* Note that the opposite is not guarded against;
685 * we do not advise against capturing a laddered
686 * group (but we don't encourage it either). Such
687 * a move can simplify tactical situations if we
689 if (map
->to_play
!= board_at(b
, g
))
691 /* FIXME: We give the malus even if this move
692 * captures another group. */
694 fprintf(stderr
, "0.0: ladder %s\n", coord2sstr(coord
, b
));
695 add_prior_value(map
, coord
, 0, games
);
699 if (!pp
->capturerate
&& !pp
->lcapturerate
)
703 fprintf(stderr
, "1.0: atari %s\n", coord2sstr(coord
, b
));
704 int assess
= games
* 2;
705 add_prior_value(map
, coord
, 1, assess
);
710 playout_moggy_assess_one(struct playout_policy
*p
, struct prior_map
*map
, coord_t coord
, int games
)
712 struct moggy_policy
*pp
= p
->data
;
713 struct board
*b
= map
->b
;
716 fprintf(stderr
, "ASSESS of move %s:\n", coord2sstr(coord
, b
));
717 board_print(b
, stderr
);
720 /* Is this move a self-atari? */
721 if (pp
->selfatarirate
) {
722 if (!board_playing_ko_threat(b
) && is_bad_selfatari(b
, map
->to_play
, coord
)) {
724 fprintf(stderr
, "0.0: self-atari\n");
725 add_prior_value(map
, coord
, 0, games
);
726 if (!pp
->selfatari_other
)
728 /* If we can play on the other liberty of the
729 * endangered group, do! */
730 coord
= selfatari_cousin(b
, map
->to_play
, coord
);
734 fprintf(stderr
, "1.0: self-atari redirect %s\n", coord2sstr(coord
, b
));
735 add_prior_value(map
, coord
, 1.0, games
);
741 if (pp
->patternrate
) {
742 struct move m
= { .color
= map
->to_play
, .coord
= coord
};
743 if (test_pattern3_here(p
, b
, &m
)) {
745 fprintf(stderr
, "1.0: pattern\n");
746 add_prior_value(map
, coord
, 1, games
);
754 playout_moggy_assess(struct playout_policy
*p
, struct prior_map
*map
, int games
)
756 struct moggy_policy
*pp
= p
->data
;
758 /* First, go through all endangered groups. */
759 for (group_t g
= 1; g
< board_size2(map
->b
); g
++)
760 if (group_at(map
->b
, g
) == g
)
761 playout_moggy_assess_group(p
, map
, g
, games
);
763 /* Then, assess individual moves. */
764 if (!pp
->patternrate
&& !pp
->selfatarirate
)
766 foreach_free_point(map
->b
) {
767 if (map
->consider
[c
])
768 playout_moggy_assess_one(p
, map
, c
, games
);
769 } foreach_free_point_end
;
773 playout_moggy_permit(struct playout_policy
*p
, struct board
*b
, struct move
*m
)
775 struct moggy_policy
*pp
= p
->data
;
777 /* The idea is simple for now - never allow self-atari moves.
778 * They suck in general, but this also permits us to actually
779 * handle seki in the playout stage. */
781 if (fast_random(100) >= pp
->selfatarirate
) {
783 fprintf(stderr
, "skipping sar test\n");
786 bool selfatari
= is_bad_selfatari(b
, m
->color
, m
->coord
);
789 fprintf(stderr
, "__ Prohibiting self-atari %s %s\n",
790 stone2str(m
->color
), coord2sstr(m
->coord
, b
));
791 if (pp
->selfatari_other
) {
792 /* Ok, try the other liberty of the atari'd group. */
793 coord_t c
= selfatari_cousin(b
, m
->color
, m
->coord
);
794 if (is_pass(c
)) return false;
796 fprintf(stderr
, "___ Redirecting to other lib %s\n",
807 struct playout_policy
*
808 playout_moggy_init(char *arg
, struct board
*b
, struct joseki_dict
*jdict
)
810 struct playout_policy
*p
= calloc2(1, sizeof(*p
));
811 struct moggy_policy
*pp
= calloc2(1, sizeof(*pp
));
813 p
->choose
= playout_moggy_seqchoose
;
814 p
->assess
= playout_moggy_assess
;
815 p
->permit
= playout_moggy_permit
;
819 /* These settings are tuned for 19x19 play with several threads
820 * on reasonable time limits (i.e., rather large number of playouts).
821 * XXX: no 9x9 tuning has been done recently. */
822 int rate
= board_large(b
) ? 80 : 90;
824 pp
->lcapturerate
= pp
->atarirate
= pp
->nlibrate
= pp
->patternrate
825 = pp
->selfatarirate
= pp
->josekirate
= -1U;
826 if (board_large(b
)) {
827 pp
->lcapturerate
= pp
->patternrate
= 100;
831 pp
->korate
= 20; pp
->koage
= 4;
832 pp
->alwaysccaprate
= 20;
833 pp
->selfatari_other
= true;
834 pp
->atari_def_no_hopeless
= !board_large(b
);
835 pp
->atari_miaisafe
= true;
839 double mq_prob_default
[MQ_MAX
] = {
849 memcpy(pp
->mq_prob
, mq_prob_default
, sizeof(pp
->mq_prob
));
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
, "debug") && optval
) {
863 p
->debug_level
= atoi(optval
);
864 } else if (!strcasecmp(optname
, "lcapturerate") && optval
) {
865 pp
->lcapturerate
= atoi(optval
);
866 } else if (!strcasecmp(optname
, "atarirate") && optval
) {
867 pp
->atarirate
= atoi(optval
);
868 } else if (!strcasecmp(optname
, "nlibrate") && optval
) {
869 pp
->nlibrate
= atoi(optval
);
870 } else if (!strcasecmp(optname
, "capturerate") && optval
) {
871 pp
->capturerate
= atoi(optval
);
872 } else if (!strcasecmp(optname
, "patternrate") && optval
) {
873 pp
->patternrate
= atoi(optval
);
874 } else if (!strcasecmp(optname
, "selfatarirate") && optval
) {
875 pp
->selfatarirate
= atoi(optval
);
876 } else if (!strcasecmp(optname
, "korate") && optval
) {
877 pp
->korate
= atoi(optval
);
878 } else if (!strcasecmp(optname
, "josekirate") && optval
) {
879 pp
->josekirate
= atoi(optval
);
880 } else if (!strcasecmp(optname
, "nakaderate") && optval
) {
881 pp
->nakaderate
= atoi(optval
);
882 } else if (!strcasecmp(optname
, "alwaysccaprate") && optval
) {
883 pp
->alwaysccaprate
= atoi(optval
);
884 } else if (!strcasecmp(optname
, "rate") && optval
) {
886 } else if (!strcasecmp(optname
, "fillboardtries")) {
887 pp
->fillboardtries
= atoi(optval
);
888 } else if (!strcasecmp(optname
, "koage") && optval
) {
889 pp
->koage
= atoi(optval
);
890 } else if (!strcasecmp(optname
, "pattern2")) {
891 pp
->pattern2
= optval
&& *optval
== '0' ? false : true;
892 } else if (!strcasecmp(optname
, "selfatari_other")) {
893 pp
->selfatari_other
= optval
&& *optval
== '0' ? false : true;
894 } else if (!strcasecmp(optname
, "capcheckall")) {
895 pp
->capcheckall
= optval
&& *optval
== '0' ? false : true;
896 } else if (!strcasecmp(optname
, "atari_miaisafe")) {
897 pp
->atari_miaisafe
= optval
&& *optval
== '0' ? false : true;
898 } else if (!strcasecmp(optname
, "atari_def_no_hopeless")) {
899 pp
->atari_def_no_hopeless
= optval
&& *optval
== '0' ? false : true;
900 } else if (!strcasecmp(optname
, "nlib_count") && optval
) {
901 pp
->nlib_count
= atoi(optval
);
902 } else if (!strcasecmp(optname
, "fullchoose")) {
903 p
->choose
= optval
&& *optval
== '0' ? playout_moggy_seqchoose
: playout_moggy_fullchoose
;
904 } else if (!strcasecmp(optname
, "mqprob") && optval
) {
905 /* KO%LATARI%L2LIB%LNLIB%PAT3%GATARI%JOSEKI%NAKADE */
906 for (int i
= 0; *optval
&& i
< MQ_MAX
; i
++, optval
+= strcspn(optval
, "%")) {
908 pp
->mq_prob
[i
] = atof(optval
);
910 } else if (!strcasecmp(optname
, "tenukiprob") && optval
) {
911 pp
->tenuki_prob
= atof(optval
);
913 fprintf(stderr
, "playout-moggy: Invalid policy argument %s or missing value\n", optname
);
918 if (pp
->lcapturerate
== -1U) pp
->lcapturerate
= rate
;
919 if (pp
->atarirate
== -1U) pp
->atarirate
= rate
;
920 if (pp
->capturerate
== -1U) pp
->capturerate
= rate
;
921 if (pp
->patternrate
== -1U) pp
->patternrate
= rate
;
922 if (pp
->selfatarirate
== -1U) pp
->selfatarirate
= rate
;
923 if (pp
->korate
== -1U) pp
->korate
= rate
;
924 if (pp
->josekirate
== -1U) pp
->josekirate
= rate
;
925 if (pp
->nakaderate
== -1U) pp
->nakaderate
= rate
;
926 if (pp
->alwaysccaprate
== -1U) pp
->alwaysccaprate
= rate
;
928 pattern3s_init(&pp
->patterns
, moggy_patterns_src
, moggy_patterns_src_n
);