Skip to content

Commit 1176993

Browse files
Merge pull request #5 from shinoi2/main
支持 Engine
2 parents 06b24f8 + 1c65ee0 commit 1176993

6 files changed

Lines changed: 3194 additions & 1 deletion

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__
2+
build
3+
cchess.egg-info
4+
5+
*.pyc
6+
.vscode

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,27 @@ Board('rnb1kaCnr/4a4/1c5c1/p1p1p3p/6p2/9/P1P1P1P1P/1C7/9/RNBAKABNR b - - 0 3')
4040
>>> svg = cchess.svg.board(board, size=600, coordinates=True, orientation=cchess.RED, lastmove=board.peek(), checkers=board.checkers())
4141
```
4242

43+
## 配合 Uci Engine 使用
44+
```python
45+
>>> import cchess
46+
>>> import cchess.engine
47+
48+
>>> engine = cchess.engine.SimpleEngine.popen_uci("/path/to/pikafish")
49+
50+
>>> board = cchess.Board()
51+
>>> limit = cchess.engine.Limit(time=2.0)
52+
>>> engine.play(board, limit)
53+
<PlayResult at 0x7f47747ff6e0 (move=h2e2, ponder=h9g7, info={}, draw_offered=False, resigned=False)>
54+
55+
>>> engine.quit()
56+
```
57+
4358
## 安装方法
4459

4560
```shell script
4661
git clone https://github.com/windshadow233/python-chinese-chess.git
62+
cd python-chinese-chess
63+
pip install .
4764
```
4865

4966
## 功能
@@ -365,7 +382,7 @@ Move.from_uci('a4b6')
365382

366383
```python
367384
>>> board = cchess.Board()
368-
385+
369386
>>> board.push_notation('炮二平五')
370387
Move.from_uci('h2e2')
371388
>>> board.push_notation('砲8平5')

cchess/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ def push_uci(self, uci: str):
15951595
if not self.is_legal(move):
15961596
raise ValueError(f"illegal uci: {uci!r} in {self.fen()!r}")
15971597
self.push(move)
1598+
return move
15981599

15991600
def find_move(self, from_square: Square, to_square: Square) -> Move:
16001601
"""

0 commit comments

Comments
 (0)