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.
- 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
Search¶
rustshogi provides a search engine and search algorithms to find the best move.
- class rustshogi.SearchEngine¶
The search engine. It combines a search algorithm and an evaluation function to find the best move.
- __init__(algorithm: str = 'minmax', max_nodes: int = 1000000, evaluator: Evaluator | None = None)¶
Initializes the search engine.
- Parameters:
algorithm – Search algorithm (“minmax” or “alphabeta”)
max_nodes – Maximum number of nodes to search
evaluator – Evaluator (optional, defaults to SimpleEvaluator)
- search(board: Board, color: ColorType, depth: int) EvaluationResult¶
Executes a search to find the best move.
- Parameters:
board – The current board
color – The color of the player to move
depth – The search depth
- Returns:
The evaluation result (includes score, best move, and number of nodes searched)
- class rustshogi.EvaluationResult¶
A class representing the search result.
- score¶
The evaluation score (float)
- best_move¶
The best move (Optional[Move])
- nodes_searched¶
The number of nodes searched (int)
- class rustshogi.MinMaxSearchStrategy¶
The Minimax search algorithm. It explores all possible moves to select the optimal one.
- __init__(max_nodes: int = 100)¶
Initializes the Minimax search strategy.
- Parameters:
max_nodes – Maximum number of nodes to search
- class rustshogi.AlphaBetaSearchStrategy¶
The Alpha-Beta search algorithm. It is an optimized version of Minimax that prunes branches of the search tree that are not worth exploring.
- __init__(max_nodes: int = 100)¶
Initializes the Alpha-Beta search strategy.
- Parameters:
max_nodes – Maximum number of nodes to search