Metadata-Version: 2.4
Name: rshogi-py
Version: 0.7.4
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
License-File: LICENSE
Summary: Python bindings for the rshogi core library.
Author: rshogi contributors
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/nyoki-mtl/rshogi

# 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`](https://pypi.org/project/rshogi-py-avx2/).

## Development Install

```bash
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.

```bash
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

```python
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

```python
from rshogi.core import Board

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

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

```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` 文字列を直接扱うこともできます。

```python
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"
```

## Structured Imports

`rshogi` provides structured imports through submodules for better organization:

```python
# Types and constants
from rshogi.types import Color, PieceType, Square
from rshogi.core import Move, Move32

# 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

# Policy labels
from rshogi.policy import move_label, compact_move_label
```

Use submodules for all imports:

```python
from rshogi.core import Board
from rshogi.core import Move
from rshogi.record import GameRecord
```

