OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [example/] [chess.exp] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#!../expect -f
2
# expect script to connect two UNIX chess programs together.
3
# written by Don Libes - May 9, 1990
4
 
5
# Note, this depends on the "usual" UNIX chess output.  Other chess programs
6
# will almost certainly not work.
7
 
8
# Moves and counter-moves are printed out in different formats, sigh...
9
# But I guess that's what makes this Expect script challenging to write.
10
# In particular, the 1st player outputs:
11
#
12
# p/k2-k4               (echo from 2nd player)
13
# 1. ... p/k2-k4        (reprint it with a number in front - god knows why)
14
# 2. n/kn1-kb3          (our new move)
15
#
16
# and the 2nd player outputs the following
17
#
18
# n/kn1-kb3             (echo from first player)
19
# 2. n/kn1-kb3          (reprint it as above, but differently - god knows why)
20
# 2. ... p/k4-k5        (our new countermove - written differently, of course)
21
 
22
set timeout -1;                 # wait forever
23
expect_before {
24
        -i $any_spawn_id eof {
25
                send_user "player resigned!\n"
26
                exit
27
        }
28
}
29
 
30
# start things rolling
31
spawn chess
32
set id1 $spawn_id
33
expect "Chess\r\n"
34
send "first\r"
35
# read_first_move
36
expect -re "1. (.*)\n"
37
 
38
spawn chess
39
set id2 $spawn_id
40
expect "Chess\r\n"
41
send $expect_out(1,string)
42
 
43
for {} 1 {} {
44
        expect {
45
                -i $id2 -re "\\.\\. (.*)\n" {
46
                        send -i $id1 $expect_out(1,string)
47
                }
48
                -i $id1 -re "\\.\\. .*\\. (.*)\n" {
49
                        send -i $id2 $expect_out(1,string)
50
                }
51
        }
52
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.