$ m2chess
Enter Stage Of Game : opening
Is the present Board in initial position? yes
White - Computer or Human (c/h) ? h
Black - Computer or Human (c/h) ? c
The Board :
a b c d e f g h
+-----------------+
8 | r n b q k b n r | 8
7 | p p p p p p p p | 7
6 | . . . . . . . . | 6
5 | . . . . . . . . | 5
4 | . . . . . . . . | 4
3 | . . . . . . . . | 3
2 | P P P P P P P P | 2
1 | R N B Q K B N R | 1
+-----------------+
a b c d e f g h
Please enter move: e2e4
My move is: E7-E5 0
The Board :
a b c d e f g h
+-----------------+
8 | r n b q k b n r | 8
7 | p p p p . p p p | 7
6 | . . . . s . . . | 6
5 | . . . . p . . . | 5
4 | . . . . P . . . | 4
3 | . . . . . . . . | 3
2 | P P P P . P P P | 2
1 | R N B Q K B N R | 1
+-----------------+
a b c d e f g h
Please enter move:
import pexpect, sys, string, os
from pexpect import TIMEOUT, EOF
class m2chess:
def __init__ (self, debugging = False, level = 1,
filename = "./chess", directory = "."):
if os.path.isdir(directory):
os.chdir(directory)
print "cd ", directory, " and running ", filename
else:
print "error as, directory: ", \
directory, " does not exist"
sys.exit(0)
self.child = pexpect.spawn (filename)
self.child.delaybeforesend = 0
self.level = level
self.finished = False
self.debugging = debugging
self.child.expect(’Enter Stage Of Game’)
self.child.sendline(’opening0)
if self.debugging:
print self.child.before
self.child.expect(’Is the present Board in initial position’)
self.child.sendline(’yes’)
if self.debugging:
print self.child.before
self.child.expect(’Human’)
self.child.sendline(’h’)
if self.debugging:
print self.child.before
self.child.expect(’Human’)
self.child.sendline(’c’)
if self.debugging:
print self.child.before
def makeMove(self, move):
if self.debugging:
print "making move"
print self.child.before
self.child.expect(’Please enter move’)
self.child.sendline(move)
def getMove(self):
if self.debugging:
print "getting move"
print self.child.before
i = self.child.expect([pexpect.TIMEOUT, ’(gdb)’,
’My move is:\s+(.*[A-H][1-8].*[A-H][1-8])’],
timeout=1000)
if i==0 or i==1:
print "something has gone wrong..."
self.child.interact()
sys.exit(0)
return self.child.match.groups()[0]
def doInteract(self):
if self.finished:
print "no m2chess interactive session available"
else:
try:
self.child.interact()
except os.error:
self.finished = True
def main():
foo = m2chess(False)
foo.makeMove(’e2e4’)
print foo.getMove()
foo.makeMove(’d2d4’)
print foo.getMove()
if __name__ == ’__main__’: main()
$ tar zxf m2chess-0.2.tar.gz $ cd m2chess $ make
$ tar zxf ModifiedChessBoard.tar.gz $ cd ModifiedChessBoard $ python PlayGame.py

This document was produced using groff-1.19.