Source Code
Config
Config modules provide a way to manage game-specific configurations supporting unified management, caching mechanism and factory mode creation of multiple configuration types.
BaseConfig Base Class
BaseConfig Base ClassThe BaseConfig class is the foundation for all configuration classes. It provides the basic loading and caching functionality.
load_config(game_ver: str) -> Dict[str, Any]: Loads the configuration for the specified game version.
To ensure that the function gives the correct result, you need to follow the configuration file convention. It returns the dictionaries that contains the version information as follow example.
{
"th08": {
"ver": "th08",
"area": [
{
"id": "0",
"description": "Main Game Area",
"offset": [0, 0],
"size": [640, 480]
}
]
}
}It will return:
{
"ver": "th08",
"area": [
{
"id": "0",
"description": "Main Game Area",
"offset": [0, 0],
"size": [640, 480]
}
]
}ConfigFactory Class
ConfigFactory ClassThe ConfigFactory class is responsible for creating configuration instances based on the registered configuration names.
create(config_type: str) -> BaseConfig: Creates a configuration instance based on the provided configuration name.
Decorators
@config_loader(config_file: str): A decorator to specify the configuration file to load.@register_config(config_name: str): A decorator to register the configuration class with a specific name.
Gamebase
Define the base classes for game-specific implementations. These classes provide a common interface for different games, allowing the bot to interact with various Touhou STG games in a unified manner.
Constants
WIDTH: The minimal width of the official Touhou STG game window is always 640 pixels.HEIGHT: The minimal height of the official Touhou STG game window is always 480 pixels.
GameInfo Class
GameInfo ClassThe GameInfo class is used to store information about the game version and the window size.
game_ver: str
window_size: tuple[int, int]GameState Class
GameState ClassIt's a enumeration that defines the possible states of the game, including GAMING, GAME_OVER, BOMB, MENU, and UNKNOWN.
GamingInfo Class
GamingInfo ClassThe GamingInfo class is used to store information about the gaming information, such as the game stage, score, etc.
GameKey Class
GameKey ClassIt's a enumeration that defines the integer flags of the possible keys of the game as follow:
UP = 1
DOWN = 2
LEFT = 4
RIGHT = 8
Z = 16
X = 32
SHIFT = 64
C = 128 # Some special game uses C for additional actionsPerception
The perception module is responsible for game screen capture and detection functionality, providing a unified interface to handle different types of game state detection and object recognition.
Capture Class
Capture ClassThe Capture class is responsible for capturing screenshots of the game window, supporting screenshot capture at specified frame rates.
__init__(game_info: GameInfo, capture_rate: int = 30, game_config: Optional[GameInfoConfig] = None): Initialize the capturer, setting game information, capture frame rate, and configuration.capture_screen() -> Optional[np.ndarray]: Capture a screenshot of the game window, returning a numpy array in BGR format.
DetectionBase Abstract Base Class
DetectionBase Abstract Base ClassDetectionBase is the foundation for all detection classes, providing a common interface for detection functionality and configuration management.
Main Attributes
image: Current image data being processed.is_available: Status flag indicating whether the detector is available.game_info: Basic information about the game to be detected.
Abstract Methods
_set_available(game_state) -> None: Set the detector's availability based on the game state.detect(image: np.ndarray) -> None: Detect target objects in the image.get_results() -> dict: Get the detection results.
Helper Methods
get_detect_area(area_id: str) -> Optional[dict]: Get detection area configuration based on area ID._load_config_data(config_type: str) -> Dict[str, Any]: Load the corresponding configuration data. Theconfig_typeis the registered name by the decorator._set_image(image: np.ndarray) -> None: Set the image.
The detection module requires configuration files to define detection areas and parameters. Please ensure that the corresponding configuration files are properly configured.
Last updated
