1# pgn4web javascript chessboard
2# copyright (C) 2009-2013 Paolo Casaschi
3# see README file and http://pgn4web.casaschi.net
4# for credits, license and more details
5
6# bash script to create a pgn file over time, same as a live broadcast
7# more realistic than simulating the live broadcast within pgn4web
8# run as "bash script.sh"
9
10set +o posix
11
12if [ "$1" == "--help" ]
13then
14   echo
15   echo "$(basename $0)"
16   echo
17   echo "Shell script to create a pgn file over time, same as a live broadcast"
18   echo "and more realistic than simulating the live broadcast within pgn4web"
19   echo
20   echo "Needs to be run using bash"
21   echo
22   exit
23fi
24
25if [ "$1" == "--no-shell-check" ]
26then
27   shift 1
28else
29   if [ "$(basename $SHELL)" != "bash" ]
30   then
31      echo "ERROR: $(basename $0) should be run with bash. Prepend --no-shell-check as first parameters to skip checking the shell type."
32      exit
33   fi
34fi
35
36pgn_file=live.pgn
37pgn_file_tmp=live-tmp.pgn
38
39delay=17
40if [ -n "$1" ]
41then
42   if [ "$1" -eq "$1" 2> /dev/null ]
43   then
44      delay="$1"
45   else
46      echo "ERROR: $(basename $0) the delay parameter should be an integer (supplied $1)"
47      exit
48   fi
49fi
50
51# dont touch after this line
52
53umask 0000
54if [ $? -ne 0 ]
55then
56   echo "ERROR: $(basename $0) failed setting umask 0000"
57   exit
58fi
59
60game1_header="[Event \"Tilburg Fontys\"]\n[Site \"Tilburg\"]\n[Date \"1998.10.24\"]\n[Round \"2\"]\n[White \"Anand, Viswanathan\"]\n[Black \"Kramnik, Vladimir\"]\n[WhiteClock \"2:00:00\"]\n[BlackClock \"2:00:00\"]"
61game1_header_live="$game1_header\n[Result \"*\"]"
62game1_header_end="$game1_header\n[Result \"1-0\"]"
63
64game1_moves[0]="1.e4 {[%clk 1:59:59]} e5 {[%clk 1:58:58]}"
65game1_clock[0]="[Clock \"W/1:58:00\"]"
66
67game1_moves[1]=" 2.Nf3 {[%clk 1:57:57]} Nf6 {[%clk 1:56:56]} 3.Nxe5 {[%clk 1:55:55]}"
68game1_clock[1]="[Clock \"B/1:55:00\"]"
69
70game1_moves[2]="d6 {[%clk 1:54:54]}"
71game1_clock[2]="[Clock \"W/1:54:00\"]"
72
73game1_moves[3]="4.Nf3 {[%clk 1:53:53]} Nxe4 {[%clk 1:52:52]}"
74game1_clock[3]="[Clock \"W/1:52:00\"]"
75
76game1_moves[4]="5.d4 {[%clk 1:51:51]} d5 {[%clk 1:50:50]} 6.Bd3 {[%clk 1:49:49]}"
77game1_clock[4]="[Clock \"B/1:49:00\"]"
78
79game1_moves[5]="Nc6 {[%clk 1:48:48]} 7.O-O {[%clk 1:47:47]}"
80game1_clock[5]="[Clock \"B/1:47:00\"]"
81
82game1_moves[6]="Be7 {[%clk 1:46:46]} 8.Re1 {[%clk 1:45:45]}"
83game1_clock[6]="[Clock \"B/1:45:00\"]"
84
85game1_moves[7]="Bg4 {[%clk 1:44:44]} 9.c3 {[%clk 1:43:43]} f5 {[%clk 1:42:42]}"
86game1_clock[7]="[Clock \"W/1:43:01\"]"
87
88game1_moves[8]=""
89game1_clock[8]="[Clock \"W/1:43:00\"]"
90
91game1_moves[9]="10.Qb3 {[%clk 1:41:41]} O-O {[%clk 1:40:40]} 11.Nbd2 {[%clk 1:39:39]}"
92game1_clock[9]="[Clock \"B/1:39:01\"]"
93
94game1_moves[10]=""
95game1_clock[10]="[Clock \"B/1:39:00\"]"
96
97game1_moves[11]="Na5 {[%clk 1:38:38]}"
98game1_clock[11]="[Clock \"W/1:38:00\"]"
99
100game1_moves[12]="12.Qa4 {[%clk 1:37:37]} Nc6 {[%clk 1:36:36]} 13.Bb5 {[%clk 1:35:35]}"
101game1_clock[12]="[Clock \"W/1:35:00\"]"
102
103game1_moves[13]="Nxd2 {[%clk 1:34:34]} 14.Nxd2 {[%clk 1:33:33]} Qd6 {[%clk 1:32:32]}"
104game1_clock[13]="[Clock \"W/1:32:00\"]"
105
106game1_moves[14]="15.h3 {[%clk 1:31:31]} Bh5 {[%clk 1:30:30]}"
107game1_clock[14]="[Clock \"W/1:30:01\"]"
108
109game1_moves[15]=""
110game1_clock[15]="[Clock \"W/1:30:00\"]"
111
112game1_moves[16]="16.Nb3 {[%clk 1:29:29]} Bh4 {[%clk 1:28:28]}"
113game1_clock[16]="[Clock \"W/1:28:00\"]"
114
115game1_moves[17]="17.Nc5 {[%clk 1:27:27]}"
116game1_clock[17]="[Clock \"B/1:27:00\"]"
117
118game1_moves[18]="Bxf2+ {[%clk 1:26:26]}"
119game1_clock[18]="[Clock \"W/1:26:00\"]"
120
121game1_moves[19]="18.Kxf2 {[%clk 1:25:25]} Qh2 {[%clk 1:24:24]} 19.Bxc6 {[%clk 1:23:23]}"
122game1_clock[19]="[Clock \"B/1:23:00\"]"
123
124game1_moves[20]="bxc6 {[%clk 1:22:22]} 20.Qxc6 {[%clk 1:21:21]} f4 {[%clk 1:20:20]}"
125game1_clock[20]="[Clock \"W/1:20:00\"]"
126
127game1_moves[21]="21.Qxd5+ {[%clk 1:19:19]}"
128game1_clock[21]="[Clock \"B/1:19:00\"]"
129
130game1_moves[22]="Kh8 {[%clk 1:18:18]} 22.Qxh5 {[%clk 1:17:17]}"
131game1_clock[22]="[Clock \"W/1:17:00\"]"
132
133game1_moves[23]="f3 {[%clk 1:16:16]}"
134game1_clock[23]="[Clock \"W/1:16:00\"]"
135
136game1_moves[24]="23.Qxf3 {[%clk 1:15:15]} Rxf3+ {[%clk 1:14:14]}"
137game1_clock[24]="[Clock \"W/1:14:00\"]"
138
139game1_moves[25]="24.Kxf3 {[%clk 1:13:13]} Rf8+ {[%clk 1:12:12]} 25.Ke2 {[%clk 1:11:11]}"
140game1_clock[25]="[Clock \"B/1:11:00\"]"
141
142game1_moves[26]="Qxg2+ {[%clk 1:10:10]} 26.Kd3 {[%clk 1:09:09]}"
143game1_clock[26]="[Clock \"B/1:09:00\"]"
144
145game1_moves[27]="Qxh3+ {[%clk 1:08:08]} 27.Kc2 {[%clk 1:07:07]} Qg2+ {[%clk 1:06:06]}"
146game1_clock[27]="[Clock \"W/1:06:00\"]"
147
148game1_moves[28]="28.Bd2 {[%clk 1:05:05]} Qg6+ {[%clk 1:04:04]}"
149game1_clock[28]="[Clock \"W/1:04:00\"]"
150
151game1_moves[29]="29.Re4 {[%clk 1:03:03]} h5 {[%clk 1:02:02]} 30.Re1 {[%clk 1:01:01]}"
152game1_clock[29]="[Clock \"B/1:01:00\"]"
153
154game1_moves[30]="Re8 {[%clk 1:00:00]} 31.Kc1 {[%clk 59:59]} Rxe4 {[%clk 58:58]}"
155game1_clock[30]="[Clock \"W/58:00\"]"
156
157game1_moves[31]="Nxe4 {[%clk 57:57]} h4 {[%clk 56:56]} 33.Ng5 {[%clk 55:55]}"
158game1_clock[31]="[Clock \"B/55:00\"]"
159
160game1_moves[32]="Qh5 {[%clk 54:54]} 34.Re3 {[%clk 53:53]} Kg8 {[%clk 52:52]}"
161game1_clock[32]="[Clock \"W/52:00\"]"
162
163game1_moves[33]="35.c4 {[%clk 51:51]}"
164game1_clock[33]="[Clock \"B/51:00\"]"
165
166game1_moves[34]="1-0"
167game1_clock[34]="[Clock \"B/50:00\"]"
168
169game2_header="[Event \"Tilburg Fontys\"]\n[Site \"Tilburg\"]\n[Date \"1998.10.24\"]\n[Round \"2\"]\n[White \"Lautier, Joel\"]\n[Black \"Van Wely, Loek\"]\n[WhiteClock \"2:00:00\"]\n[BlackClock \"2:00:00\"]"
170game2_header_live="$game2_header\n[Result \"*\"]"
171game2_header_end="$game2_header\n[Result \"1/2-1/2\"]"
172
173game2_moves[0]=""
174game2_clock[0]="[Clock \"W/1:59:5A\"]"
175
176game2_moves[1]="1.d4 {[%clk 1:59:59]} Nf6 {[%clk 1:59:58]} 2.c4 {[%clk 1:58:57]} c5 {[%clk 1:58:56]} 3.d5 {[%clk 1:57:55]}"
177game2_clock[1]="[Clock \"B/1:58:00\"]"
178
179game2_moves[2]="b5 {[%clk 1:57:54]}"
180game2_clock[2]="[Clock \"W/1:57:00\"]"
181
182game2_moves[3]="4.Nf3 {[%clk 1:56:53]}"
183game2_clock[3]="[Clock \"B/1:57:00\"]"
184
185game2_moves[4]="Bb7 {[%clk 1:56:52]}"
186game2_clock[4]="[Clock \"W/1:56:00\"]"
187
188game2_moves[5]="5.a4 {[%clk 1:55:51]}"
189game2_clock[5]="[Clock \"B/1:56:00\"]"
190
191game2_moves[6]="Qa5+ {[%clk 1:55:50]}"
192game2_clock[6]="[Clock \"W/1:55:00\"]"
193
194game2_moves[7]="6.Bd2 {[%clk 1:54:49]}"
195game2_clock[7]="[Clock \"B/1:55:00\"]"
196
197game2_moves[8]="b4 {[%clk 1:54:48]}"
198game2_clock[8]="[Clock \"W/1:54:00\"]"
199
200game2_moves[9]="7.Bg5 {[%clk 1:53:47]} d6 {[%clk 1:53:46]}"
201game2_clock[9]="[Clock \"W/1:53:01\"]"
202
203game2_moves[10]=""
204game2_clock[10]="[Clock \"W/1:53:00\"]"
205
206game2_moves[11]="8.Nbd2 {[%clk 1:52:45]}"
207game2_clock[11]="[Clock \"B/1:53:00\"]"
208
209game2_moves[12]="Nbd7 {[%clk 1:52:44]}"
210game2_clock[12]="[Clock \"W/1:52:00\"]"
211
212game2_moves[13]="9.h3 {[%clk 1:51:43]} g6 {[%clk 1:51:42]}"
213game2_clock[13]="[Clock \"W/1:51:00\"]"
214
215game2_moves[14]="10.e4 {[%clk 1:50:41]} Bg7 {[%clk 1:50:40]} 11.Bd3 {[%clk 1:49:39]}"
216game2_clock[14]="[Clock \"B/1:50:00\"]"
217
218game2_moves[15]="O-O {[%clk 1:49:38]} 12.O-O {[%clk 1:48:37]}"
219game2_clock[15]="[Clock \"B/1:49:00\"]"
220
221game2_moves[16]="Rae8 {[%clk 1:48:36]}"
222game2_clock[16]="[Clock \"W/1:48:01\"]"
223
224game2_moves[17]=""
225game2_clock[17]="[Clock \"W/1:48:00\"]"
226
227game2_moves[18]="13.Re1 {[%clk 1:47:35]} e5 {[%clk 1:47:34]}"
228game2_clock[18]="[Clock \"W/1:47:00\"]"
229
230game2_moves[19]="14.Nf1 {[%clk 1:46:33]}"
231game2_clock[19]="[Clock \"B/1:47:00\"]"
232
233game2_moves[20]="Nh5 {[%clk 1:46:32]} 15.g3 {[%clk 1:45:31]}"
234game2_clock[20]="[Clock \"B/1:46:00\"]"
235
236game2_moves[21]="Bc8 {[%clk 1:45:30]}"
237game2_clock[21]="[Clock \"W/1:45:01\"]"
238
239game2_moves[22]=""
240game2_clock[22]="[Clock \"W/1:45:00\"]"
241
242game2_moves[23]="16.Kh2 {[%clk 1:44:29]} Kh8 {[%clk 1:44:28]}"
243game2_clock[23]="[Clock \"W/1:44:00\"]"
244
245game2_moves[24]="17.b3 {[%clk 1:43:27]}"
246game2_clock[24]="[Clock \"B/1:44:00\"]"
247
248game2_moves[25]="Qc7 {[%clk 1:43:26]}"
249game2_clock[25]="[Clock \"W/1:43:01\"]"
250
251game2_moves[26]=""
252game2_clock[26]="[Clock \"W/1:43:00\"]"
253
254game2_moves[27]="18.Ra2 {[%clk 1:42:25]}"
255game2_clock[27]="[Clock \"B/1:43:00\"]"
256
257game2_moves[28]="Ndf6 {[%clk 1:42:24]}"
258game2_clock[28]="[Clock \"W/1:42:00\"]"
259
260game2_moves[29]="19.Ng1 {[%clk 1:41:23]}"
261game2_clock[29]="[Clock \"B/1:42:01\"]"
262
263game2_moves[30]=""
264game2_clock[30]="[Clock \"B/1:42:00\"]"
265
266game2_moves[31]="Ng8 {[%clk 1:41:22]}"
267game2_clock[31]="[Clock \"W/1:41:01\"]"
268
269game2_moves[32]=""
270game2_clock[32]="[Clock \"W/1:41:00\"]"
271
272game2_moves[33]="20.Bc1 {[%clk 1:40:21]}"
273game2_clock[33]="[Clock \"B/1:40:00\"]"
274
275game2_moves[34]="1/2-1/2"
276game2_clock[34]="[Clock \"B/1:39:00\"]"
277
278steps=34
279
280if [ -e "$pgn_file" ]
281then
282   echo "ERROR: $(basename $0): $pgn_file exists"
283   echo "Delete the file or choose another filename and restart $(basename $0)"
284   exit
285fi
286
287echo Generating PGN file $pgn_file simulating live game broadcast
288
289echo > $pgn_file_tmp
290echo -e $game1_header_live >> $pgn_file_tmp
291echo "*" >> $pgn_file_tmp
292echo >> $pgn_file_tmp
293echo -e $game2_header_live >> $pgn_file_tmp
294echo "*" >> $pgn_file_tmp
295mv $pgn_file_tmp $pgn_file
296sleep $delay
297
298upto=0;
299while [ $upto -lt $steps ]
300do
301   echo " step $upto of $steps"
302   echo > $pgn_file_tmp
303
304   echo -e $game1_header_live >> $pgn_file_tmp
305        echo -e ${game1_clock[$upto]} >> $pgn_file_tmp
306   echo >> $pgn_file_tmp
307   move=0
308   while [ $move -le $upto ]
309   do
310      echo ${game1_moves[$move]} >> $pgn_file_tmp
311      move=$(($move + 1))
312   done
313
314   echo >> $pgn_file_tmp
315
316   echo -e $game2_header_live >> $pgn_file_tmp
317        echo -e ${game2_clock[$upto]} >> $pgn_file_tmp
318   echo >> $pgn_file_tmp
319   move=0
320   while [ $move -le $upto ]
321   do
322      echo ${game2_moves[$move]} >> $pgn_file_tmp
323      move=$(($move + 1))
324   done
325
326   mv $pgn_file_tmp $pgn_file
327   sleep $delay
328
329   upto=$(($upto + 1))
330done
331
332echo " step $upto of $steps"
333echo > $pgn_file_tmp
334echo -e $game1_header_end >> $pgn_file_tmp
335echo -e ${game1_clock[$upto]} >> $pgn_file_tmp
336echo >> $pgn_file_tmp
337move=0
338while [ $move -le $upto ]
339do
340   echo ${game1_moves[$move]} >> $pgn_file_tmp
341   move=$(($move + 1))
342done
343echo >> $pgn_file_tmp
344echo -e $game2_header_end >> $pgn_file_tmp
345echo -e ${game2_clock[$upto]} >> $pgn_file_tmp
346echo >> $pgn_file_tmp
347move=0
348while [ $move -le $upto ]
349do
350   echo ${game2_moves[$move]} >> $pgn_file_tmp
351   move=$(($move + 1))
352done
353mv $pgn_file_tmp $pgn_file
354echo done with games... waiting for a while before deleting $pgn_file
355
356sleep 3600
357rm $pgn_file
358
359