# Path: toolbox.py
# def log(*args):
# 	global loglock
# 	loglock.acquire()
# 	encoding=sys.stdout.encoding
# 	for arg in args:
# 		try:
# 			if type(arg)==type(str('abc')):
# 				arg=arg.decode('utf-8',errors='replace')
# 			elif type(arg)!=type(u'abc'):
# 				try:
# 					arg=str(arg)
# 				except:
# 					arg=unicode(arg,errors='replace')
# 				arg=arg.decode('utf-8',errors='replace')
# 			arg=arg.encode(encoding, errors='replace')
# 			print arg,
# 		except:
# 			print "?"*len(arg),
# 	print
# 	loglock.release()
# 
# class GRPException(Exception):
# 	def __init__(self,msg):
# 		if type(msg)==type(u"abc"):
# 			self.utf_msg=msg
# 			self.str_msg=msg.encode("utf-8",errors='replace')
# 		else:
# 			self.str_msg=msg
# 			self.utf_msg=msg.decode("utf-8",errors='replace')
# 		log("===")
# 		log(format_exc())
# 		log("===")
# 		Exception.__init__(self,self.str_msg)
# 
# 	def __unicode__(self):
# 		return self.utf_msg


import subprocess,sys
import threading, Queue
from time import sleep
from toolbox import log,GRPException
		self.write("boardsize "+str(size))
		answer=self.readline()
		if answer[0]=="=":return True
		else:return False
		
	def reset(self):
		self.write("clear_board")
		answer=self.readline()
		if answer[0]=="=":return True
		else:return False

	def komi(self,k):
		self.write("komi "+str(k))
		answer=self.readline()
		if answer[0]=="=":
			self.komi_value=k
			return True
		else:
			self.komi_value=0
			return False

	def place_black(self,move):
		if move == "RESIGN":
			log("WARNING: trying to play RESIGN as GTP move")
			self.history.append(["b",move])
			return True
		self.write("play black "+move)
		answer=self.readline()
		if answer[0]=="=":
			self.history.append(["b",move])

# Path: toolbox.py
# def log(*args):
# 	global loglock
# 	loglock.acquire()
# 	encoding=sys.stdout.encoding
# 	for arg in args:
# 		try:
# 			if type(arg)==type(str('abc')):
# 				arg=arg.decode('utf-8',errors='replace')
# 			elif type(arg)!=type(u'abc'):
# 				try:
# 					arg=str(arg)
# 				except:
# 					arg=unicode(arg,errors='replace')
# 				arg=arg.decode('utf-8',errors='replace')
# 			arg=arg.encode(encoding, errors='replace')
# 			print arg,
# 		except:
# 			print "?"*len(arg),
# 	print
# 	loglock.release()
# 
# class GRPException(Exception):
# 	def __init__(self,msg):
# 		if type(msg)==type(u"abc"):
# 			self.utf_msg=msg
# 			self.str_msg=msg.encode("utf-8",errors='replace')
# 		else:
# 			self.str_msg=msg
# 			self.utf_msg=msg.decode("utf-8",errors='replace')
# 		log("===")
# 		log(format_exc())
# 		log("===")
# 		Exception.__init__(self,self.str_msg)
# 
# 	def __unicode__(self):
# 		return self.utf_msg


# Path: gtp.py
import subprocess,sys
import threading, Queue
from time import sleep
from toolbox import log,GRPException

		self.write("boardsize "+str(size))
		answer=self.readline()
		if answer[0]=="=":return True
		else:return False
		
	def reset(self):
		self.write("clear_board")
		answer=self.readline()
		if answer[0]=="=":return True
		else:return False

	def komi(self,k):
		self.write("komi "+str(k))
		answer=self.readline()
		if answer[0]=="=":
			self.komi_value=k
			return True
		else:
			self.komi_value=0
			return False

	def place_black(self,move):
		if move == "RESIGN":
			log("WARNING: trying to play RESIGN as GTP move")
			self.history.append(["b",move])
			return True
		self.write("play black "+move)
		answer=self.readline()
		if answer[0]=="=":
			self.history.append(["b",move])

			return True