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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [example/] [robohunt] - Blame information for rev 1776

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

Line No. Rev Author Line
1 578 markom
#!../expect -f
2
# Synopsis
3
#    robohunt player-name [-nodisplay]
4
 
5
# Plays hunt automatically.  Optional "-nodisplay" argument disables output.
6
 
7
# by Don Libes
8
 
9
expect_version -exit 5.0
10
 
11
set timeout 1
12
 
13
proc random {} {
14
        global ia ic im jran
15
 
16
        set jran [expr ($jran*$ia + $ic) % $im]
17
        return $jran
18
}
19
 
20
set ia 7141
21
set ic 54773
22
set im 259200
23
set jran [pid]
24
 
25
# given a direction and number, moves that many spaces in that direction
26
proc mv {dir num} {
27
        # first try firing a bullet (what the hell...open some walls to move!)
28
        send "f"
29
        for {set i 0} {$i<$num} {incr i} {
30
                send $dir
31
        }
32
}
33
 
34
# move a random distance/direction
35
 
36
# 31 is arbitrarily used as a max distance to move in any one direction
37
# this is a compromise between long horizontal and vertical moves
38
# but since excess movement is good for stabbing, this is reasonable
39
proc move {} {
40
        set num [random]
41
        set mask [expr $num&3]
42
        set num [expr $num&31]
43
        if $mask==0 {send "H"; mv "h" $num; return}
44
        if $mask==1 {send "L"; mv "l" $num; return}
45
        if $mask==2 {send "K"; mv "k" $num; return}
46
                     send "J"; mv "j" $num; return
47
}
48
 
49
if 2==$argc { set output 0 } {set output 1}
50
if 1>$argc  { send_user "usage: robohunt name \[-nodisplay\]\n"; exit}
51
spawn hunt -b -c -n [lindex $argv 0]
52
expect "team"
53
send "\r"
54
 
55
set several_moves 5
56
 
57
expect "Monitor:"
58
sleep 1
59
expect ;# flush output
60
log_user 0
61
# output is turned off so that we can first strip out ^Gs before they
62
# are sent to the tty.  It seems to drive xterms crazy - because our
63
# rather stupid algorithm off not checking after every move can cause
64
# the game to send a lot of them.
65
 
66
for {} 1 {} {
67
        # make several moves at a time, before checking to see if we are dead
68
        # this is a compromise between just ignoring our status after each move
69
        # and looking at our status after each move
70
        for {set j $several_moves} {$j} {incr j -1} {
71
                move
72
        }
73
 
74
        expect {
75
                -re ^\007+ {exp_continue}
76
                -re "\\? " {send y}
77
                -re .+
78
        }
79
        if $output {send_user -raw $expect_out(buffer)}
80
}

powered by: WebSVN 2.1.0

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