#!/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()