Moggy: Do not play 'lumpy' 2-lib moves
[pachi.git] / random / random.c
blobc0c9356187c8b1e0a8df92aa7e9c399bb343a18b
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 /* Play a random coordinate. However, we must also guard
13 * against suicide moves; repeat playing while it's a suicide
14 * unless we keep suiciding; in that case, we probably don't
15 * have any other moves available and we pass. */
16 coord_t coord;
17 int i = 0; bool suicide = false;
19 do {
20 /* board_play_random() actually plays the move too;
21 * this is desirable for MC simulations but not within
22 * the genmove. Make a scratch new board for it. */
23 struct board b2;
24 board_copy(&b2, b);
26 board_play_random(&b2, color, &coord, NULL, NULL);
28 suicide = (coord != pass && !group_at(&b2, coord));
29 board_done_noalloc(&b2);
30 } while (suicide && i++ < 100);
32 return coord_copy(suicide ? pass : coord);
35 struct engine *
36 engine_random_init(char *arg, struct board *b)
38 struct engine *e = calloc2(1, sizeof(struct engine));
39 e->name = "RandomMove Engine";
40 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.";
41 e->genmove = random_genmove;
43 if (arg)
44 fprintf(stderr, "Random: I support no engine arguments\n");
46 return e;