remove .swp
This commit is contained in:
parent
17a22138f7
commit
2f95a1d854
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
leela-zero
|
leela-zero
|
||||||
*.pyc
|
*.pyc
|
||||||
parameters
|
parameters
|
||||||
|
*.swp
|
BIN
GTP/.game.py.swp
BIN
GTP/.game.py.swp
Binary file not shown.
BIN
GTP/.test.py.swp
BIN
GTP/.test.py.swp
Binary file not shown.
Binary file not shown.
@ -6,7 +6,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from game import Game
|
from game import Game
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
|
|
||||||
class GTPEngine():
|
class GTPEngine():
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -27,7 +28,6 @@ class GTPEngine():
|
|||||||
except:
|
except:
|
||||||
self._version = 2
|
self._version = 2
|
||||||
|
|
||||||
|
|
||||||
self.disconnect = False
|
self.disconnect = False
|
||||||
|
|
||||||
self.known_commands = [
|
self.known_commands = [
|
||||||
@ -42,9 +42,6 @@ class GTPEngine():
|
|||||||
x, y = vertex
|
x, y = vertex
|
||||||
return "{}{}".format("ABCDEFGHJKLMNOPQRSTYVWYZ"[x - 1], y)
|
return "{}{}".format("ABCDEFGHJKLMNOPQRSTYVWYZ"[x - 1], y)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _vertex_string2point(self, s):
|
def _vertex_string2point(self, s):
|
||||||
if s is None:
|
if s is None:
|
||||||
return False
|
return False
|
||||||
@ -62,7 +59,6 @@ class GTPEngine():
|
|||||||
return False
|
return False
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
|
||||||
|
|
||||||
def _parse_color(self, color):
|
def _parse_color(self, color):
|
||||||
if color.lower() in ["b", "black"]:
|
if color.lower() in ["b", "black"]:
|
||||||
color = utils.BLACK
|
color = utils.BLACK
|
||||||
@ -72,21 +68,18 @@ class GTPEngine():
|
|||||||
color = None
|
color = None
|
||||||
return color
|
return color
|
||||||
|
|
||||||
|
|
||||||
def _parse_move(self, move_string):
|
def _parse_move(self, move_string):
|
||||||
color, move = move_string.split(" ",1)
|
color, move = move_string.split(" ", 1)
|
||||||
color = self._parse_color(color)
|
color = self._parse_color(color)
|
||||||
|
|
||||||
point = self._vertex_string2point(move)
|
point = self._vertex_string2point(move)
|
||||||
|
|
||||||
if point and color:
|
if point and color:
|
||||||
return color,point
|
return color, point
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_res(self, res, id_ = None, success = True):
|
def _parse_res(self, res, id_=None, success=True):
|
||||||
if success:
|
if success:
|
||||||
if id_:
|
if id_:
|
||||||
return '={} {}\n\n'.format(id_, res)
|
return '={} {}\n\n'.format(id_, res)
|
||||||
@ -98,7 +91,6 @@ class GTPEngine():
|
|||||||
else:
|
else:
|
||||||
return '? {}\n\n'.format(res)
|
return '? {}\n\n'.format(res)
|
||||||
|
|
||||||
|
|
||||||
def _parse_cmd(self, message):
|
def _parse_cmd(self, message):
|
||||||
try:
|
try:
|
||||||
m = message.strip().split(" ", 1)
|
m = message.strip().split(" ", 1)
|
||||||
@ -119,19 +111,17 @@ class GTPEngine():
|
|||||||
return self._parse_res("invaild message", id_, False)
|
return self._parse_res("invaild message", id_, False)
|
||||||
|
|
||||||
if cmd in self.known_commands:
|
if cmd in self.known_commands:
|
||||||
#dispatch
|
# dispatch
|
||||||
#try:
|
# try:
|
||||||
if True:
|
if True:
|
||||||
res, flag = getattr(self, "cmd_" + cmd)(args)
|
res, flag = getattr(self, "cmd_" + cmd)(args)
|
||||||
return self._parse_res(res, id_, flag)
|
return self._parse_res(res, id_, flag)
|
||||||
#except Exception as e:
|
# except Exception as e:
|
||||||
# print(e)
|
# print(e)
|
||||||
# return self._parse_res("command excution failed", id_, False)
|
# return self._parse_res("command excution failed", id_, False)
|
||||||
else:
|
else:
|
||||||
return self._parse_res("unknown command", id_, False)
|
return self._parse_res("unknown command", id_, False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_protocol_version(self, args, **kwargs):
|
def cmd_protocol_version(self, args, **kwargs):
|
||||||
return 2, True
|
return 2, True
|
||||||
|
|
||||||
@ -148,50 +138,45 @@ class GTPEngine():
|
|||||||
return self.known_commands, True
|
return self.known_commands, True
|
||||||
|
|
||||||
def cmd_quit(self, args, **kwargs):
|
def cmd_quit(self, args, **kwargs):
|
||||||
return None,True
|
return None, True
|
||||||
|
|
||||||
def cmd_boardsize(self, args, **kwargs):
|
def cmd_boardsize(self, args, **kwargs):
|
||||||
if args.isdigit():
|
if args.isdigit():
|
||||||
size = int(args)
|
size = int(args)
|
||||||
self.size = size
|
self.size = size
|
||||||
self._game.set_size(size)
|
self._game.set_size(size)
|
||||||
return None,True
|
return None, True
|
||||||
else:
|
else:
|
||||||
return 'non digit size',False
|
return 'non digit size', False
|
||||||
|
|
||||||
def cmd_clear_board(self, args, **kwargs):
|
def cmd_clear_board(self, args, **kwargs):
|
||||||
self._game.clear()
|
self._game.clear()
|
||||||
return None,True
|
return None, True
|
||||||
|
|
||||||
def cmd_komi(self, args, **kwargs):
|
def cmd_komi(self, args, **kwargs):
|
||||||
try:
|
try:
|
||||||
komi = float(args)
|
komi = float(args)
|
||||||
self.komi = komi
|
self.komi = komi
|
||||||
self._game.set_komi(komi)
|
self._game.set_komi(komi)
|
||||||
return None,True
|
return None, True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError("syntax error")
|
raise ValueError("syntax error")
|
||||||
|
|
||||||
|
|
||||||
def cmd_play(self, args, **kwargs):
|
def cmd_play(self, args, **kwargs):
|
||||||
move = self._parse_move(args)
|
move = self._parse_move(args)
|
||||||
if move:
|
if move:
|
||||||
color, vertex = move
|
color, vertex = move
|
||||||
res = self._game.do_move(color, vertex)
|
res = self._game.do_move(color, vertex)
|
||||||
if res:
|
if res:
|
||||||
return None,True
|
return None, True
|
||||||
else:
|
else:
|
||||||
return None,False
|
return None, False
|
||||||
return None,True
|
return None, True
|
||||||
|
|
||||||
def cmd_genmove(self, args, **kwargs):
|
def cmd_genmove(self, args, **kwargs):
|
||||||
color = self._parse_color(args)
|
color = self._parse_color(args)
|
||||||
if color:
|
if color:
|
||||||
move = self._game.gen_move(color)
|
move = self._game.gen_move(color)
|
||||||
return self._vertex_point2string(move),True
|
return self._vertex_point2string(move), True
|
||||||
else:
|
else:
|
||||||
return 'unknown player',False
|
return 'unknown player', False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user