7 #include "joseki/base.h"
10 #include "playout/light.h"
11 #include "playout/moggy.h"
12 #include "replay/replay.h"
15 /* Internal engine state. */
18 struct playout_policy
*playout
;
23 replay_genmove(struct engine
*e
, struct board
*b
, struct time_info
*ti
, enum stone color
, bool pass_all_alive
)
25 struct replay
*r
= e
->data
;
26 struct playout_setup s
; memset(&s
, 0, sizeof(s
));
28 coord_t coord
= r
->playout
->choose(r
->playout
, &s
, b
, color
);
30 if (!is_pass(coord
)) {
32 m
.coord
= coord
; m
.color
= color
;
33 if (board_play(b
, &m
) >= 0)
37 fprintf(stderr
, "Pre-picked move %d,%d is ILLEGAL:\n",
38 coord_x(coord
, b
), coord_y(coord
, b
));
39 board_print(b
, stderr
);
43 /* Defer to uniformly random move choice. */
44 board_play_random(b
, color
, &coord
, (ppr_permit
) r
->playout
->permit
, r
->playout
);
47 if (!group_at(b
, coord
)) {
48 /* This was suicide. Just pass. */
49 /* XXX: We should check for non-suicide alternatives. */
53 return coord_copy(coord
);
58 replay_state_init(char *arg
, struct board
*b
)
60 struct replay
*r
= calloc2(1, sizeof(struct replay
));
65 char *optspec
, *next
= arg
;
68 next
+= strcspn(next
, ",");
69 if (*next
) { *next
++ = 0; } else { *next
= 0; }
71 char *optname
= optspec
;
72 char *optval
= strchr(optspec
, '=');
73 if (optval
) *optval
++ = 0;
75 if (!strcasecmp(optname
, "debug")) {
77 r
->debug_level
= atoi(optval
);
80 } else if (!strcasecmp(optname
, "playout") && optval
) {
81 char *playoutarg
= strchr(optval
, ':');
84 if (!strcasecmp(optval
, "moggy")) {
85 r
->playout
= playout_moggy_init(playoutarg
, b
, joseki_load(b
->size
));
86 } else if (!strcasecmp(optval
, "light")) {
87 r
->playout
= playout_light_init(playoutarg
, b
);
89 fprintf(stderr
, "Replay: Invalid playout policy %s\n", optval
);
92 fprintf(stderr
, "Replay: Invalid engine argument %s or missing value\n", optname
);
98 r
->playout
= playout_light_init(NULL
, b
);
99 r
->playout
->debug_level
= r
->debug_level
;
105 engine_replay_init(char *arg
, struct board
*b
)
107 struct replay
*r
= replay_state_init(arg
, b
);
108 struct engine
*e
= calloc2(1, sizeof(struct engine
));
109 e
->name
= "PlayoutReplay Engine";
110 e
->comment
= "I select moves blindly according to playout policy. I won't pass as long as there is a place on the board where I can play. When we both pass, I will consider all the stones on the board alive.";
111 e
->genmove
= replay_genmove
;