Skip to main content

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

Project description

rsshogi

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

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

Rust 製の rsshogi core を内部で利用していますが、一般的な Python モジュールと同じように 使えるよう構成しています。まずはこの標準ビルドを利用してください。AVX2 対応の x86_64 CPU で AVX2 最適化版を使いたい場合は rsshogi-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/rsshogi-py/pyproject.toml

AVX2 ビルド

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

python -m pip install rsshogi-avx2

注意

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

Policy Label

from rsshogi.core import Move
from rsshogi.policy import compact_move_label, move_label
from rsshogi.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 rsshogi.core import Board

board = Board()
board.apply_usi("7g7f")
print(board.to_sfen())

raw-state を Python から直接編集することもできます。

from rsshogi.core import Board
from rsshogi.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 rsshogi.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

rsshogi は用途別の submodule から import できます。

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

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

# 棋譜
from rsshogi.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 rsshogi.numpy import (
    PackedSfen,
    PackedSfenValue,
    HuffmanCodedPos,
    HuffmanCodedPosAndEval,
)

# Policy label
from rsshogi.policy import move_label, compact_move_label

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

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

ドキュメント

API リファレンスと、各棋譜形式の細かな互換挙動(コメントの扱い、終局行や消費時間の整形など)は mdBook ドキュメントにまとめています。

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

rsshogi-1.0.0.tar.gz (448.7 kB view details)

Uploaded Source

Built Distributions

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

rsshogi-1.0.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

rsshogi-1.0.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

rsshogi-1.0.0-cp314-cp314-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.14Windows x86-64

rsshogi-1.0.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

rsshogi-1.0.0-cp314-cp314-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

rsshogi-1.0.0-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

rsshogi-1.0.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

rsshogi-1.0.0-cp313-cp313-macosx_11_0_arm64.whl (988.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rsshogi-1.0.0-cp312-cp312-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.12Windows x86-64

rsshogi-1.0.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

rsshogi-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (987.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rsshogi-1.0.0-cp311-cp311-win_amd64.whl (994.5 kB view details)

Uploaded CPython 3.11Windows x86-64

rsshogi-1.0.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

rsshogi-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (993.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rsshogi-1.0.0-cp310-cp310-win_amd64.whl (994.5 kB view details)

Uploaded CPython 3.10Windows x86-64

rsshogi-1.0.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 rsshogi-1.0.0.tar.gz.

File metadata

  • Download URL: rsshogi-1.0.0.tar.gz
  • Upload date:
  • Size: 448.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rsshogi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aa39695016d50bb91b2f0092e0521d29923cef5e1edca488703d55a6a425de35
MD5 f97dc84c4e26079f55f71b8fbdd8ee62
BLAKE2b-256 7281e478a0e84ae817483f1372413401a97893d94df8e90ef2405d4481549fc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0.tar.gz:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0191ddd24551a4e01429458644973e727ae44c9396735deeb3659d1316c1ee84
MD5 481e1b09800bf317a2fb6785254cbd99
BLAKE2b-256 4d62a9c63e32062b9d5ddc2c5d0d76a4fa0da0a8f0e94e2414fc5a0cf98e76d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5b7b4304a17a309745c9fc6cf8f893e7332f840e2134e17c79c14adf6b85cc2
MD5 e527393c81a47987c50980f92bb8bd7e
BLAKE2b-256 f6aac2e293d351be4476249a1bd35d5de58bdf00bc3bd5f410cbab3b3b65105c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp314-cp314-win_amd64.whl.

File metadata

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

File hashes

Hashes for rsshogi-1.0.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 161514377e36b2f7f375c93da74cbded1fd142d50c160c1f1be4cea5c2373a2d
MD5 70fa1e55661068679b4ec2060f94a237
BLAKE2b-256 9177e8b98b3f0b0eaa03571135dfad78e17d5dfa6f669c17fa9440446c2b42e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp314-cp314-win_amd64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85de12bf2f34cda02fddc419755a5f05a43591cf1c331b5cd47fc2e12bca168d
MD5 f5fbe64cbf73cbd14741236ac24f9c40
BLAKE2b-256 900b9ee79a83fd19bd117560abea721f4d83fd18181ac7b9c3e409244d8ddfd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b968fdad36c0e887c8ce1167564eeaef190a33daf9f9fb198755173215a6f75b
MD5 9b681b2b478a3fb71d30e0643f59b355
BLAKE2b-256 64465a23bcf168ac34fff1668983e70126fbc3cfbe965ae2e6dd8d9536b2bd77

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

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

File hashes

Hashes for rsshogi-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6e14caec861b0cfb1d3db1d4d3bb1927acd2cd8890fff880d365e39654aaf2ec
MD5 6c66f3d1664bd19049c0b045cf4bbdf7
BLAKE2b-256 38e7e42395c683f120372109740bae12b9a434a90c1875d93291b475456510a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp313-cp313-win_amd64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02661a9effb90d8ccbdaaa507a13c08daeb48e7cbea6e933ead95e970286fb5b
MD5 48ae274cfa0bdc04f053b9b5d135b221
BLAKE2b-256 9229af9d1521e9612f9f27aea40795b9a82c735bc7b24911fb72583852a12375

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 379d97a2d1c90d777cf907f38efd125e9293aff84c21154e99002f1b4ce2d054
MD5 eb99c16164149e092e2b4860e4e2e93f
BLAKE2b-256 95a917d4ef02664b80456647758340c750e7d241d0318c7840865b513e098286

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

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

File hashes

Hashes for rsshogi-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 912a032209dd1efb94a64b06990532adb29556d849fa03b9baad29d21cc4b391
MD5 7a5e0be6f872cee6496f65298a69b8aa
BLAKE2b-256 79625bd7835bc7804502f02f785234cf6dd6269bfcedd3a7a98095e5b4caeaa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp312-cp312-win_amd64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0a8d0276566e1a2a0536aa8f49f4f188e9862dd31e87630d3750d4d1bafa2b7
MD5 6b4d6864b4bc0478e3c48476207e5bd2
BLAKE2b-256 80bc35fb29464655b0b68cac43fa2a0d33fd0316e21ce661cd54a9eedfeefd4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f80157acb359055f574ccb030516747b5c55c218e6dd6c50478defdda29adb02
MD5 d6609362b84100799234614705c67aa4
BLAKE2b-256 1aba9358b1c90b01da805937b32840549abfdca64e0fd7b72a015b612e779390

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rsshogi-1.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 994.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rsshogi-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9320011b50436ce79c910c6a5f92ed50d736d0803f094d299449b313229be61a
MD5 ea97a1a6f5f7fc95fa124ba2414d1449
BLAKE2b-256 31ff869cca272d8270625de47aa9a4a56c8059815554cb3000778083207ca578

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp311-cp311-win_amd64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a206aa358e33ca4306d2aa4c96c05d3855bf1bd97cc125dcbdce78c849e8fbe8
MD5 28cc0cca4ee56be56a324075711cf73c
BLAKE2b-256 b3ead688391b389bf7aa4d974a8fe8f183e28250f3e47d34f0b6387d456ec851

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb51c0fae19f1acda6b7b1bb635b142ecd75ff86dc2fc53519dfbf637e4b523f
MD5 91a44483cac6821ddc0d4c19467357ae
BLAKE2b-256 caae75b0534d6c1a32d96b28dc2ea8857496905127c21271d5b195aa64cc46a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: rsshogi-1.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 994.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rsshogi-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b7b00520984e88790ebf91185039c68cffa51d5fabf933e6d4fca2ef76c20f83
MD5 b7d1992ffdf4406182fe49b9cb93fc7f
BLAKE2b-256 dc716a14196da3b61ed59bc49da415638e3a1b03895b0f177cbcf21ab2f2b529

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp310-cp310-win_amd64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsshogi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsshogi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae4d01495663627539c80e59f347ce231c883011dcd5931b9ce9d9d124069e14
MD5 450afbdcd21b8bb4f9fdff81998f2e4e
BLAKE2b-256 bb09ed95a3807371f3dcf6c2c9218b27d97dbc7f1d437a7e11a07f9223e8915d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsshogi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-release.yml on nyoki-mtl/rsshogi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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