summaryrefslogtreecommitdiffstats
path: root/lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py')
-rw-r--r--lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py208
1 files changed, 106 insertions, 102 deletions
diff --git a/lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py b/lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py
index c62d5ce37a0..c75b6d8493f 100644
--- a/lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py
+++ b/lldb/third_party/Python/module/pexpect-2.4/examples/chess2.py
@@ -7,125 +7,129 @@ It starts two instances of gnuchess and then pits them against each other.
import pexpect
import string
import ANSI
-import sys, os, time
+import sys
+import os
+import time
+
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.child.before)
- #self.term.process_list (self.child.after)
-
- self.last_computer_move = ''
-
- def read_until_cursor (self, r,c, e=0):
- '''Eventually something like this should move into the screen class or
- a subclass. Maybe a combination of pexpect and screen...
- '''
- fout = open ('log','a')
- while self.term.cur_r != r or self.term.cur_c != c:
- try:
- k = self.child.read(1, 10)
- except Exception, e:
- print 'EXCEPTION, (r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c)
- sys.stdout.flush()
- self.term.process (k)
- fout.write ('(r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c))
- fout.flush()
- if e:
- sys.stdout.write (k)
- sys.stdout.flush()
- if self.term.cur_r == r and self.term.cur_c == c:
- fout.close()
- return 1
- print 'DIDNT EVEN HIT.'
- fout.close()
- return 1
-
- def expect_region (self):
- '''This is another method that would be moved into the
- screen class.
- '''
- pass
- def do_scan (self):
- fout = open ('log','a')
- while 1:
- c = self.child.read(1,10)
- self.term.process (c)
- fout.write ('(r,c):(%d,%d)\n' %(self.term.cur_r, self.term.cur_c))
- fout.flush()
- sys.stdout.write (c)
+ 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.child.before)
+ #self.term.process_list (self.child.after)
+
+ self.last_computer_move = ''
+
+ def read_until_cursor(self, r, c, e=0):
+ '''Eventually something like this should move into the screen class or
+ a subclass. Maybe a combination of pexpect and screen...
+ '''
+ fout = open('log', 'a')
+ while self.term.cur_r != r or self.term.cur_c != c:
+ try:
+ k = self.child.read(1, 10)
+ except Exception as e:
+ print 'EXCEPTION, (r,c):(%d,%d)\n' % (self.term.cur_r, self.term.cur_c)
sys.stdout.flush()
-
- def do_move (self, move, e = 0):
- time.sleep(1)
- self.read_until_cursor (19,60, e)
- self.child.sendline (move)
-
- def wait (self, color):
- while 1:
- r = self.term.get_region (14,50,14,60)[0]
- r = r.strip()
- if r == color:
- return
- time.sleep (1)
-
- def parse_computer_move (self, s):
- i = s.find ('is: ')
- cm = s[i+3:i+9]
- return cm
- def get_computer_move (self, e = 0):
- time.sleep(1)
- self.read_until_cursor (19,60, e)
- time.sleep(1)
- r = self.term.get_region (17,50,17,62)[0]
- cm = self.parse_computer_move (r)
- return cm
-
- def switch (self):
- print 'switching'
- 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')
-
-def LOG (s):
+ self.term.process(k)
+ fout.write('(r,c):(%d,%d)\n' % (self.term.cur_r, self.term.cur_c))
+ fout.flush()
+ if e:
+ sys.stdout.write(k)
+ sys.stdout.flush()
+ if self.term.cur_r == r and self.term.cur_c == c:
+ fout.close()
+ return 1
+ print 'DIDNT EVEN HIT.'
+ fout.close()
+ return 1
+
+ def expect_region(self):
+ '''This is another method that would be moved into the
+ screen class.
+ '''
+ pass
+
+ def do_scan(self):
+ fout = open('log', 'a')
+ while True:
+ c = self.child.read(1, 10)
+ self.term.process(c)
+ fout.write('(r,c):(%d,%d)\n' % (self.term.cur_r, self.term.cur_c))
+ fout.flush()
+ sys.stdout.write(c)
+ sys.stdout.flush()
+
+ def do_move(self, move, e=0):
+ time.sleep(1)
+ self.read_until_cursor(19, 60, e)
+ self.child.sendline(move)
+
+ def wait(self, color):
+ while True:
+ r = self.term.get_region(14, 50, 14, 60)[0]
+ r = r.strip()
+ if r == color:
+ return
+ time.sleep(1)
+
+ def parse_computer_move(self, s):
+ i = s.find('is: ')
+ cm = s[i + 3:i + 9]
+ return cm
+
+ def get_computer_move(self, e=0):
+ time.sleep(1)
+ self.read_until_cursor(19, 60, e)
+ time.sleep(1)
+ r = self.term.get_region(17, 50, 17, 62)[0]
+ cm = self.parse_computer_move(r)
+ return cm
+
+ def switch(self):
+ print 'switching'
+ 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')
+
+
+def LOG(s):
print s
- sys.stdout.flush ()
- fout = open ('moves.log', 'a')
- fout.write (s + '\n')
+ sys.stdout.flush()
+ fout = open('moves.log', 'a')
+ fout.write(s + '\n')
fout.close()
print 'Starting...'
black = Chess()
white = Chess()
-white.read_until_cursor (19,60,1)
+white.read_until_cursor(19, 60, 1)
white.switch()
done = 0
while not done:
- white.wait ('Black')
+ white.wait('Black')
move_white = white.get_computer_move(1)
- LOG ( 'move white:'+ move_white )
+ LOG('move white:' + move_white)
- black.do_move (move_white)
- black.wait ('White')
+ black.do_move(move_white)
+ black.wait('White')
move_black = black.get_computer_move()
- LOG ( 'move black:'+ move_black )
-
- white.do_move (move_black, 1)
-
-g.quit()
+ LOG('move black:' + move_black)
+ white.do_move(move_black, 1)
+g.quit()
OpenPOWER on IntegriCloud