API Reference

This is the complete API reference for rustshogi.

Module Overview

rustshogi consists of the following main classes and enumerations:

  • rustshogi package - Main module (basic functions for shogi board, moves, pieces, etc.)

Basic Types

class rustshogi.Address

A class that represents coordinates on the shogi board. It includes column and row information.

class rustshogi.ColorType

An enumeration that represents the players. It has values for Black (Sente) and White (Gote).

class rustshogi.PieceType

An enumeration that represents the types of shogi pieces. It includes King, Gold, Rook, Bishop, Silver, Knight, Lance, Pawn, and their promoted versions.

class rustshogi.Piece

A class that represents a shogi piece. It includes information about the piece type (PieceType) and its color (ColorType).

class rustshogi.Move

A class that represents a shogi move. It includes information such as the source, destination, piece type, and promotion status.

class rustshogi.Hand

A class that represents the pieces in a player’s hand.

class rustshogi.Board

A class that represents the shogi board. It provides functions for managing the position, generating legal moves, and executing moves.

class rustshogi.Game

A class that manages the overall game. It handles game progression, win/loss determination, and random games.

Evaluation Functions

rustshogi provides multiple evaluation functions to evaluate positions.

class rustshogi.SimpleEvaluator

A simple evaluator. It evaluates the position using only the value of the pieces.

evaluate(board: Board, color: ColorType) float

Evaluates the board.

Parameters:
  • board – The board to evaluate

  • color – The color of the player to evaluate for (Black or White)

Returns:

The evaluation score (from the perspective of color, higher is better)

class rustshogi.NeuralEvaluator

A neural network evaluator. It uses a machine learning model to predict the win rate of a position and calculate an evaluation score.

__init__(db_type_str: str | None = None, connection_string: str | None = None, model_path: str | None = None)

Initializes the evaluator.

Parameters:
  • db_type_str – Database type (“sqlite” or “postgres”)

  • connection_string – Database connection string

  • model_path – Path to the model file

init_database() None

Initializes the database tables.

evaluate(board: Board, color: ColorType) float

Evaluates the board.

Parameters:
  • board – The board to evaluate

  • color – The color of the player to evaluate for

Returns:

The evaluation score

evaluate_position(board: Board, model_path: str | None = None) Tuple[float, float, float]

Predicts the win rate for a specific position.

Parameters:
  • board – The board to evaluate

  • model_path – Path to the model file (optional)

Returns:

A tuple of (white win rate, black win rate, draw rate)

generate_and_save_random_boards(count: int) int

Generates random boards and saves them to the database.

Parameters:

count – The number of boards to generate

Returns:

The number of boards saved