Skip to content

Commit

Permalink
Support pickling tablebases
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Mar 25, 2015
1 parent db28cd4 commit 09b1d17
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions chess/syzygy.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,21 @@ def __enter__(self):
def __exit__(self, type, value, traceback):
self.close()

def __getstate__(self):
state = self.__dict__.copy()
del state["fd"]
del state["data"]
return state

def __setstate__(self, state):
self.__dict__.update(state)
self.__init__(self.directory, self.filename, self.suffix)


class WdlTable(Table):
def __init__(self, directory, filename):
super(WdlTable, self).__init__(directory, filename, ".rtbw")

def __init__(self, directory, filename, suffix=".rtbw"):
super(WdlTable, self).__init__(directory, filename, suffix)

assert WDL_MAGIC[0] == self.read_ubyte(0)
assert WDL_MAGIC[1] == self.read_ubyte(1)
Expand Down Expand Up @@ -1069,8 +1080,8 @@ def probe_wdl_table(self, board):

class DtzTable(Table):

def __init__(self, directory, filename):
super(DtzTable, self).__init__(directory, filename, ".rtbz")
def __init__(self, directory, filename, suffix=".rtbz"):
super(DtzTable, self).__init__(directory, filename, suffix)

assert DTZ_MAGIC[0] == self.read_ubyte(0)
assert DTZ_MAGIC[1] == self.read_ubyte(1)
Expand Down

0 comments on commit 09b1d17

Please sign in to comment.