diff options
author | Steven Myint <git@stevenmyint.com> | 2013-10-04 07:02:31 -0700 |
---|---|---|
committer | Steven Myint <git@stevenmyint.com> | 2013-10-04 07:02:31 -0700 |
commit | dd0479cb32e55e882a8d1391af2d5b37f25e2db7 (patch) | |
tree | ae595ce22b4b9d6700c71e2af4ef7d8055808b15 /examples/chess.py | |
parent | f64079f942fce756b52c81210401afd175b05902 (diff) | |
download | pexpect-git-dd0479cb32e55e882a8d1391af2d5b37f25e2db7.tar.gz |
Fix mixture of tabs and spaces
Diffstat (limited to 'examples/chess.py')
-rwxr-xr-x | examples/chess.py | 124 |
1 files changed, 61 insertions, 63 deletions
diff --git a/examples/chess.py b/examples/chess.py index 193dbd8..47daec2 100755 --- a/examples/chess.py +++ b/examples/chess.py @@ -31,68 +31,68 @@ REGEX_MOVE_PART = '(?:[0-9]|\x1b\[C)(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)' class Chess: - def __init__(self, engine = "/usr/local/bin/gnuchess -a -h 1"): - self.child = pexpect.spawn (engine) - self.term = ANSI.ANSI () - - self.child.expect ('Chess') - if self.child.after != 'Chess': - raise IOError, 'incompatible chess program' - self.term.process_list (self.before) - self.term.process_list (self.after) - self.last_computer_move = '' - def read_until_cursor (self, r,c) - while 1: - self.child.read(1, 60) - self.term.process (c) - if self.term.cur_r == r and self.term.cur_c == c: - return 1 - - def do_first_move (self, move): - self.child.expect ('Your move is') - self.child.sendline (move) - self.term.process_list (self.before) - self.term.process_list (self.after) - return move - - def do_move (self, move): - read_until_cursor (19,60) - #self.child.expect ('\[19;60H') - self.child.sendline (move) - print 'do_move' move - return move - - def get_first_computer_move (self): - self.child.expect ('My move is') - self.child.expect (REGEX_MOVE) + def __init__(self, engine = "/usr/local/bin/gnuchess -a -h 1"): + self.child = pexpect.spawn (engine) + self.term = ANSI.ANSI () + + self.child.expect ('Chess') + if self.child.after != 'Chess': + raise IOError, 'incompatible chess program' + self.term.process_list (self.before) + self.term.process_list (self.after) + self.last_computer_move = '' + def read_until_cursor (self, r,c) + while 1: + self.child.read(1, 60) + self.term.process (c) + if self.term.cur_r == r and self.term.cur_c == c: + return 1 + + def do_first_move (self, move): + self.child.expect ('Your move is') + self.child.sendline (move) + self.term.process_list (self.before) + self.term.process_list (self.after) + return move + + def do_move (self, move): + read_until_cursor (19,60) + #self.child.expect ('\[19;60H') + self.child.sendline (move) + print 'do_move' move + return move + + def get_first_computer_move (self): + self.child.expect ('My move is') + self.child.expect (REGEX_MOVE) # print '', self.child.after - return self.child.after - - def get_computer_move (self): - print 'Here' - i = self.child.expect (['\[17;59H', '\[17;58H']) - print i - if i == 0: - self.child.expect (REGEX_MOVE) - if len(self.child.after) < 4: - self.child.after = self.child.after + self.last_computer_move[3] - if i == 1: - self.child.expect (REGEX_MOVE_PART) - self.child.after = self.last_computer_move[0] + self.child.after - print '', self.child.after - self.last_computer_move = self.child.after - return self.child.after - - def switch (self): - self.child.sendline ('switch') - - def set_depth (self, depth): - self.child.sendline ('depth') - self.child.expect ('depth=') - self.child.sendline ('%d' % depth) - - def quit(self): - self.child.sendline ('quit') + return self.child.after + + def get_computer_move (self): + print 'Here' + i = self.child.expect (['\[17;59H', '\[17;58H']) + print i + if i == 0: + self.child.expect (REGEX_MOVE) + if len(self.child.after) < 4: + self.child.after = self.child.after + self.last_computer_move[3] + if i == 1: + self.child.expect (REGEX_MOVE_PART) + self.child.after = self.last_computer_move[0] + self.child.after + print '', self.child.after + self.last_computer_move = self.child.after + return self.child.after + + def switch (self): + self.child.sendline ('switch') + + def set_depth (self, depth): + self.child.sendline ('depth') + self.child.expect ('depth=') + self.child.sendline ('%d' % depth) + + def quit(self): + self.child.sendline ('quit') import sys, os print 'Starting...' white = Chess() @@ -145,5 +145,3 @@ while not done: print 'tail of loop' g.quit() - - |