Skip to content

Commit

Permalink
v1.25.1
Browse files Browse the repository at this point in the history
  • Loading branch information
walker8088 committed Dec 26, 2024
1 parent 7f72052 commit a0d2a4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "cchess"
version = "1.24.5"
version = "1.25.1"
description = "ChineseChess (AKA XiangQi) library"
authors = ["walker8088 <walker8088@gmail.com>"]
license = "LGPL3"
Expand Down
7 changes: 5 additions & 2 deletions src/cchess/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ def get_move_color(self):
def put_fench(self, fench, pos):
self._board[pos[1]][pos[0]] = fench

def remove_fench(self, pos):
def pop_fench(self, pos):
fench = self._board[pos[1]][pos[0]]
self._board[pos[1]][pos[0]] = None


return fench

def get_fench(self, pos):
if pos[0] < 0 or pos[0] > 8 :
return None
Expand Down
7 changes: 4 additions & 3 deletions src/cchess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ def _send_cmd(self, cmd_str):
if self.process.returncode is not None:
self.engine_status = EngineStatus.ERROR
raise EngineErrorException(f"程序异常退出,退出码:{self.process.returncode}")

try:
cmd_bytes = f'{cmd_str}\r\n'
self.pin.write(cmd_bytes)
self.pin.flush()
except Exception as e:
logger.error(f"Send cmd [{cmd_str}] ERROR: {e}")

raise EngineErrorException(f"程序异常退出,退出码:{self.process.returncode}")

if self.process.returncode is not None:
self.engine_status = EngineStatus.ERROR
raise EngineErrorException(f"程序异常退出,退出码:{self.process.returncode}")
Expand Down Expand Up @@ -462,7 +463,7 @@ def get_fen_score(self, fen):
#再处理出现mate时,score没分的情况
if ('score' not in action) and ('mate' in action):
mate = 1 if action['mate'] > 0 else -1
action['score'] = 39999 * mate
action['score'] = 29999 * mate

#最后处理分数都换算到红方得分的情况
#move_color = board.get_move_color()
Expand Down
11 changes: 7 additions & 4 deletions src/cchess/piece.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,29 @@ def create(board, fench, pos):
#王
class King(Piece):
def is_valid_pos(self, pos):
#因为存在王杀王的情况,王可以放到对方的九宫中,所以不再根据红黑判断王的九宫在哪一边
#放置棋子要把各自的王放到自己一方
if not super().is_valid_pos(pos):
return False

if pos[0] < 3 or pos[0] > 5:
return False

if (pos[1] > 2) and (pos[1] < 7):
if (self.color == RED) and (pos[1] > 2):
return False

if (self.color == BLACK) and (pos[1] < 7):
return False

return True

def is_valid_move(self, pos_to):

#face to face
#首先判断“白脸将”条件
k2 = self.board.get_king(opposite_color(self.color))
if (self.x == k2.x) and (pos_to[1]
== k2.y) and (self.board.count_y_line_in(
self.x, self.y, k2.y) == 0):
#白脸将,王杀王
#白脸将
return True

if not self.is_valid_pos(pos_to):
Expand Down

0 comments on commit a0d2a4f

Please sign in to comment.