From 2b5458bd0eadd27bbf256765d49deac3893ad861 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 8 Jan 2012 19:27:56 +0100 Subject: [PATCH] Patternscan: Change output format, clearly identify winner and witnesses --- patternscan/patternscan.c | 22 +++++++++++++++++++++- tools/pattern_bayes_gen.sh | 12 +++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/patternscan/patternscan.c b/patternscan/patternscan.c index b8ef060..5ee8dc4 100644 --- a/patternscan/patternscan.c +++ b/patternscan/patternscan.c @@ -12,6 +12,19 @@ #include "random.h" +/* The engine has two modes: + * + * * gen_spat_dict=1: patterns.spat file is generated with a list of all + * encountered spatials + * + * * gen_spat_dict=0,no_pattern_match=1: all encountered patterns are + * listed on output on each move; the general format is + * [(winpattern)] + * but with competition=1 it is + * [(winpattern)] [(witnesspattern0) (witnesspattern1) ...] + */ + + /* Internal engine state. */ struct patternscan { int debug_level; @@ -97,20 +110,27 @@ patternscan_play(struct engine *e, struct board *b, struct move *m) /* Scan for supported features. */ /* For specifiation of features and their payloads, * please refer to pattern.h. */ + *strp++ = '['; process_pattern(ps, b, m, &strp); + *strp++ = ']'; if (ps->competition) { /* Look at other possible moves as well. */ + *strp++ = ' '; + *strp++ = '['; for (int f = 0; f < b->flen; f++) { struct move mo = { .coord = b->f[f], .color = m->color }; if (is_pass(mo.coord)) continue; if (!board_is_valid_move(b, &mo)) continue; - *strp++ = ' '; + if (strp[-1] != '[') + *strp++ = ' '; process_pattern(ps, b, &mo, &strp); } + *strp++ = ']'; } + *strp++ = 0; return ps->no_pattern_match ? NULL : str; } diff --git a/tools/pattern_bayes_gen.sh b/tools/pattern_bayes_gen.sh index dfff880..8caea3c 100755 --- a/tools/pattern_bayes_gen.sh +++ b/tools/pattern_bayes_gen.sh @@ -8,12 +8,14 @@ s/^= // or next; chomp; - s/\) \(/),(/g; - @a = split(/,/); + my ($winner, $witness) = (/^\[(.*)\] \[(.*)\]$/); - $win = shift @a; - $choices{$win}++; - for (uniq @a) { + sub parse { $_ = $_[0]; s/\) \(/),(/g; return split(/,/); } + + for (uniq(parse($winner))) { + $choices{$_}++; + } + for (uniq(parse($witness))) { $counts{$_}++; } -- 2.11.4.GIT