python - a skeletal robot

February 09, 2009 09:22PM
<pre>
"""

This is the basic framework for writing a robot in Python.

"""

# this will work with any mud - these settings are for one where it's OK to run bots and mess around.

from telnetlib import Telnet #see [docs.python.org]
host = 'pearachute.net'
port = 9998

t = Telnet()


"""
This bit is sort of advanced, and you don't really have to understand it - but
what it does, is when you launch this script, you can pass it an extra argument,
and it will try to import that argument and run the strings from the mud through that.

that way, you can write different bots/characters without rewriting this every time! :)
"""
import sys
try:
_foo = __import__(sys.argv[1],globals(),locals(),['proc','triggers'])
proc = _foo.proc
triggers = _foo.triggers
except Exception, e:
print e,'\n','print-only:'
def MAGIC(tuple):
sys.stdout.write( tuple[2])
triggers = ['\r\n']

#this is a convenience, it hits enter at the end of lines
def write(msg):
if msg: t.write(msg + '\n')

def main():
t.open(host,port)

while True:
write( MAGIC( t.expect(triggers)))



if __name__=='__main__': main()


"""
MAGIC is the magic in this program. It takes the data coming from the mud
and can (optionally) return a string, which will be sent to the mud.

I'll explain more in part 2! WALDO THE WANDERBOT!

;p
"""
</pre>
Subject Author Posted

python - a skeletal robot

chalupah February 09, 2009 09:22PM

In Russia, games play you? Or .. what?

WraithOfLight February 10, 2009 12:23PM

AI is kind of fun, and programming real code will get you a job ;p ~

chalupah February 11, 2009 06:15PM

Don't have to tell me :) nt

WraithOfLight February 12, 2009 08:28AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 135
Record Number of Users: 5 November 04, 2022
Record Number of Guests: 358 August 31, 2022