From 1d6b21929680e7c4f403ede90ec89526dc786058 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 3 Dec 2010 04:41:13 +0100 Subject: [PATCH] fbook: In case of multiple candidates, pick a semi-random one instead of the first one --- fbook.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fbook.c b/fbook.c index 3713d3f..da08db8 100644 --- a/fbook.c +++ b/fbook.c @@ -6,6 +6,7 @@ #include "board.h" #include "debug.h" #include "fbook.h" +#include "random.h" static coord_t @@ -91,6 +92,14 @@ fbook_init(char *filename, struct board *b) line++; while (isspace(*line)) line++; + /* In case of multiple candidates, pick one with + * exponentially decreasing likelihood. */ + while (strchr(line, ' ') && fast_random(2)) { + line = strchr(line, ' '); + while (isspace(*line)) line++; + // fprintf(stderr, "<%s> skip to %s\n", linebuf, line); + } + coord_t *c = str2coord(line, fbook->bsize); for (int i = 0; i < 8; i++) { coord_t coord = coord_transform(b, *c, i); -- 2.11.4.GIT