board_undo: define QUICK_BOARD_CODE to get compiler error with forbidden fields.
[pachi.git] / tools / pattern_byplayer.sh
blob1e82c3eafbf8e0a96a41b08b76a4f54df09ba25c
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 # TODO: Does not work correctly for attributes containing escaped ]
16 # e.g. "PB[Tony \[Killer\] Nowak]" gets cropped to "Tony \[Killer"
17 # Not a big problem, since usually the player name is just
18 # [a-zA-Z0-9]*
20 sed -n 's/^.*'$1'\[\([^]]*\)\].*$/\1/p' "$sgf"
23 black="$(sgf_attr PB)"
24 white="$(sgf_attr PW)"
25 handi="$(sgf_attr HA)"
27 if [ -n "$handi" ] && [ "$handi" -gt 0 ]; then
28 to_play=white
29 # Comment following out if you want to include handi games.
30 echo "$sgf: Skipping handicap game" >&2
31 exit 1
34 to_play=black
35 cat "$sgf" | tools/sgf2gtp.pl | ./pachi -d 0 -e patternscan "$@" |
36 sed -n -e 's/^= //p' | grep -v '^ *$' | # skip irrelevant replies
37 while read pattern; do
38 if [ "$to_play" = black ]; then
39 player="$black"
40 to_play=white
41 else
42 player="$white"
43 to_play=black
45 echo "$pattern" >>"$dbdir/$player"
46 done