From f788bdcf63d14dd97f0802391b0676ca84c900ce Mon Sep 17 00:00:00 2001 From: Peter Ward Date: Tue, 5 Jan 2010 06:56:13 +1100 Subject: Renamed old bots to process bots. --- processbot.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 processbot.py (limited to 'processbot.py') diff --git a/processbot.py b/processbot.py new file mode 100644 index 0000000..3bd3038 --- /dev/null +++ b/processbot.py @@ -0,0 +1,30 @@ +import subprocess + +class BotWrapper(object): + def __init__(self, process): + self.process = process + self.__name__ = 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() + + assert proc.returncode == 0, 'Snake died.' + output = proc.stdout.read() + return output.strip() + -- cgit v1.2.3