9 #include "playout/elo.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
;
27 coord_t coord
= r
->playout
->choose(r
->playout
, b
, color
);
29 if (!is_pass(coord
)) {
31 m
.coord
= coord
; m
.color
= color
;
32 if (board_play(b
, &m
) >= 0)
36 fprintf(stderr
, "Pre-picked move %d,%d is ILLEGAL:\n",
37 coord_x(coord
, b
), coord_y(coord
, b
));
38 board_print(b
, stderr
);
42 /* Defer to uniformly random move choice. */
43 board_play_random(b
, color
, &coord
, (ppr_permit
) r
->playout
->permit
, r
->playout
);
46 if (!group_at(b
, coord
)) {
47 /* This was suicide. Just pass. */
48 /* XXX: We should check for non-suicide alternatives. */
52 return coord_copy(coord
);
57 replay_state_init(char *arg
, struct board
*b
)
59 struct replay
*r
= calloc2(1, sizeof(struct replay
));
64 char *optspec
, *next
= arg
;
67 next
+= strcspn(next
, ",");
68 if (*next
) { *next
++ = 0; } else { *next
= 0; }
70 char *optname
= optspec
;
71 char *optval
= strchr(optspec
, '=');
72 if (optval
) *optval
++ = 0;
74 if (!strcasecmp(optname
, "debug")) {
76 r
->debug_level
= atoi(optval
);
79 } else if (!strcasecmp(optname
, "playout") && optval
) {
80 char *playoutarg
= strchr(optval
, ':');
83 if (!strcasecmp(optval
, "moggy")) {
84 r
->playout
= playout_moggy_init(playoutarg
, b
);
85 } else if (!strcasecmp(optval
, "light")) {
86 r
->playout
= playout_light_init(playoutarg
, b
);
87 } else if (!strcasecmp(optval
, "elo")) {
88 r
->playout
= playout_elo_init(playoutarg
, b
);
90 fprintf(stderr
, "Replay: Invalid playout policy %s\n", optval
);
93 fprintf(stderr
, "Replay: Invalid engine argument %s or missing value\n", optname
);
99 r
->playout
= playout_light_init(NULL
, b
);
100 r
->playout
->debug_level
= r
->debug_level
;
106 engine_replay_init(char *arg
, struct board
*b
)
108 struct replay
*r
= replay_state_init(arg
, b
);
109 struct engine
*e
= calloc2(1, sizeof(struct engine
));
110 e
->name
= "PlayoutReplay Engine";
111 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.";
112 e
->genmove
= replay_genmove
;