Skip to main content

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-py and rshogi-py-avx2 are mutually exclusive; install only one.
  • rshogi-py is 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 に保持されます。
  • 互換性のため、手番行より前にある '*commentinitial_comment に正規化して受理します。
  • GameRecordMetadata.comment は自由コメントではなく、KIF の 備考 / CSA の $NOTE / JKF header の 備考 に対応します。
  • to_csa() は move comment と初期局面コメントを '*comment として出力し、 write_kif() / write_ki2() / write_csa() は末尾改行つきで書き出します。

Project details


Download files

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

Source Distribution

rshogi_py-0.7.9.tar.gz (325.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rshogi_py-0.7.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (893.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

rshogi_py-0.7.9-cp314-cp314-win_amd64.whl (748.2 kB view details)

Uploaded CPython 3.14Windows x86-64

rshogi_py-0.7.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (920.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

rshogi_py-0.7.9-cp314-cp314-macosx_11_0_arm64.whl (845.2 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

rshogi_py-0.7.9-cp313-cp313-win_amd64.whl (728.9 kB view details)

Uploaded CPython 3.13Windows x86-64

rshogi_py-0.7.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (902.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rshogi_py-0.7.9-cp313-cp313-macosx_11_0_arm64.whl (827.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rshogi_py-0.7.9-cp312-cp312-win_amd64.whl (728.2 kB view details)

Uploaded CPython 3.12Windows x86-64

rshogi_py-0.7.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (901.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rshogi_py-0.7.9-cp312-cp312-macosx_11_0_arm64.whl (826.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rshogi_py-0.7.9-cp311-cp311-win_amd64.whl (721.1 kB view details)

Uploaded CPython 3.11Windows x86-64

rshogi_py-0.7.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (893.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rshogi_py-0.7.9-cp311-cp311-macosx_11_0_arm64.whl (832.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rshogi_py-0.7.9-cp310-cp310-win_amd64.whl (721.2 kB view details)

Uploaded CPython 3.10Windows x86-64

rshogi_py-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (894.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Hashes for rshogi_py-0.7.9.tar.gz
Algorithm Hash digest
SHA256 39036c12e041045f66219cd89173ecbfede522b04afe9f383c7b78895f75cb8f
MD5 ca91231493cdda545809a392c7218751
BLAKE2b-256 eccfc44c3cfda7727badc5568d5b80d522cf11d0f39030cb461d94bd3af7cdd9

See more details on using hashes here.

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

File hashes

Hashes for rshogi_py-0.7.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 969f071949ef6f1e2092b099cf5a3b8d6c44dc449a3264750fe602eed07c378f
MD5 ddb7724d873ab2098db620ee6f151957
BLAKE2b-256 4699b7361a4479b72b42e9fdc67230a206d41292420aa9a5dfc242c307fa1157

See more details on using hashes here.

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

Hashes for rshogi_py-0.7.9-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 471d4004d4f4e4e0134a0f25df3dc7bd76096a6ab39f33557c899e91dc647907
MD5 4ef60fb0acd8744c4b87187fe3b45750
BLAKE2b-256 eac9c1482aa83f81034a840d1288baa8f72658472f981302502f81f11c6ed537

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 035aca04ab5b0212082c113ae5f68d27a746de0a0817b29b37443496a99fe2ab
MD5 c387e97bea91a4b7656655a6bc16bb01
BLAKE2b-256 a7639081ae12156ef6d89271c8828caf047d4249a78d9d7ccee45bb2d89050a5

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54d4aa279a1c216e562a3cde669329e6f1e668ac9c6f9284dff0c8fbd5ad9611
MD5 e813f613532c344ae81521b02b36388c
BLAKE2b-256 c4d2b17ba9e73d77cebdb384e233f5167b79f6a6481790536316c6080d7d67b6

See more details on using hashes here.

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

Hashes for rshogi_py-0.7.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aa9eb84248ac507dd3ef7c40b046ebbbcbeaf99fb809b0a661024958edf95387
MD5 4cb4ad8bd88cb3a49c4e5b1e0f29cc74
BLAKE2b-256 916d7a21fcaaa0b210d04afcf4f636d852688ac261a9494d5d3f25dad29465cb

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b903afdafc4b3fd4b0db7c6165b2bf447601e253e517177310fee7fc4e3cd9f7
MD5 ba5e46a5838105579b5b8dcc0de503e9
BLAKE2b-256 822c10e7cbdda51db1ed39822e4eb87da92968d7f299f54436ae55c88c26d456

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9271e516204c15416e1f7c75086cfbcfe5f8bc2098bba844990abb5492c2f88f
MD5 53f199a733c8c457fa442e4398a312cc
BLAKE2b-256 106ca06ed664f5c9fd795f696244c50a524d648ade077c724e4b72e633884a21

See more details on using hashes here.

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

Hashes for rshogi_py-0.7.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a2e4dcb0301f00c982db9a3b0680a6aa05605ceb903185d0fae926340ee187c1
MD5 c40e38a1bcc81d4e0837d420ec4b5b3f
BLAKE2b-256 587bb6800ed065f89289a4f63311323474c6e6fa3289a77de46a7cfd493a4f84

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 962ced6ab18902313dac6a744f20639b875e44ef85a7e5f2d7295946bd6be8b7
MD5 0a7e9508c4f771cd177ca0bf17a3222f
BLAKE2b-256 b209d67ff67d2400823a1c9d55c2a82cff12f8c898227ca44349bdfb38df3de0

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 728af1ac0f15e0dce2f2a3e084ee16807ef73619f43512e25b443944eacac0c1
MD5 8cbce6b8e38a33468e38808ed5eb66d9
BLAKE2b-256 4526b377f0b15fa33c49d8c3fd0125af5a42bd0e14b4ab41adacde6f95996a05

See more details on using hashes here.

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

Hashes for rshogi_py-0.7.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 51903b0594d3a733f3894b5142719e72ea62650fd9aa05b9aae7c1d0ae648707
MD5 a08df3ac9ca18cc0473c1e37f291463b
BLAKE2b-256 b1f468fb20d1eb3cfe81e0a9d523770e499e612ffd18a5992c2f4bc597ee777d

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6649c4cdd672bc4f627d32395aad2d62221ca7cd1cbe58c569def310b000ab03
MD5 955bef6dcd8787207b2c79b89a903908
BLAKE2b-256 0932a9a1435fdb2ba8309defcd3065b0d759e025b87ca3718006cc1241ee3219

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53784e453c361de807bfff6b011ffeeffeb6f7718a58def8ef4a3ed626feafa1
MD5 4bb21e82b8694c608cfe1e1a1b1db7ff
BLAKE2b-256 2cfa28ad7c38a728292ed411ae0178f601f6e648c44346205991bf630ea7d7c8

See more details on using hashes here.

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

Hashes for rshogi_py-0.7.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1d534cae0bb194b2d7b46404758b7f80e3b39ee6fea0cf915347db47fe82793d
MD5 44609e8d70a106277ed8a1ef54a6f7d7
BLAKE2b-256 54d21fdfc1a0b13f27122dfd3c356644b9dfe2aa5b27a16141d599531de8e526

See more details on using hashes here.

File details

Details for the file rshogi_py-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.7.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 12f1a87363889be6e6d31f43be79d670b6a20ae48bb7904a9d3b340f52011e50
MD5 a850e851fd20bc6317c991227a748578
BLAKE2b-256 206a6ef537bb0740c34875abab847bd9ab43c06b3e57213cb45932dc55bc78f6

See more details on using hashes here.

Supported by

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