34 lines
919 B
Python
34 lines
919 B
Python
|
# 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': None,
|
||
|
'boardsize': None,
|
||
|
'clear_board': None,
|
||
|
'komi': None,
|
||
|
'play': None,
|
||
|
'genmove': None
|
||
|
}
|
||
|
|
||
|
|
||
|
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.extend(dispatcher.keys())
|
||
|
|
||
|
|
||
|
def run(self):
|
||
|
pass
|