Architectural refactor to eliminate circular imports and establish clean module boundaries: - Move enums from app/core/models/enums.py to app/core/enums.py (foundational module with zero dependencies) - Update all imports across 30 files to use new enum location - Set up clean export structure: - app.core.enums: canonical source for all enums - app.core: convenience exports for full public API - app.core.models: exports models only (not enums) - Add module exports to app/core/__init__.py and app/core/effects/__init__.py - Remove circular import workarounds from game_state.py This enables app.core.models to export GameState without circular import issues, since enums no longer depend on the models package. All 826 tests passing.
155 lines
3.6 KiB
Python
155 lines
3.6 KiB
Python
"""Mantimon TCG - Core Game Engine.
|
|
|
|
This module contains the core game engine for Mantimon TCG, a highly configurable
|
|
Pokemon TCG-inspired card game. The engine supports both campaign mode with fixed
|
|
rules and free play mode with user-configurable rules.
|
|
|
|
Key Components:
|
|
- config: RulesConfig and sub-configs for all game rules
|
|
- models: Data models for cards, game state, and actions
|
|
- effects: Effect handler system for card abilities and attacks
|
|
- engine: Main GameEngine orchestrator
|
|
- turn_manager: Turn/phase state machine
|
|
- rules_validator: Action legality checking
|
|
- win_conditions: Win/loss detection
|
|
- visibility: Hidden information filtering for clients
|
|
- rng: Random number generation with testable seeded implementation
|
|
|
|
Quick Start:
|
|
from app.core import GameEngine, RulesConfig, create_rng
|
|
|
|
# Create engine with rules and RNG
|
|
engine = GameEngine(rules=RulesConfig(), rng=create_rng())
|
|
|
|
# Create a game
|
|
game = engine.create_game(
|
|
player_ids=["player1", "player2"],
|
|
decks={"player1": deck1, "player2": deck2},
|
|
card_registry=registry,
|
|
)
|
|
|
|
# Execute actions
|
|
result = await engine.execute_action(game, "player1", action)
|
|
|
|
# Get client-safe view
|
|
visible = engine.get_visible_state(game, "player1")
|
|
"""
|
|
|
|
# Enums (foundational, no dependencies)
|
|
# Configuration
|
|
from app.core.config import (
|
|
ActiveConfig,
|
|
BenchConfig,
|
|
CombatConfig,
|
|
DeckConfig,
|
|
EnergyConfig,
|
|
EvolutionConfig,
|
|
FirstTurnConfig,
|
|
PrizeConfig,
|
|
RetreatConfig,
|
|
RulesConfig,
|
|
StatusConfig,
|
|
TrainerConfig,
|
|
WinConditionsConfig,
|
|
)
|
|
|
|
# Engine
|
|
from app.core.engine import ActionResult, GameEngine
|
|
from app.core.enums import (
|
|
ActionType,
|
|
CardType,
|
|
EnergyType,
|
|
GameEndReason,
|
|
ModifierMode,
|
|
PokemonStage,
|
|
PokemonVariant,
|
|
StatusCondition,
|
|
TrainerType,
|
|
TurnPhase,
|
|
)
|
|
|
|
# Game state models (imported after config to avoid circular imports)
|
|
from app.core.models.game_state import (
|
|
ForcedAction,
|
|
GameState,
|
|
PlayerState,
|
|
Zone,
|
|
)
|
|
|
|
# RNG
|
|
from app.core.rng import RandomProvider, SecureRandom, SeededRandom, create_rng
|
|
|
|
# Validation
|
|
from app.core.rules_validator import ValidationResult, validate_action
|
|
|
|
# Turn management
|
|
from app.core.turn_manager import TurnManager, TurnStartResult
|
|
|
|
# Visibility (for service layer)
|
|
from app.core.visibility import (
|
|
VisibleGameState,
|
|
VisiblePlayerState,
|
|
VisibleZone,
|
|
get_spectator_state,
|
|
get_visible_state,
|
|
)
|
|
|
|
# Win conditions
|
|
from app.core.win_conditions import WinResult, check_win_conditions
|
|
|
|
__all__ = [
|
|
# Enums
|
|
"ActionType",
|
|
"CardType",
|
|
"EnergyType",
|
|
"GameEndReason",
|
|
"ModifierMode",
|
|
"PokemonStage",
|
|
"PokemonVariant",
|
|
"StatusCondition",
|
|
"TrainerType",
|
|
"TurnPhase",
|
|
# Configuration
|
|
"RulesConfig",
|
|
"DeckConfig",
|
|
"ActiveConfig",
|
|
"BenchConfig",
|
|
"EnergyConfig",
|
|
"PrizeConfig",
|
|
"FirstTurnConfig",
|
|
"WinConditionsConfig",
|
|
"StatusConfig",
|
|
"TrainerConfig",
|
|
"EvolutionConfig",
|
|
"RetreatConfig",
|
|
"CombatConfig",
|
|
# RNG
|
|
"RandomProvider",
|
|
"SeededRandom",
|
|
"SecureRandom",
|
|
"create_rng",
|
|
# Engine
|
|
"GameEngine",
|
|
"ActionResult",
|
|
# Validation
|
|
"ValidationResult",
|
|
"validate_action",
|
|
# Win conditions
|
|
"WinResult",
|
|
"check_win_conditions",
|
|
# Turn management
|
|
"TurnManager",
|
|
"TurnStartResult",
|
|
# Visibility
|
|
"VisibleGameState",
|
|
"VisiblePlayerState",
|
|
"VisibleZone",
|
|
"get_visible_state",
|
|
"get_spectator_state",
|
|
# Game state models
|
|
"ForcedAction",
|
|
"GameState",
|
|
"PlayerState",
|
|
"Zone",
|
|
]
|