-
Notifications
You must be signed in to change notification settings - Fork 1
/
genleaves.sh
executable file
·149 lines (137 loc) · 3.74 KB
/
genleaves.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
set -euo pipefail
breadth_mode=""
full_mode=""
klv1_mode=""
no_logs_mode=""
no_smooth_mode=""
while :; do
if [ "${1:-}" = "--" ]; then
shift
break
fi
if [ "${1:-}" = "--breadth" ]; then
breadth_mode=1
shift
continue
fi
if [ "${1:-}" = "--full" ]; then
full_mode=1
shift
continue
fi
if [ "${1:-}" = "--klv1" ]; then
klv1_mode=1
shift
continue
fi
if [ "${1:-}" = "--no-logs" ]; then
no_logs_mode=1
shift
continue
fi
if [ "${1:-}" = "--no-smooth" ]; then
no_smooth_mode=1
shift
continue
fi
break
done
if [ "$#" -lt 3 ]; then
cat <<"EOF"
usage 1:
mkdir t
cd t
cp -ip ../.../CSW21.kwg .
../genleaves.sh [options] super-english english 2000000 2000000 2000000
usage 2:
mkdir t
cd t
cp -ip ../.../NSF20.kwg .
../genleaves.sh [options] norwegian norwegian 2000000 2000000 2000000
usage 3: (same as usage 2 but sample different number of games)
../genleaves.sh [options] norwegian norwegian 1000000 2000000 3000000
usage 4: (number of number of games does not have to be 3, minimum is 1)
../genleaves.sh [options] norwegian norwegian 100 300 600 1000
bash allows this syntax:
../genleaves.sh [options] {super-,}english 2000000{,,}
../genleaves.sh [options] {,}norwegian 2000000{,,}
../genleaves.sh [options] {,}norwegian {1..3}000000
../genleaves.sh [options] {,}norwegian {1,3,6,10}00
options:
--breadth gather diverse samples by allowing free midgame exchanges
(this is slow and may need many more than 2000000 samples)
--full generate full-rack leaves (typically used with --breadth)
--klv1 use klv1 instead of klv2 (not recommended)
--no-logs do not log the games (not recommended unless disk space is low)
--no-smooth disable smoothing (not recommended)
EOF
exit 2
fi
leave_param="$1"
buildlex_param="$2"
kwg=""
for x in *.kwg; do
if [ ! -f "$x" ]; then
:
elif [ ! "$kwg" ]; then
kwg="$x"
else
echo "there must be exactly 1 kwg here (found multiple)" >&2
exit 1
fi
done
if [ ! "$kwg" ]; then
echo "there must be exactly 1 kwg here (found none)" >&2
exit 1
fi
echo "$kwg"
let i=3
while [ "${!i:-}" != "" ]; do
if [ "${!i}" != "$[${!i} + 0]" ]; then
echo "invalid number: ${!i}" >&2
exit 1
fi
let i=i+1
done
autoplay_subcommand="${leave_param}-autoplay-summarize"
generate_subcommand="${leave_param}-generate"
buildlex_subcommand="${buildlex_param}-klv2"
leave_name="leaves-smooth"
klv_ext="klv2"
if [ "$no_logs_mode" ]; then
autoplay_subcommand="${autoplay_subcommand}-only"
fi
if [ "$breadth_mode" ]; then
# this must come after no_logs_mode
autoplay_subcommand="${autoplay_subcommand}-breadth"
fi
if [ "$full_mode" ]; then
generate_subcommand="${generate_subcommand}-full"
fi
if [ "$no_smooth_mode" ]; then
# this must come after full_mode
generate_subcommand="${generate_subcommand}-no-smooth"
leave_name="leaves"
fi
if [ "$klv1_mode" ]; then
buildlex_subcommand="${buildlex_param}-klv"
klv_ext="klv"
fi
num_processed=0
last_leave="-"
let i=3
while [ "${!i:-}" != "" ]; do
num="${!i:-}"
time cargo run --release --bin leave -- "$autoplay_subcommand" "$kwg" "$last_leave"{,} "$num"
log_file="$(ls -1td games-log-* | head -1 | cut -f2- -d-)"
echo "$log_file"
mv -fv "summary-${log_file}" "summary${num_processed}.csv"
last_leave="${leave_name}$[num_processed + 1]"
time cargo run --release --bin leave -- "$generate_subcommand" "summary${num_processed}.csv" "${last_leave}.csv"
time cargo run --release --bin buildlex -- "$buildlex_subcommand" "$last_leave".{csv,"$klv_ext"}
zip -9v result.zip "summary${num_processed}.csv" "$last_leave".{csv,"$klv_ext"}
last_leave="${last_leave}.${klv_ext}"
let num_processed=num_processed+1
let i=i+1
done