From f449b608f755d7b1506b29c35d563565798b786a Mon Sep 17 00:00:00 2001 From: Samuel Sonning Date: Wed, 16 Dec 2020 17:33:25 +0100 Subject: [PATCH 1/6] allow multiline strings --- chess/engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chess/engine.py b/chess/engine.py index de5ccd6ed..9f59e7299 100644 --- a/chess/engine.py +++ b/chess/engine.py @@ -1654,13 +1654,13 @@ def _parse_uci_info(arg: str, root_board: chess.Board, selector: Info = INFO_ALL info: InfoDict = {} if not selector: return info - + info["string"] = "" tokens = arg.split(" ") while tokens: parameter = tokens.pop(0) if parameter == "string": - info["string"] = " ".join(tokens) + info["string"] = info["string"] + "\n" + " ".join(tokens) break elif parameter in ["depth", "seldepth", "nodes", "multipv", "currmovenumber", "hashfull", "nps", "tbhits", "cpuload"]: try: From 5477807f452b5ad57940588b85500df9a87855c5 Mon Sep 17 00:00:00 2001 From: Samuel Sonning Date: Wed, 16 Dec 2020 17:39:54 +0100 Subject: [PATCH 2/6] fix --- chess/engine.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chess/engine.py b/chess/engine.py index 9f59e7299..543e27675 100644 --- a/chess/engine.py +++ b/chess/engine.py @@ -1660,8 +1660,7 @@ def _parse_uci_info(arg: str, root_board: chess.Board, selector: Info = INFO_ALL parameter = tokens.pop(0) if parameter == "string": - info["string"] = info["string"] + "\n" + " ".join(tokens) - break + info["string"] += " ".join(tokens) + "\n" elif parameter in ["depth", "seldepth", "nodes", "multipv", "currmovenumber", "hashfull", "nps", "tbhits", "cpuload"]: try: info[parameter] = int(tokens.pop(0)) # type: ignore @@ -1739,6 +1738,8 @@ def _parse_uci_info(arg: str, root_board: chess.Board, selector: Info = INFO_ALL info["wdl"] = PovWdl(Wdl(int(tokens.pop(0)), int(tokens.pop(0)), int(tokens.pop(0))), root_board.turn) except (ValueError, IndexError): LOGGER.error("Exception parsing wdl from info: %r", arg) + elif parameter == 'bestmove': + break return info From 1b48babb7ca179d220486801b7dc21e7dc6dc882 Mon Sep 17 00:00:00 2001 From: Samuel Sonning Date: Fri, 18 Dec 2020 11:15:15 +0100 Subject: [PATCH 3/6] send all move info --- chess/engine.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/chess/engine.py b/chess/engine.py index 543e27675..c1cb30630 100644 --- a/chess/engine.py +++ b/chess/engine.py @@ -1654,13 +1654,12 @@ def _parse_uci_info(arg: str, root_board: chess.Board, selector: Info = INFO_ALL info: InfoDict = {} if not selector: return info - info["string"] = "" tokens = arg.split(" ") while tokens: parameter = tokens.pop(0) - if parameter == "string": - info["string"] += " ".join(tokens) + "\n" + info["string"] = " ".join(tokens) + break elif parameter in ["depth", "seldepth", "nodes", "multipv", "currmovenumber", "hashfull", "nps", "tbhits", "cpuload"]: try: info[parameter] = int(tokens.pop(0)) # type: ignore @@ -2433,13 +2432,16 @@ def __init__(self, stop: Optional[Callable[[], None]] = None): self._seen_kork = False self._finished: asyncio.Future[BestMove] = asyncio.Future() self.multipv = [{}] + self.string = "" def post(self, info: InfoDict) -> None: # Empty dictionary reserved for kork. if not info: return - + string = info.get("string", "") + self.string += string multipv = info.get("multipv", 1) + info["string"] = self.string while len(self.multipv) < multipv: self.multipv.append({}) self.multipv[multipv - 1].update(info) From 45142e43637f4f2034ffa45ac69cb0722611e800 Mon Sep 17 00:00:00 2001 From: Samuel Sonning Date: Wed, 23 Dec 2020 15:18:11 +0100 Subject: [PATCH 4/6] make hashable --- chess/__init__.py | 18 ++++++++++++++++++ chess/engine.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/chess/__init__.py b/chess/__init__.py index e7739b212..93d0fcc9b 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -584,6 +584,22 @@ def _reset_board(self) -> None: self.occupied_co[BLACK] = BB_RANK_7 | BB_RANK_8 self.occupied = BB_RANK_1 | BB_RANK_2 | BB_RANK_7 | BB_RANK_8 + def __hash__(self): + return (self.pawns & self.occupied_co[WHITE], + self.pawns & self.occupied_co[BLACK], + self.knights & self.occupied_co[WHITE], + self.knights & self.occupied_co[BLACK], + self.bishops & self.occupied_co[WHITE], + self.bishops & self.occupied_co[BLACK], + self.rooks & self.occupied_co[WHITE], + self.rooks & self.occupied_co[BLACK], + self.queens & self.occupied_co[WHITE], + self.queens & self.occupied_co[BLACK], + self.kings & self.occupied_co[WHITE], + self.kings & self.occupied_co[BLACK], + + + def reset_board(self) -> None: """Resets pieces to the starting position.""" self._reset_board() @@ -1495,6 +1511,8 @@ def __init__(self: BoardT, fen: Optional[str] = STARTING_FEN, *, chess960: bool self.reset() else: self.set_fen(fen) + def __hash__(self): + return super.__hash__ + self.turn + hash(self.ep_square) @property def legal_moves(self) -> LegalMoveGenerator: diff --git a/chess/engine.py b/chess/engine.py index c1cb30630..193d9ec20 100644 --- a/chess/engine.py +++ b/chess/engine.py @@ -2439,7 +2439,8 @@ def post(self, info: InfoDict) -> None: if not info: return string = info.get("string", "") - self.string += string + if len(string) > 0: + self.string += string + "\n" multipv = info.get("multipv", 1) info["string"] = self.string while len(self.multipv) < multipv: From 1cc69d847fe27779ca719e48cb425345174df43f Mon Sep 17 00:00:00 2001 From: Samuel Sonning Date: Wed, 23 Dec 2020 15:19:45 +0100 Subject: [PATCH 5/6] tjo --- chess/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chess/__init__.py b/chess/__init__.py index 93d0fcc9b..869fa7b55 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -596,8 +596,7 @@ def __hash__(self): self.queens & self.occupied_co[WHITE], self.queens & self.occupied_co[BLACK], self.kings & self.occupied_co[WHITE], - self.kings & self.occupied_co[BLACK], - + self.kings & self.occupied_co[BLACK]) def reset_board(self) -> None: @@ -1511,6 +1510,7 @@ def __init__(self: BoardT, fen: Optional[str] = STARTING_FEN, *, chess960: bool self.reset() else: self.set_fen(fen) + def __hash__(self): return super.__hash__ + self.turn + hash(self.ep_square) From a5e14b5c51345cabaca63106730d72e2940f8cf5 Mon Sep 17 00:00:00 2001 From: Samuel Sonning Date: Wed, 23 Dec 2020 15:27:23 +0100 Subject: [PATCH 6/6] fix --- chess/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chess/__init__.py b/chess/__init__.py index 869fa7b55..dd47dc342 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -585,7 +585,7 @@ def _reset_board(self) -> None: self.occupied = BB_RANK_1 | BB_RANK_2 | BB_RANK_7 | BB_RANK_8 def __hash__(self): - return (self.pawns & self.occupied_co[WHITE], + return hash((self.pawns & self.occupied_co[WHITE], self.pawns & self.occupied_co[BLACK], self.knights & self.occupied_co[WHITE], self.knights & self.occupied_co[BLACK], @@ -596,7 +596,7 @@ def __hash__(self): self.queens & self.occupied_co[WHITE], self.queens & self.occupied_co[BLACK], self.kings & self.occupied_co[WHITE], - self.kings & self.occupied_co[BLACK]) + self.kings & self.occupied_co[BLACK])) def reset_board(self) -> None: @@ -1512,7 +1512,7 @@ def __init__(self: BoardT, fen: Optional[str] = STARTING_FEN, *, chess960: bool self.set_fen(fen) def __hash__(self): - return super.__hash__ + self.turn + hash(self.ep_square) + return super(Board, self).__hash__() + self.turn + hash(self.ep_square) @property def legal_moves(self) -> LegalMoveGenerator: