From fcbcc3cdefeb2590cd7c77e979a897e97ca1cb3d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 4 Apr 2024 00:41:46 +0100 Subject: [PATCH] Add 'from_gdb' constructors in GDB utils --- utils/gdb/seer_pretty_printers.py | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/utils/gdb/seer_pretty_printers.py b/utils/gdb/seer_pretty_printers.py index 47bce35..56caadb 100644 --- a/utils/gdb/seer_pretty_printers.py +++ b/utils/gdb/seer_pretty_printers.py @@ -28,6 +28,10 @@ class Square(object): val = val._val self._val = val + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + @classmethod def from_file_rank(cls, file, rank): return cls(file * 8 + rank) @@ -54,6 +58,10 @@ class Bitboard(object): val = val._val self._val = val + @classmethod + def from_gdb(cls, val): + return cls(int(val["__0"])) + def __str__(self): return "[" + ", ".join(map(str, self.squares)) + "]" @@ -80,6 +88,10 @@ class CastleRights(enum.IntEnum): QUEEN_SIDE = 2 BOTH_SIDES = 3 + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + def __str__(self): return self.name.title().replace("_", "") @@ -93,6 +105,10 @@ class Color(enum.IntEnum): WHITE = 0 BLACK = 1 + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + def __str__(self): return self.name.title() @@ -112,6 +128,10 @@ class File(enum.IntEnum): G = 6 H = 7 + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + def __str__(self): return self.name.title() @@ -131,6 +151,10 @@ class Rank(enum.IntEnum): Seventh = 6 Eighth = 7 + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + def __str__(self): return self.name.title() @@ -148,6 +172,10 @@ class Piece(enum.IntEnum): KNIGHT = 4 PAWN = 5 + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + def __str__(self): return self.name.title() @@ -179,6 +207,10 @@ class Move(object): def __init__(self, val): self._val = val + @classmethod + def from_gdb(cls, val): + return cls(int(val)) + @property def piece(self): return Piece(self._val >> self.PIECE_SHIFT & self.PIECE_MASK)