7 #include "joseki/base.h"
10 #include "playout/elo.h"
11 #include "playout/light.h"
12 #include "playout/moggy.h"
13 #include "replay/replay.h"
16 /* Internal engine state. */
19 struct playout_policy
*playout
;
24 replay_genmove(struct engine
*e
, struct board
*b
, struct time_info
*ti
, enum stone color
, bool pass_all_alive
)
26 struct replay
*r
= e
->data
;
27 struct playout_setup s
; memset(&s
, 0, sizeof(s
));
29 coord_t coord
= r
->playout
->choose(r
->playout
, &s
, b
, color
);
31 if (!is_pass(coord
)) {
33 m
.coord
= coord
; m
.color
= color
;
34 if (board_play(b
, &m
) >= 0)
38 fprintf(stderr
, "Pre-picked move %d,%d is ILLEGAL:\n",
39 coord_x(coord
, b
), coord_y(coord
, b
));
40 board_print(b
, stderr
);
44 /* Defer to uniformly random move choice. */
45 board_play_random(b
, color
, &coord
, (ppr_permit
) r
->playout
->permit
, r
->playout
);
48 if (!group_at(b
, coord
)) {
49 /* This was suicide. Just pass. */
50 /* XXX: We should check for non-suicide alternatives. */
54 return coord_copy(coord
);
59 replay_state_init(char *arg
, struct board
*b
)
61 struct replay
*r
= calloc2(1, sizeof(struct replay
));
66 char *optspec
, *next
= arg
;
69 next
+= strcspn(next
, ",");
70 if (*next
) { *next
++ = 0; } else { *next
= 0; }
72 char *optname
= optspec
;
73 char *optval
= strchr(optspec
, '=');
74 if (optval
) *optval
++ = 0;
76 if (!strcasecmp(optname
, "debug")) {
78 r
->debug_level
= atoi(optval
);
81 } else if (!strcasecmp(optname
, "playout") && optval
) {
82 char *playoutarg
= strchr(optval
, ':');
85 if (!strcasecmp(optval
, "moggy")) {
86 r
->playout
= playout_moggy_init(playoutarg
, b
, joseki_load(b
->size
));
87 } else if (!strcasecmp(optval
, "light")) {
88 r
->playout
= playout_light_init(playoutarg
, b
);
89 } else if (!strcasecmp(optval
, "elo")) {
90 r
->playout
= playout_elo_init(playoutarg
, b
);
92 fprintf(stderr
, "Replay: Invalid playout policy %s\n", optval
);
95 fprintf(stderr
, "Replay: Invalid engine argument %s or missing value\n", optname
);
101 r
->playout
= playout_light_init(NULL
, b
);
102 r
->playout
->debug_level
= r
->debug_level
;
108 engine_replay_init(char *arg
, struct board
*b
)
110 struct replay
*r
= replay_state_init(arg
, b
);
111 struct engine
*e
= calloc2(1, sizeof(struct engine
));
112 e
->name
= "PlayoutReplay Engine";
113 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.";
114 e
->genmove
= replay_genmove
;