Skip to main content

Python tools for shogi board handling, move legality, records, and training-data formats.

Reason this release was yanked:

Project renamed to rsshogi. Use rsshogi instead.

Project description

rshogi-py

rshogi-py は、Python から将棋の局面・指し手・合法性・棋譜・学習データ形式を扱うための ライブラリです。

English: rshogi-py provides Python tools for shogi board handling, move legality, game records, policy labels, and dataset formats.

Rust 製の rshogi core を内部で利用していますが、通常の Python モジュールとして使えるように 構成しています。通常はこの標準ビルドを利用してください。AVX2 対応の x86_64 CPU で AVX2 最適化版を使いたい場合は rshogi-py-avx2 を利用します。

Python API は cshogi から影響を受けています。

できること

  • SFEN / USI から局面を構築し、指し手を適用して更新する
  • 指し手の生成・検証を行い、局面を SFEN として出力する
  • KIF / KI2 / CSA / JKF / SFEN などの棋譜形式を読み書きする
  • policy label や学習データ向けに指し手・局面を変換する
  • データセット向けに NumPy と扱いやすい packed position 形式を利用する

開発用インストール

python -m pip install maturin
maturin develop -m crates/rshogi-py/pyproject.toml

AVX2 ビルド

rshogi-py-avx2 は、AVX2 対応 x86_64 CPU 向けに最適化した同じ Python モジュールです。

python -m pip install rshogi-py-avx2

注意

  • rshogi-pyrshogi-py-avx2 は同時にインストールせず、どちらか一方だけを利用してください。
  • 幅広い環境では rshogi-py が安全な標準選択です。
  • 学習向けの policy label 変換は rshogi.policy から利用できます。

Policy Label

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

クイック例

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"

構造化 import

rshogi-py は用途別の submodule から import できます。

# 型と定数
from rshogi.types import Color, PieceType, Square
from rshogi.core import Move, Move32

# 盤面
from rshogi.core import Board, PositionState, ValidationIssue, ValidationReport

# 棋譜
from rshogi.record import Record, RecordMetadata, GameResult

# 棋譜変換
record = Record.from_kif_str(kif_text)
kif_text = record.to_kif()

# 棋譜ファイル I/O
record = Record.from_kif_file("example.kif")
record.write_kif("example_out.kif")

# NumPy dtype
from rshogi.numpy import (
    PackedSfen,
    PackedSfenValue,
    HuffmanCodedPos,
    HuffmanCodedPosAndEval,
)

# Policy label
from rshogi.policy import move_label, compact_move_label

基本的には submodule から import してください。

from rshogi.core import Board
from rshogi.core import Move
from rshogi.record import Record

棋譜 I/O の注意

Record の棋譜 I/O は、内部の rshogi 実装と同じ互換方針で動作します。

  • KIF/KI2 は ShogiHome/tsshogi 系の実務互換と shogi-validator 寄りの整形を意識しています。
  • 変化手順と終局要約が同居する場合、to_kif() / to_ki2()変化:... を先に、 まで... を最後に出力します。
  • from_kif_str() / from_ki2_str() で読んだ初手前コメントは Record.initial_comment に保持され、to_kif() / to_ki2() で 1 手目の前に戻ります。
  • from_csa_str() / from_csa_file() は CSA 3.0 に合わせて '*comment だけを プログラムが読むコメントとして受理し、plain な 'comment は読み飛ばします。 受理した開始局面コメントは Record.initial_comment に保持されます。
  • 互換性のため、手番行より前にある '*commentinitial_comment に正規化して受理します。
  • RecordMetadata.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

rshogi_py-0.11.0.tar.gz (451.1 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.11.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

rshogi_py-0.11.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

rshogi_py-0.11.0-cp314-cp314-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.14Windows x86-64

rshogi_py-0.11.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

rshogi_py-0.11.0-cp314-cp314-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

rshogi_py-0.11.0-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

rshogi_py-0.11.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rshogi_py-0.11.0-cp313-cp313-macosx_11_0_arm64.whl (993.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rshogi_py-0.11.0-cp312-cp312-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.12Windows x86-64

rshogi_py-0.11.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rshogi_py-0.11.0-cp312-cp312-macosx_11_0_arm64.whl (992.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rshogi_py-0.11.0-cp311-cp311-win_amd64.whl (998.8 kB view details)

Uploaded CPython 3.11Windows x86-64

rshogi_py-0.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rshogi_py-0.11.0-cp311-cp311-macosx_11_0_arm64.whl (997.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rshogi_py-0.11.0-cp310-cp310-win_amd64.whl (998.7 kB view details)

Uploaded CPython 3.10Windows x86-64

rshogi_py-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file rshogi_py-0.11.0.tar.gz.

File metadata

  • Download URL: rshogi_py-0.11.0.tar.gz
  • Upload date:
  • Size: 451.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rshogi_py-0.11.0.tar.gz
Algorithm Hash digest
SHA256 dfc93fb6b2891c365ebf83be833e2c0cfae3265082cfdda8c3589b6c2e5c66f8
MD5 59f070f8e3075ed5a84e709c10419a67
BLAKE2b-256 2797e415dd7badee6a9d36c84dd5d37fb4b373189bda676b8c4e3bc5efdf8389

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.11.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 100a1e7b603497759c7df004431f2d5c6b8612179bd88ddc5559e8181ebb34d2
MD5 ac2e21f64f91db3c95d0c7b87bdb6262
BLAKE2b-256 f9973a1f2ea00925c1c54892ebe34abfdd6183367bac1f0a567e266e208b060f

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a4a1bf2df35d829d506829255040673ab88467e79e1b62195a60be2cb48cee9
MD5 09d83fd80acc1f31dd268932804504f3
BLAKE2b-256 2ea3c30d390a931642738f10357478414a54eb13d694a61cd9b1c25581352896

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: rshogi_py-0.11.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rshogi_py-0.11.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2e70ed36aabf696d82b28c724b7db0e84f5559d298b7624109f391ccb6bb1f81
MD5 492100d2dba69a4cda4581801aebc40a
BLAKE2b-256 f6c97c25986f3829d572a90456b5622c801dc669364359b1b505b1f10b915801

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb7688c56a7acd9fe5f8dc18f01737c516946cd998dfa7a2c075ab80d7a8af29
MD5 3359459157c0a7113de9ef92b96f0f24
BLAKE2b-256 3fe6b2b40e1e1d0940306949e92042757b3d28a024f35ceb5b44630663cc4627

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a1b6857daf6f5ee1ccab3f515ee1d4683f4d9631a5f4c9bf3285f5f66bdbcac
MD5 15408220519340cd9504bf56aae5c3cb
BLAKE2b-256 f927917320607f7469d2fddf052965c11f5a1c311453ecbca01bda5f765d74ff

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: rshogi_py-0.11.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rshogi_py-0.11.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3bbdf6d7dddc97213656f269e2ed651fd6a41facb00d805e75565bbb111b3fbd
MD5 6705c8e8cd642c19e6997b77c3f3539f
BLAKE2b-256 cc5a9f214a59a056ea18fa401b7b8354346c665cbacd083869d471af8aa362c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b525d3a5f5ecda8f3d58a699ffa009618f329c2f49ab4cf9ea8f236ec263c991
MD5 44254926bc8a158ebeb9f26876ae9b51
BLAKE2b-256 b51654e9ee14182a0ca484fce814fb47259ed84d376a4edd8520fc9a37675502

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 556084830f7d62207cb87c7c6da0aecd80376c4133e71622e752e731da9f0d24
MD5 8eb033a6c0be3314b45f20a13f3f4e63
BLAKE2b-256 08f42059facc57a80c9ef49d6f7b3e07bec785bd5670f5ceb54ba0eb9c59c247

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: rshogi_py-0.11.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rshogi_py-0.11.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8954785260f797ad4b1ad55d4df62f6394b2833078977473838de59a9ec7bc21
MD5 8fcb45cada658ae58e88e4c4638d9156
BLAKE2b-256 445752365d25cf75c17e86f0627caf809913d7fc6c34bb85e738e7d1346b720a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 638a3b607de4debdb75432543fc16aeff977298284d8f74c669e8b11d9584483
MD5 ac5aa0859b5568a697dc8776bf7bd297
BLAKE2b-256 63e5548ba2580d47f6199b30650744953e1662d663c2c32c0ba1dd475abe266f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e2c3224e8e4e026d6649e3a875fd68293ab6e093d9b9be80e8a0fbaf0a000fc
MD5 e51557c62bd9aa1459f253e1eb24e860
BLAKE2b-256 f4f7797432bb019d11a8c19d6d3b237799e22e805512f59ea59c17c350fd720b

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rshogi_py-0.11.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 998.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rshogi_py-0.11.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3b2cc6423421fd911153e1bf93b3562715c23b55415bcb0c6cd029fb37021a21
MD5 277b8f4ac44fd220a640f005a71639e8
BLAKE2b-256 4ab2d6801a27708b0872d8ed3e3713dea88c92a2e3f14ecfd6c577fcf2497a09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f3e4d72a7dbefa702f309a74b12b1206a07ee31a634cd3973835616c5756ce04
MD5 7840beed767b6b945b9ae9fd46b66980
BLAKE2b-256 f49c3affebb8ce7f9f09d9e5765936749a14c69a32dee6fd3376775721c98d68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f248dee6566827fa12ef73b8def14d60ffd09379a2a8874ae7380099fa5909b
MD5 7514eef5a5b2e90cdcbf1523cc67f218
BLAKE2b-256 eb4c1a6c13d5a0cef9e46c4ded71e37fbb4b3979d9d4f6c8b160328cc0c51815

See more details on using hashes here.

File details

Details for the file rshogi_py-0.11.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: rshogi_py-0.11.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 998.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rshogi_py-0.11.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 829f4cbfb36693b2ad3bfa4f829a3d6f5120b7aa56021216f65fcc1bf1a40791
MD5 6e20d56b4f2ba6d7e69805a0a38167b8
BLAKE2b-256 700ceb031ba29512acc84cd9aaf9284046a98d5bd66679abcf03ddd16a9dfad8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rshogi_py-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7b617066fe16ba855e107e7dc642b6f738c33281618126b45e7d40212829017
MD5 54fa27fd538de24c55bad6bbcda70359
BLAKE2b-256 c52946c9ec46faa92e1dc6e2e794d71e58e24d21a0126c87e3baf862a033f82d

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