Preserve rules over board_clear()
[pachi/nmclean.git] / tools / pattern_getdrops.pl
blob99bff56d12a69cc12c5f31c28e0addc7b8a73d6e
1 #!/usr/bin/perl -n
3 # pattern_getdrops - Find significant value drops in kgslog GTP stream
4 # and convert them to lead-in game records for pattern learning
6 # Run as pipeline:
7 # tools/kgslog2gtp.pl | tools/pattern_getdrops.pl | tools/pattern_bayes_gen.sh -
9 BEGIN {
10 use vars qw(@game $lastval $valthres $valfrac);
11 $valthres = 0.8;
12 $valfrac = 0.95;
15 chomp;
16 @_ = split(/\s+/);
18 if ($_[0] eq 'pachi-mygame') {
19 @game = @_[1..4];
20 print STDERR "*** new game [@game]\n";
21 $lastval = 0;
22 @commands = ();
24 } elsif ($_[0] eq 'pachi-mymove') {
25 if ($lastval > 0 and $lastval < $valthres and $_[2] / $lastval < $valfrac) {
26 print STDERR "large value drop $lastval -> $_[2] [@game :: @_]\n";
27 print "$_\n" for @commands;
28 print "play $game[0] $_[1] 1\n";
30 $lastval = $_[2];
31 my $cmd = "play $game[0] $_[1] 0 $_[2]";
32 push @commands, $cmd;
34 } elsif ($_[0] eq 'play') {
35 push @_, 0;
36 push @commands, "@_";
38 } else {
39 push @commands, "@_";