Created
July 17, 2011 23:16
-
-
Save craigcalef/1088218 to your computer and use it in GitHub Desktop.
Automate 'start scumming' -- repeatedly generating characters till an advantageous starting inventory is found.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USERNAME = 'NAOUSERNAME' | |
PASSWORD = 'NAOPASSWORD' | |
import pexpect, traceback, sys, time | |
def scum(n): | |
try: | |
#n = pexpect.spawn('nethack') | |
print "BEGIN" | |
r = n.expect(['Shall I pick', 'Restoring save file', 'Too many hacks', 'stale' ]) | |
print "START STATE", r | |
if r == 4: | |
n.send('p') | |
return False | |
if r == 3: | |
print "Game in progress." | |
time.sleep(11) | |
n.sendline('#quit') | |
n.send('nnn') | |
n.sendline('') | |
return False | |
if r == 2: | |
print "Too many locks." | |
sys.exit(-1) | |
if r == 1: | |
print "Attempting to kill running game" | |
n.sendline('#quit') | |
n.send('nnn') | |
n.sendline('') | |
return False | |
n.send('nwgm') | |
print "SENT CHARACTER" | |
n.expect('Go bravely') | |
print "GO BRAVELY" | |
n.sendline('') | |
n.expect('welcome to') | |
print "WELCOME" | |
n.send('i') | |
print "REQUEST INVENTORY" | |
r = n.expect([r'(ring of polymorph$)|(wand of polymorph)', r'(ring of polymorph control)', r'.*smoky.*', r'\(end\)'], timeout=1) | |
print "Results: ", r | |
if r != 3: | |
return True | |
n.sendline(' ') | |
n.sendline('#quit') | |
#n.send('nnnn') | |
n.send('y') | |
n.send('n') | |
n.send('n') | |
n.send('n') | |
n.sendline('') | |
return False | |
except SystemExit: | |
sys.exit(-1) | |
except KeyboardInterrupt: | |
sys.exit(-1) | |
except: | |
traceback.print_exc() | |
n.interact() | |
if __name__ == '__main__': | |
i = False | |
c = 0 | |
n = pexpect.spawn('telnet nethack.alt.org') | |
n.setecho(True) | |
n.logfile = open('startscum.log', 'w') | |
#n.logfile = sys.stdout | |
n.expect('=>') | |
n.send('l') | |
n.expect('Please enter your username') | |
n.sendline(USERNAME) | |
n.expect('Please enter your password') | |
n.sendline(PASSWORD) | |
n.expect('=>') | |
n.send('p') | |
time.sleep(0.1) | |
#scum(n) | |
#n.interact() | |
#sys.exit(-1) | |
while not i: | |
c = c + 1 | |
print "Scum try: ", c | |
i = scum(n) | |
if i: | |
print "Scum successful!" | |
sys.exit(1) | |
else: | |
print "RESTARTING GAME EXPECTING PROMPT" | |
n.expect('=>') | |
print "PROMPT FOUND SENDING p" | |
n.send('p') | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment