Skip to main content

ChineseChess (AKA XiangQi) library

Project description

cchess

cchess是一个Python版的中国象棋库,主要功能如下:

##棋盘显示

board_strs = board.text_view()
print()
for s in board_strs:
    print(s)
#or    
board.print_board()

##走子(内部格式), 中文显示

move = board.copy().move((0,0),(0,1))
print(move.to_text())

##走子(ICCS纵线格式),中文显示

move = board.copy().move_iccs('a0a1')
print(move.to_text())

##走子(中文格式,尚待完善),中文显示

move = board.copy().move_text('车九进一')
print(move.to_text())

##产生某个棋子的合法走子

moves = board.create_piece_moves((0,0))
for mv in moves:
    move = board.copy().move(*mv)
    print(move.to_text())

##产生所有合法走子

moves = board.create_moves()
for mv in moves:
    move = board.copy().move(*mv)
    print(move.to_text())

##将军检测

board.from_fen('3k5/9/9/9/9/3R5/9/9/9/4K4 w - - 0 1') 
print(board.is_checking()) #True

##将死对方检测

print(board.is_checkmate())      #True 

##走子被将军检测

board.from_fen('3k5/9/9/9/9/3R5/9/9/9/4K4 b - - 0 1')
mv = move.from_iccs('d9e9') 
print(board.is_checked_move(*mv)) #True

##被对方将死检测

print(board.no_moves())    #True

##读取xqf文件, 显示棋谱

#8.读取xqf文件, 显示棋谱
game = read_from_xqf("WildHouse.xqf")
game.init_board.print_board()
board_strs = game.init_board.text_view()
print()
for s in board_strs:
    print(s)
    
game.print_text_moves()

以上参见demo/demo_base.py

##加载引擎进行对弈

参见demo/end_game.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

cchess-1.24.3-py3-none-any.whl (80.3 kB view details)

Uploaded Python 3

File details

Details for the file cchess-1.24.3-py3-none-any.whl.

File metadata

  • Download URL: cchess-1.24.3-py3-none-any.whl
  • Upload date:
  • Size: 80.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for cchess-1.24.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a31d7a6f25415077f5f4199690a7aeb13a36e31ec6ed2f7f742219f8f07f5b4
MD5 7c4a6c9781476431ccb860287599101b
BLAKE2b-256 5b5878fd5790c3b4fbaf8ce8f71f8191820800ae4a18e99eb504ec652b924d6c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page