diff options
author | Peter Ward <peteraward@gmail.com> | 2009-09-28 12:17:22 +1000 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2009-09-28 12:17:22 +1000 |
commit | bc47a4c3efe6006b42f1a4925a0994dc3e5093d1 (patch) | |
tree | 512d42921a570a2a31b5b54a3a11ba3f09f9e11f /oldbot.py | |
parent | 84c620ce93dbb9da9fc2328c13b8a48316641d4a (diff) |
Added a compatibility layer for Gregsnakebots.
Diffstat (limited to 'oldbot.py')
-rw-r--r-- | oldbot.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/oldbot.py b/oldbot.py new file mode 100644 index 0000000..436375c --- /dev/null +++ b/oldbot.py @@ -0,0 +1,29 @@ +import subprocess + +class BotWrapper(object): + def __init__(self, process): + self.process = process + + def __call__(self, board, (x, y)): + height = len(board) + width = len(board[0]) + + letter = board[y][x].lower() + + proc = subprocess.Popen( + [self.process], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + ) + + board = '\n'.join([''.join(row) for row in board]) + + print>>proc.stdin, width, height, letter + print>>proc.stdin, board + proc.stdin.close() + proc.wait() + + if proc.returncode == 0: + output = proc.stdout.read() + return output.strip() + |