def findEgg():
    direction = 'e'
    got_egg = eggCheck('n')
    for i in range(4):
        for j in range(5):
            got_egg = eggCheck(direction) or got_egg
            if got_egg:
                st = 4 - j if direction == 'w' else j + 1
                ensureFifthSt(st)
                break
        if i < 3:
            up_egg = eggCheck('n')
            got_egg = up_egg or got_egg
            if direction == 'w' and up_egg:
                ensureFifthSt(0)
        if i == 0:
            sendOne(dunnet, 'get all')
        if got_egg:
            for l in range(2-i):
                sendOne(dunnet, 'n')
            break
        direction = flip(direction)
def answerQuestion(direction):
    questions = ['What is your password on the machine called ‘pokey‘?',
                 'What password did you use during anonymous ftp to gamma?',
                 'treasures for points?',
                 'What is your login name on the ‘endgame’ machine?',
                 'What is the nearest whole dollar to the price of the shovel?',
                 'What is the name of the bus company serving the town?',
                 'Give either of the two last names in the mailroom, other than your own.',
                 'What cartoon character is on the towel?',
                 'What is the last name of the author of EMACS?',
                 'How many megabytes of memory is on the CPU board for the Vax?',
                 'Which street in town is named after a U.S. state?',
                 'How many pounds did the weight weigh?',
                 'Name the STREET which runs right over the subway stop.',
                 'How many corners are there in town (excluding the one with the Post Office)?',
                 'What type of bear was hiding your key?',
                 'Name either of the two objects you found by digging.',
                 'What network protocol is used between pokey and gamma?']
    answers = ['robert',
               'toukmond',
               '4',
               'toukmond',
               '20',
               'mobytours',
               'collier',
               'snoopy',
               'stallman',
               '2',
               'vermont',
               '10',
               '4',
               '24',
               'grizzly',
               'cpu',
               'tcp/ip']
    dunnet.sendline(direction)
    i = dunnet.expect(questions)
    sendOne(dunnet, 'answer ' + answers[i])
Exemple #3
0
#!/usr/bin/env python
import sys
from pexpect import spawn, EOF
from dunnetPytool import sendOne, getCode

dunnet = spawn('emacs -batch -l dunnet', encoding='utf-8')
dunnet.logfile_read = sys.stdout
dunnet.expect('>')

sendOne(dunnet, 'get shovel')
sendOne(dunnet, 'e')
sendOne(dunnet, 'e')
sendOne(dunnet, 'dig')
sendOne(dunnet, 'take card')
sendOne(dunnet, 'se')
sendOne(dunnet, 'take food')
sendOne(dunnet, 'se')
sendOne(dunnet, 'drop food')
sendOne(dunnet, 'take key')
sendOne(dunnet, 'nw')
sendOne(dunnet, 'nw')
sendOne(dunnet, 'ne')
sendOne(dunnet, 'ne')
sendOne(dunnet, 'ne')
sendOne(dunnet, 'w')
sendOne(dunnet, 'put card in cabinet')
sendOne(dunnet, 'type')
sendOne(dunnet, 'toukmond')
sendOne(dunnet, 'robert')
sendOne(dunnet, 'dun-inventory=\'(1 7 10 11 12 15 17 18 23 24 25 26)\'')
sendOne(dunnet, 'moby')
def ensureFifthSt(street):
    for k in range(5 - street):
        sendOne(dunnet, 'e')
def eggCheck(direction):
    got_egg = sendOne(dunnet, direction, expected=['egg'])
    if got_egg:
        sendOne(dunnet, 'get all')
    return got_egg
               '24',
               'grizzly',
               'cpu',
               'tcp/ip']
    dunnet.sendline(direction)
    i = dunnet.expect(questions)
    sendOne(dunnet, 'answer ' + answers[i])


def flip(direction):
    if direction == 'e':
        return 'w'
    else:
        return 'e'

sendOne(dunnet, 'get shovel')
sendOne(dunnet, 'e')
sendOne(dunnet, 'e')
sendOne(dunnet, 'dig')
sendOne(dunnet, 'take card')
sendOne(dunnet, 'se')
sendOne(dunnet, 'take food')
sendOne(dunnet, 'se')
sendOne(dunnet, 'drop food')
sendOne(dunnet, 'take key')
sendOne(dunnet, 'sw')
sendOne(dunnet, 'take bracelet')
sendOne(dunnet, 'ne')
sendOne(dunnet, 'nw')
sendOne(dunnet, 'nw')
sendOne(dunnet, 'ne')