Skip to content

Instantly share code, notes, and snippets.

@MLLeKander
Created October 3, 2012 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MLLeKander/3825222 to your computer and use it in GitHub Desktop.
Save MLLeKander/3825222 to your computer and use it in GitHub Desktop.
305 BoardTest Shell
#!/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