Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions bench.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Performance benchmark for core ChessBoard operations."""
import sys
import time

Expand All @@ -7,12 +8,12 @@

board = ChessBoard(FULL_INIT_FEN)

# Test 1: get_pieces
# Test 1: get_all_fench_positions
start = time.perf_counter()
for _ in range(10000):
list(board.get_all_pieces())
list(board.get_all_fench_positions())
elapsed = time.perf_counter() - start
print(f"get_pieces x10000: {elapsed:.3f}s")
print(f"get_all_fench_positions x10000: {elapsed:.3f}s")

# Test 2: create_moves
start = time.perf_counter()
Expand Down
34 changes: 19 additions & 15 deletions demo/end_game_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# pylint: disable=import-error,no-member,not-callable,undefined-variable,wildcard-import
# pylint: disable=missing-class-docstring,invalid-name,attribute-defined-outside-init
# pylint: disable=redefined-builtin,anomalous-backslash-in-string,pointless-string-statement
# pylint: disable=broad-exception-caught

import logging
import os
Expand Down Expand Up @@ -197,14 +201,14 @@ def draw(self):
for x in range(9):
for y in range(10):
key = (x, y)
piece = self.board.get_piece(key)
if not piece:
fench = self.board.get_fench(key)
if not fench or fench == ".":
continue

image = self.pieces_image[piece.fench.lower()]
image = self.pieces_image[fench.lower()]
board_pos = pos_to_screen(key)

if piece.color == cchess.SIDE_RED:
if fench.isupper():
offset = (0, 0, 52, 52)
else:
offset = (53, 0, 52, 52)
Expand Down Expand Up @@ -240,18 +244,18 @@ def show_move(self, p_from, p_to):

for x in range(9):
for y in range(10):
key = Pos(x, y)
piece = self.board.get_piece(key)
if piece is None:
key = (x, y)
fench = self.board.get_fench(key)
if fench is None or fench == ".":
continue

board_pos = pos_to_screen(piece)
image = self.pieces_image[piece.fench.lower()]
offset = (int(piece.side) * 53, 0, 52, 52)
board_pos = pos_to_screen(key)
image = self.pieces_image[fench.lower()]
offset = (0, 0, 52, 52) if fench.isupper() else (53, 0, 52, 52)
if key == p_from:
self.screen.blit(image, step(), offset)
else:
self.screen.blit(image, board_pos(), offset)
self.screen.blit(image, board_pos, offset)

pygame.display.flip()
pygame.event.pump()
Expand Down Expand Up @@ -310,7 +314,7 @@ def __init__(self, file):
self.flile_eplib = self.file + ".eplib"

def load(self):
with open(self.file_src, "r") as f:
with open(self.file_src, "r", encoding="utf-8") as f:
lines = f.readlines()

for line in lines:
Expand All @@ -324,7 +328,7 @@ def load(self):

if os.path.isfile(self.file + ".eplib"):
with open(self.flile_eplib, "rb") as f:
done_array = bytearray(open(self.flile_eplib, "rb").read())
done_array = bytearray(f.read())
for i, it in enumerate(done_array):
if i >= len(self.games):
break
Expand Down Expand Up @@ -455,8 +459,8 @@ def next(self, index):

fen_moves.sort(key=lambda x: x[0])

with open(f"{type_name}.csv", "w") as f:
f.write(f"title, old_name, hint, fen, moves\n")
with open(f"{type_name}.csv", "w", encoding="utf-8") as f:
f.write("title, old_name, hint, fen, moves\n")
for move_len, old_name, fen, moves in fen_moves:
steps = (move_len + 1) // 2
f.write(f"{steps}步杀, {old_name}, {get_title_full(fen)}, {fen}, {moves}\n")
2 changes: 1 addition & 1 deletion src/cchess/io_xqf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

# pylint: disable=too-many-locals,too-many-branches,too-many-statements
# pylint: disable=too-many-locals,too-many-branches,too-many-statements,invalid-name,too-few-public-methods

import struct
from typing import Tuple
Expand Down
1 change: 0 additions & 1 deletion src/cchess/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ def make_branchs_tag(self, branch_id, depth): # pylint: disable=unused-argument

当前为桩实现,预留接口供未来扩展。
"""
... # 桩实现占位

def get_variations(self, include_me=False):
"""返回当前走子的所有分支(变招),可选择是否包含自身。"""
Expand Down