Add 'from_gdb' constructors in GDB utils
This commit is contained in:
parent
f0edd0abc7
commit
fcbcc3cdef
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue