Probdist: Change from cummulative probabilities back to individual ones
[pachi/json.git] / pattern_byplayer.sh
blobc2df0232e98c675d7a921ffa5a985150d469a1de
1 #!/bin/sh
2 # pattern_byplayer - Build a per-player database of used patterns
4 # Invoke this script for each played game, it will add patterns
5 # to the database incrementally; each file in the database contains
6 # patterns played by one player.
8 # You must already have a spatial dictionary generated.
10 dbdir="$1"; shift
11 sgf="$1"; shift
12 # rest of parameters is passed to the patternscan engine
14 sgf_attr() {
15 # GNU sed mishandles CRLF lines
16 cat "$sgf" | tr -d '\r' | sed -n -e 's/'$1'\[\([^]]*\)\]/\1/p'
19 black="$(sgf_attr PB)"
20 white="$(sgf_attr PW)"
21 handi="$(sgf_attr HA)"
23 if [ -n "$handi" ] && [ "$handi" -gt 0 ]; then
24 to_play=white
25 # Comment following out if you want to include handi games.
26 echo "$sgf: Skipping handicap game" >&2
27 exit 1
30 to_play=black
31 ./sgf2gtp.pl "$sgf" | ./zzgo -d 0 -e patternscan "$@" |
32 sed -n -e 's/^= //p' | grep -v '^ *$' | # skip irrelevant replies
33 while read pattern; do
34 if [ "$to_play" = black ]; then
35 player="$black"
36 to_play=white
37 else
38 player="$white"
39 to_play=black
41 echo "$pattern" >>"$dbdir/$player"
42 done