time_in_byoyomi(): Rewrite, smoother to read and more flexible now
[pachi.git] / random / random.c
blob029a96bfb1b0201806c19009ddb17c8839e18188
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "board.h"
5 #include "engine.h"
6 #include "move.h"
7 #include "random/random.h"
9 static coord_t *
10 random_genmove(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive)
12 coord_t coord;
13 board_play_random(b, color, &coord, NULL, NULL);
14 if (!group_at(b, coord)) {
15 /* This was suicide. Just pass. */
16 /* XXX: We should check for non-suicide alternatives. */
17 return coord_pass();
20 return coord_copy(coord);
23 struct engine *
24 engine_random_init(char *arg, struct board *b)
26 struct engine *e = calloc(1, sizeof(struct engine));
27 e->name = "RandomMove Engine";
28 e->comment = "I just make random moves. 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.";
29 e->genmove = random_genmove;
31 if (arg)
32 fprintf(stderr, "Random: I support no engine arguments\n");
34 return e;