How xrubin/mordheim-gpt works
Project Type and Purpose
• This is a PHP-based domain simulation library for the tabletop game Mordheim (“Mordheim Classic simulator”).
• It contains pure business logic (battle rules, fighters, warbands, strategies) and no UI or web frontend.
File-Structure Analysis
• Top-level:
• src/ contains all PHP code, organized by sub-packages:
– Data/Attributes and other Data/ classes (data models, attribute definitions)
– Rule/ (battle rules engine)
– Strategy/ (Strategy pattern implementations for battle AI)
– Traits/, Exceptions/, Interfaces, Domain entities (e.g. Fighter, Warband, Battle)
• examples/ – CLI usage examples (attribute.php, battle.php)
• tests/ – PHPUnit tests validating each domain class and rule
• composer.json – dependency and autoload configuration
Key Architectural Patterns
• Domain-Driven Design: Entities (Fighter, Warband, Battle), Value Objects (Characteristics, Spell), Services (EquipmentManager, PathFinder)
• Strategy Pattern (BattleStrategyInterface → AggressiveStrategy, CarefulStrategy, CowardlyStrategy)
• Rule Engine (each rule implements a common interface under src/Rule)
• Data Providers / Repositories under src/Data
• Use of Interfaces to decouple implementations (e.g. FighterInterface, EquipmentInterface)
Main Components
A. Domain Layer
• Entities: Fighter, Warband, Battle, GameField, FieldCell
• Value Objects: Characteristics, Spell, SpecialRule
B. Data Layer
• Data providers / attribute definitions (src/Data/Attributes/*)
• EquipmentList, Mutation, SkillGroup
C. Battle Engine Services
• Rule Engine (src/Rule/*)
• PathFinder (movement logic)
• EquipmentManager (inventory logic)
• BattleLogger (logging events)
D. Strategy Module
• BattleStrategyInterface + implementations (AggressiveStrategy, etc.)
E. Infrastructure
• Composer Autoload
• PHPUnit Tests (external to runtime, verifies correctness)
• Examples (entry points for CLI simulation)
Relationships and Interactions
• Battle orchestrates the simulation:
→ loads Domain Entities (Warband, Fighter) using Data providers
→ uses PathFinder to calculate moves on GameField
→ applies each Rule in the Rule Engine to update FighterState
→ delegates AI decisions to a Strategy implementation
→ emits events to BattleLogger
• EquipmentManager is used by Fighters when modifying equipment.
• Data Attributes repository is read by Domain Entities to initialize stats.