Skip to content

Commit

Permalink
merge read_cbl to read_cbr file
Browse files Browse the repository at this point in the history
  • Loading branch information
walker8088 committed Sep 9, 2024
1 parent 50a0a1d commit 6653fef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/cchess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
from .read_pgn import read_from_pgn # noqa: F401
from .read_txt import read_from_txt # noqa: F401
from .read_cbf import read_from_cbf # noqa: F401
from .read_cbr import read_from_cbr # noqa: F401
from .read_cbl import read_from_cbl # noqa: F401
from .read_cbr import read_from_cbr, read_from_cbl # noqa: F401

__all__ = []

Expand Down
2 changes: 1 addition & 1 deletion src/cchess/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def read_from(file_name):
@staticmethod
def read_from_lib(file_name):
#在函数开始时才导入以避免循环导入
from .read_cbl import read_from_cbl
from .read_cbr import read_from_cbl

ext = pathlib.Path(file_name).suffix.lower()
if ext == '.cbl':
Expand Down
51 changes: 0 additions & 51 deletions src/cchess/read_cbl.py

This file was deleted.

32 changes: 31 additions & 1 deletion src/cchess/read_cbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,34 @@ def read_from_cbr(file_name):
contents = f.read()

return read_from_cbr_buffer(contents)



#-----------------------------------------------------#
def read_from_cbl(file_name):

with open(file_name, "rb") as f:
contents = f.read()

magic, _i1, book_count, lib_name = struct.unpack("<16s44si512s", contents[:576])

if magic != b'CCBridgeLibrary\x00':
return None

lib_info = {}
lib_info['name'] = cut_bytes_to_str(lib_name)
lib_info['games'] = []

index = 101952
count = 0
while index < len(contents):
book_buffer = contents[index:]
game = read_from_cbr_buffer(book_buffer)
game.info['index'] = count
lib_info['games'].append(game)
count += 1
index += 4096
#print(count, game.info)
#print(game.dump_iccs_moves())

return lib_info

0 comments on commit 6653fef

Please sign in to comment.