Python bindings for the rshogi core library.
Project description
rshogi-py
Python bindings for the rshogi Rust crate.
This package provides the standard build of the rshogi Python module.
If you want an AVX2-optimized build, use
rshogi-py-avx2.
Development Install
python -m pip install maturin
maturin develop -m crates/rshogi-py/pyproject.toml
AVX2 Build
rshogi-py-avx2 is an AVX2-enabled build of the same Python module.
python -m pip install rshogi-py-avx2
Notes
rshogi-pyandrshogi-py-avx2are mutually exclusive; install only one.rshogi-pyis the safest default for broad compatibility.- policy 学習向けの move label 変換は
rshogi.policyから利用できます。
Policy Labels
from rshogi.core import Move
from rshogi.policy import compact_move_label, move_label
from rshogi.types import Color
mv = Move.from_usi("7g7f")
label = move_label(mv, Color.BLACK)
compact = compact_move_label(mv, Color.BLACK)
print(label) # 2187 クラス
print(compact) # 1496 クラス or None
Quick Example
from rshogi.core import Board
board = Board()
board.apply_usi("7g7f")
print(board.to_sfen())
raw-state を Python から直接編集することもできます。
from rshogi.core import Board
from rshogi.types import Color, Piece, PieceType, Square
board = Board()
state = board.to_position_state()
state.set_piece(Square.from_usi("7g"), Piece(0))
state.set_piece(Square.from_usi("7f"), Piece.from_color_type(Color.BLACK, PieceType.PAWN))
state.ply = 42
board.set_position_state(state)
report = board.validate_all()
print(board.to_sfen())
print(report.is_valid())
USI の position 文字列を直接扱うこともできます。
from rshogi.core import Board, normalize_usi_position, parse_usi_position
board = Board()
board.set_usi_position("position startpos moves 7g7f 3c3d")
board2 = parse_usi_position("startpos moves 7g7f")
print(board2.to_sfen())
print(normalize_usi_position("position startpos")) # "startpos"
cshogi / Apery Compatibility
rshogi can interoperate with cshogi / Apery move and training-data formats.
from rshogi.core import Board, Move
board = Board()
move = Move.from_usi("7g7f")
apery = move.to_apery()
apery32 = board.apery_move32_from_move(move)
hcpe = board.to_hcpe(best_move=apery, score=120, game_result="BLACK_WIN")
print(int(apery))
print(apery32.to_usi())
print(len(hcpe)) # 38
Structured Imports
rshogi provides structured imports through submodules for better organization:
# Types and constants
from rshogi.types import Color, PieceType, Square
from rshogi.core import Move, Move32, AperyMove, AperyMove32
# Board
from rshogi.core import Board, PositionState, ValidationIssue, ValidationReport
# Records
from rshogi.record import GameRecord, GameRecordMetadata, GameResult
# Record conversion
record = GameRecord.from_kif_str(kif_text)
kif_text = record.to_kif()
# Record file I/O
record = GameRecord.from_kif_file("example.kif")
record.write_kif("example_out.kif")
# NumPy dtypes
from rshogi.numpy import (
PackedSfen,
PackedSfenValue,
HuffmanCodedPos,
HuffmanCodedPosAndEval,
)
# Policy labels
from rshogi.policy import move_label, compact_move_label
Use submodules for all imports:
from rshogi.core import Board
from rshogi.core import Move
from rshogi.record import GameRecord
Record I/O Notes
GameRecord の棋譜 I/O は Rust core と同じ互換方針で動作します。
- KIF/KI2 は ShogiHome/tsshogi 系の実務互換と
shogi-validator寄りの整形を意識しています。 - 変化手順と終局要約が同居する場合、
to_kif()/to_ki2()は変化:...を先に、まで...を最後に出力します。 from_kif_str()/from_ki2_str()で読んだ初手前コメントはGameRecord.initial_commentに保持され、to_kif()/to_ki2()で 1 手目の前に戻ります。from_csa_str()/from_csa_file()は CSA 3.0 に合わせて'*commentだけを プログラムが読むコメントとして受理し、plain な'commentは読み飛ばします。 受理した開始局面コメントはGameRecord.initial_commentに保持されます。- 互換性のため、手番行より前にある
'*commentもinitial_commentに正規化して受理します。 GameRecordMetadata.commentは自由コメントではなく、KIF の備考/ CSA の$NOTE/ JKF header の備考に対応します。to_csa()は move comment と初期局面コメントを'*commentとして出力し、write_kif()/write_ki2()/write_csa()は末尾改行つきで書き出します。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rshogi_py-0.7.9.tar.gz.
File metadata
- Download URL: rshogi_py-0.7.9.tar.gz
- Upload date:
- Size: 325.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39036c12e041045f66219cd89173ecbfede522b04afe9f383c7b78895f75cb8f
|
|
| MD5 |
ca91231493cdda545809a392c7218751
|
|
| BLAKE2b-256 |
eccfc44c3cfda7727badc5568d5b80d522cf11d0f39030cb461d94bd3af7cdd9
|
File details
Details for the file rshogi_py-0.7.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 893.2 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
969f071949ef6f1e2092b099cf5a3b8d6c44dc449a3264750fe602eed07c378f
|
|
| MD5 |
ddb7724d873ab2098db620ee6f151957
|
|
| BLAKE2b-256 |
4699b7361a4479b72b42e9fdc67230a206d41292420aa9a5dfc242c307fa1157
|
File details
Details for the file rshogi_py-0.7.9-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 748.2 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
471d4004d4f4e4e0134a0f25df3dc7bd76096a6ab39f33557c899e91dc647907
|
|
| MD5 |
4ef60fb0acd8744c4b87187fe3b45750
|
|
| BLAKE2b-256 |
eac9c1482aa83f81034a840d1288baa8f72658472f981302502f81f11c6ed537
|
File details
Details for the file rshogi_py-0.7.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 920.9 kB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
035aca04ab5b0212082c113ae5f68d27a746de0a0817b29b37443496a99fe2ab
|
|
| MD5 |
c387e97bea91a4b7656655a6bc16bb01
|
|
| BLAKE2b-256 |
a7639081ae12156ef6d89271c8828caf047d4249a78d9d7ccee45bb2d89050a5
|
File details
Details for the file rshogi_py-0.7.9-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 845.2 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54d4aa279a1c216e562a3cde669329e6f1e668ac9c6f9284dff0c8fbd5ad9611
|
|
| MD5 |
e813f613532c344ae81521b02b36388c
|
|
| BLAKE2b-256 |
c4d2b17ba9e73d77cebdb384e233f5167b79f6a6481790536316c6080d7d67b6
|
File details
Details for the file rshogi_py-0.7.9-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 728.9 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa9eb84248ac507dd3ef7c40b046ebbbcbeaf99fb809b0a661024958edf95387
|
|
| MD5 |
4cb4ad8bd88cb3a49c4e5b1e0f29cc74
|
|
| BLAKE2b-256 |
916d7a21fcaaa0b210d04afcf4f636d852688ac261a9494d5d3f25dad29465cb
|
File details
Details for the file rshogi_py-0.7.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 902.6 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b903afdafc4b3fd4b0db7c6165b2bf447601e253e517177310fee7fc4e3cd9f7
|
|
| MD5 |
ba5e46a5838105579b5b8dcc0de503e9
|
|
| BLAKE2b-256 |
822c10e7cbdda51db1ed39822e4eb87da92968d7f299f54436ae55c88c26d456
|
File details
Details for the file rshogi_py-0.7.9-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 827.1 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9271e516204c15416e1f7c75086cfbcfe5f8bc2098bba844990abb5492c2f88f
|
|
| MD5 |
53f199a733c8c457fa442e4398a312cc
|
|
| BLAKE2b-256 |
106ca06ed664f5c9fd795f696244c50a524d648ade077c724e4b72e633884a21
|
File details
Details for the file rshogi_py-0.7.9-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 728.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2e4dcb0301f00c982db9a3b0680a6aa05605ceb903185d0fae926340ee187c1
|
|
| MD5 |
c40e38a1bcc81d4e0837d420ec4b5b3f
|
|
| BLAKE2b-256 |
587bb6800ed065f89289a4f63311323474c6e6fa3289a77de46a7cfd493a4f84
|
File details
Details for the file rshogi_py-0.7.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 901.1 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
962ced6ab18902313dac6a744f20639b875e44ef85a7e5f2d7295946bd6be8b7
|
|
| MD5 |
0a7e9508c4f771cd177ca0bf17a3222f
|
|
| BLAKE2b-256 |
b209d67ff67d2400823a1c9d55c2a82cff12f8c898227ca44349bdfb38df3de0
|
File details
Details for the file rshogi_py-0.7.9-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 826.0 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
728af1ac0f15e0dce2f2a3e084ee16807ef73619f43512e25b443944eacac0c1
|
|
| MD5 |
8cbce6b8e38a33468e38808ed5eb66d9
|
|
| BLAKE2b-256 |
4526b377f0b15fa33c49d8c3fd0125af5a42bd0e14b4ab41adacde6f95996a05
|
File details
Details for the file rshogi_py-0.7.9-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 721.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51903b0594d3a733f3894b5142719e72ea62650fd9aa05b9aae7c1d0ae648707
|
|
| MD5 |
a08df3ac9ca18cc0473c1e37f291463b
|
|
| BLAKE2b-256 |
b1f468fb20d1eb3cfe81e0a9d523770e499e612ffd18a5992c2f4bc597ee777d
|
File details
Details for the file rshogi_py-0.7.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 893.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6649c4cdd672bc4f627d32395aad2d62221ca7cd1cbe58c569def310b000ab03
|
|
| MD5 |
955bef6dcd8787207b2c79b89a903908
|
|
| BLAKE2b-256 |
0932a9a1435fdb2ba8309defcd3065b0d759e025b87ca3718006cc1241ee3219
|
File details
Details for the file rshogi_py-0.7.9-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 832.5 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53784e453c361de807bfff6b011ffeeffeb6f7718a58def8ef4a3ed626feafa1
|
|
| MD5 |
4bb21e82b8694c608cfe1e1a1b1db7ff
|
|
| BLAKE2b-256 |
2cfa28ad7c38a728292ed411ae0178f601f6e648c44346205991bf630ea7d7c8
|
File details
Details for the file rshogi_py-0.7.9-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 721.2 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d534cae0bb194b2d7b46404758b7f80e3b39ee6fea0cf915347db47fe82793d
|
|
| MD5 |
44609e8d70a106277ed8a1ef54a6f7d7
|
|
| BLAKE2b-256 |
54d21fdfc1a0b13f27122dfd3c356644b9dfe2aa5b27a16141d599531de8e526
|
File details
Details for the file rshogi_py-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rshogi_py-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 894.0 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f1a87363889be6e6d31f43be79d670b6a20ae48bb7904a9d3b340f52011e50
|
|
| MD5 |
a850e851fd20bc6317c991227a748578
|
|
| BLAKE2b-256 |
206a6ef537bb0740c34875abab847bd9ab43c06b3e57213cb45932dc55bc78f6
|