Created
October 3, 2012 05:36
-
-
Save MLLeKander/3825222 to your computer and use it in GitHub Desktop.
305 BoardTest Shell
This file contains hidden or 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
#!/usr/bin/python | |
from sys import argv, stdin, stdout | |
import re | |
translate = { | |
'em': 'enterMove', | |
'sm': 'showMove', | |
'show': 'showBoard', | |
'am': 'applyMove', | |
'dm': 'doMove', | |
'undo': 'undoLastMove', | |
'val': 'showVal', | |
'hist': 'showMoveHist', | |
'sb': 'saveBoard', | |
'sm': 'saveMove', | |
'lb': 'loadBoard', | |
'lm': 'loadMove', | |
'ck': 'compareKeys', | |
'cm': 'compareMove', | |
'opt': 'setOptions', | |
'tp': 'testPlay', | |
'tr': 'testRun', | |
'kmc': 'keyMoveCount', | |
'q': 'quit', | |
} | |
game = '' | |
checkers_pat = re.compile(r'[a-z]\d\s+') | |
othello_pat = re.compile(r'\d+\s+\d+') | |
if len(argv) > 1: | |
if argv[1] == '-c': | |
game = 'c' | |
elif argv[1] == '-o': | |
game = 'o' | |
elif argv[1] == '-p': | |
game = 'p' | |
while True: | |
line = stdin.readline() | |
if len(line) == 0: | |
break | |
lower = line.lower().rstrip() | |
found = False | |
if game == 'c' and checkers_pat.match(lower): | |
print('doMove '+re.sub('(\d)\s+([a-z])', r'\1 -> \2', lower)) | |
print('showBoard') | |
found = True | |
elif game == 'o' and othello_pat.match(lower): | |
print('doMove '+re.sub('(\d+)\s+(\d+)', r'[\1, \2]', lower)) | |
print('showBoard') | |
found = True | |
#TODO: Pylos shorthand | |
for key in translate.keys(): | |
if lower.startswith(key): | |
print(translate[key]+lower[len(key):]) | |
found = True | |
break | |
if not found: | |
print(lower) | |
stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment