A comprehensive forest fire simulation system with agent-based modeling, real-time visualization, and modular architecture.
- Grid-based Simulation: Minecraft-style grid cell representation for terrain and fire
- Agent System: Helicopter and ground crew agents with intelligent movement
- Real-time Visualization: Live GUI with step-by-step simulation display
- Ultra-Modular Architecture: 60% code reduction through expert modularization
- Fixed UI Layout: Consistent user interface that doesn't change unexpectedly
- Raster Data Support: Import and visualize real geographic data
Major Modularization Completed! โจ
| Component | Before | After | Reduction | New Modules |
|---|---|---|---|---|
| GUI Main | 774 lines | 275 lines | 64% | 4 modules |
| Simulation Controller | 628 lines | 197 lines | 69% | 3 modules |
| Scenario Input GUI | 578 lines | 167 lines | 71% | 5 modules |
| Cell Manager | 439 lines | 330 lines | 25% | 3 modules |
| Total | 2,419 lines | 969 lines | 60% | 15 modules |
Benefits Achieved:
- ๐ง Maintainability: Each module has single responsibility
- ๐ Readability: All files under 500 lines, most under 300
- ๐งช Testability: Individual modules can be tested independently
- ๐ Reusability: Components can be used in other projects
- ๐ฅ Collaboration: Multiple developers can work simultaneously
ForFiS/
โโโ agents/ # Agent behavior and movement logic
โ โโโ base/ # Base agent classes
โ โโโ types/ # Agent type definitions
โ โโโ movement/ # Movement algorithms
โ โโโ pathfinding/ # Pathfinding systems
โโโ core/ # Core simulation engine
โ โโโ cells/ # Cell system (highly modular)
โ โ โโโ cell_manager.py # Main cell manager (330 lines)
โ โ โโโ cell_factory.py # Cell creation (262 lines)
โ โ โโโ cell_updater.py # State updates (291 lines)
โ โ โโโ cell_validator.py # Data validation (298 lines)
โ โโโ simulation/ # Simulation components
โ โโโ forest/ # Forest and terrain models
โ โโโ fire/ # Fire spread algorithms
โโโ gui/ # User interface (modularized)
โ โโโ core/ # Core GUI components
โ โ โโโ main_window.py # Window management (94 lines)
โ โ โโโ state_manager.py # State management (139 lines)
โ โ โโโ event_handler.py # Event handling (339 lines)
โ โ โโโ logger.py # Logging system (130 lines)
โ โโโ gui_main.py # Main GUI coordinator (275 lines)
โ โโโ simulation/ # Simulation control
โ โ โโโ controller.py # Main controller (197 lines)
โ โ โโโ execution_controller.py # Execution control (214 lines)
โ โ โโโ data_manager.py # Data management (244 lines)
โ โ โโโ step_controller.py # Step control (217 lines)
โ โโโ visualization/ # Plotting and visualization
โ โโโ controls/ # User controls
โ โโโ animation/ # Animation and step management
โโโ scenario/ # Scenario input system (ultra-modular)
โ โโโ gui/ # GUI components
โ โ โโโ input_window.py # Window management (140 lines)
โ โ โโโ map_controller.py # Map interaction (298 lines)
โ โ โโโ form_controller.py # Form controls (304 lines)
โ โโโ logic/ # Logic components
โ โ โโโ scenario_validator.py # Validation (255 lines)
โ โ โโโ scenario_data_manager.py # Data management (291 lines)
โ โ โโโ scenario_event_handler.py # Event handling (470 lines)
โ โโโ scenario_input_gui.py # Main coordinator (167 lines)
โโโ config/ # Configuration files
โโโ docs/ # Project documentation
โ โโโ PROJECT_ARCHITECTURE.md # Architecture overview
โ โโโ CURSOR_RULES.md # Development guidelines
โ โโโ REFACTORING_GUIDE.md # Code refactoring guide
โ โโโ REFACTORING_RESULTS.md # Latest refactoring results
โโโ tests/ # Test suite
- GUI Layer: User interface and interaction
- Visualization Layer: Plotting and rendering
- Simulation Layer: Core simulation logic
- Agent Layer: Agent behavior and movement
- Core/Model Layer: Data models and algorithms
- Single Responsibility: Each module has one clear purpose
- Dependency Management: Clear interfaces between layers
- Code Reuse: Common functionality in utility modules
- DRY Principle: Don't Repeat Yourself
- Common Interfaces: Unified APIs for similar functionality
- Shared Utilities: Centralized common functions
pip install -r requirements.txtfrom gui.gui_main import GUIMain
# Create configuration
config = {
"mode": "Haksar",
"grid": "rectangular",
"size": 42,
"agent_config": {"helicopter": 1, "groundcrew": 2}
}
# Start GUI
gui = GUIMain(config)- Start: Click "Start" to begin simulation
- Step: Use "Step" for manual progression
- Pause/Resume: Control simulation flow
- Reset: Restart simulation from beginning
The UI layout is controlled by config/ui_fixed_config.yml:
ui:
fixed_layout: true
grid_spec:
width_ratios: [0.6, 0.2, 0.2] # [main_map, fire_cbar, terrain_cbar]
colorbar:
terrain:
levels: 7 # Matches raster data levels
fire:
levels: 5 # Fire intensity levelsagent_config:
helicopter: 1 # Number of helicopter agents
groundcrew: 2 # Number of ground crew agents
movement_speed: 1.0
pathfinding_enabled: true- Terrain: 7 distinct levels with custom colormap
- Fire: 5 intensity levels with hot colormap
- Forest State: 3 states (Healthy, Burning, Burnt)
- Grid Lines: Clear cell boundaries for easy identification
- English Labels: Intuitive descriptions for each color
- Terrain Types: Water, Dense Forest, Forest, Light Forest, Grassland, Rocky, Bare Soil
- Fire Intensity: No Fire, Low, Medium, High, Extreme
- Forest States: Healthy, Burning, Burnt
- Helicopters: Red circles with numbers
- Ground Crew: Blue squares with numbers
- Movement: Real-time position updates
- Status: Visual indicators for agent states
# Run all tests
python -m pytest tests/
# Run specific test categories
python -m pytest tests/unit/
python -m pytest tests/integration/
python -m pytest tests/system/- Unit Tests: Individual module functionality
- Integration Tests: Module interaction testing
- System Tests: End-to-end functionality
- PROJECT_ARCHITECTURE.md: Detailed architecture overview
- CURSOR_RULES.md: Development guidelines and rules
- REFACTORING_GUIDE.md: Code refactoring instructions
- Agent System: Agent behavior and movement APIs
- Simulation Engine: Core simulation interfaces
- GUI Components: User interface APIs
- Visualization: Plotting and rendering APIs
- Review existing code for similar functionality
- Choose appropriate layer for the feature
- Define interfaces for module communication
- Implement and document the feature
- Write tests for the new functionality
- Identify duplicate code across modules
- Extract common functionality to utility modules
- Update interfaces for consistency
- Run tests to ensure functionality
- Update documentation to reflect changes
- PEP 8 compliance for Python code style
- Type hints where appropriate
- Comprehensive docstrings for all public APIs
- Test coverage for critical functionality
- Code duplication across modules
- Layer violations (lower layers depending on higher layers)
- GUI logic in core modules
- Hardcoded values in code
- Use configuration files for settings
- Implement proper error handling
- Write comprehensive tests
- Maintain clear documentation
- Read the documentation thoroughly
- Understand the architecture and layer structure
- Follow the coding guidelines in CURSOR_RULES.md
- Check for existing implementations to avoid duplication
- Create feature branch from main
- Implement changes following project rules
- Write/update tests for new functionality
- Update documentation as needed
- Submit pull request with detailed description
- Efficient algorithms for pathfinding and movement
- Memory management for large datasets
- Caching of frequently computed results
- Parallel processing where applicable
- Memory usage during simulation
- Computation time for each step
- GUI responsiveness during updates
- Scalability with different grid sizes
- 3D Visualization: Enhanced terrain representation
- Weather Integration: Real-time weather effects
- Multi-agent Cooperation: Coordinated firefighting strategies
- Machine Learning: Adaptive agent behavior
- Plugin System: Extensible functionality
- API Standardization: RESTful interfaces
- Cloud Integration: Distributed simulation
- Real-time Data: Live sensor integration
This project is licensed under the MIT License - see the LICENSE file for details.
- Research Team: Forest fire modeling algorithms
- Open Source Community: Libraries and tools
- Contributors: Code improvements and bug fixes
Note: This project follows strict architectural principles to maintain code quality and consistency. Please refer to the documentation before making any changes.