blob: 2729ec4caba8d8c3b6f1382aef15a896be2b027f (
plain)
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
|
#!../expect -f
# expect script to connect two UNIX chess programs together.
# written by Don Libes - May 9, 1990
# Note, this depends on the "usual" UNIX chess output. Other chess programs
# will almost certainly not work.
# Moves and counter-moves are printed out in different formats, sigh...
# But I guess that's what makes this Expect script challenging to write.
# In particular, the 1st player outputs:
#
# p/k2-k4 (echo from 2nd player)
# 1. ... p/k2-k4 (reprint it with a number in front - god knows why)
# 2. n/kn1-kb3 (our new move)
#
# and the 2nd player outputs the following
#
# n/kn1-kb3 (echo from first player)
# 2. n/kn1-kb3 (reprint it as above, but differently - god knows why)
# 2. ... p/k4-k5 (our new countermove - written differently, of course)
set timeout -1; # wait forever
expect_before {
-i $any_spawn_id eof {
send_user "player resigned!\n"
exit
}
}
# start things rolling
spawn chess
set id1 $spawn_id
expect "Chess\r\n"
send "first\r"
# read_first_move
expect -re "1. (.*)\n"
spawn chess
set id2 $spawn_id
expect "Chess\r\n"
send $expect_out(1,string)
for {} 1 {} {
expect {
-i $id2 -re "\\.\\. (.*)\n" {
send -i $id1 $expect_out(1,string)
}
-i $id1 -re "\\.\\. .*\\. (.*)\n" {
send -i $id2 $expect_out(1,string)
}
}
}
|