summaryrefslogtreecommitdiff
path: root/oldbot.py
blob: 436375cbe93c9c8ec177779491b4aef44af143ac (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()