# This class implements a thread that handles the networking connection. # It expects a copy of the board and an open socket to the remote host, which # it will bind to a GTPSocket. # This is the only thread that should be calling get(), but send() could be called # twice, so we wrap it in a mutex. # The board is also wrapped in a mutex, even though only this thread should modify it # if it exists. import threading class NetworkThread(threading.Thread): dispatcher = { 'quit': do_quit, 'boardsize': do_boardsize, 'clear_board': do_clear_board, 'komi': do_komi, 'play': do_play, 'genmove': do_genmove } def __init__(self, goban, socket): self.goban = goban self.goban_lock = threading.Lock() self.socket = GTPSocket(socket) self.send_lock = threading.Lock() GTPSocket.known_cmds = GTPSocket.known_cmds & set(dispatcher.keys()) def run(self): pass def do_quit(self, gtp): pass def do_boardsize(self, gtp): pass def do_clear_board(self, gtp): pass def do_komi(self, gtp): pass def do_play(self, gtp): pass def do_genmove(self, gtp): pass