A sophisticated, max-realism seven-nation simulator featuring AI-driven governance, real-time decision-making, and comprehensive economic, social, and political modeling.
- 7 unique nations with distinct AI leaders and decision-making styles
- LLM-enhanced reasoning for realistic policy decisions
- Reinforcement learning integration for adaptive governance
- Real-time AI decision logging with full rationale
- Economic modeling: GDP, unemployment, inflation, trade, debt
- Social dynamics: Legitimacy, unrest, rights, press freedom
- Infrastructure: Grid health, technology, healthcare, education
- International relations: Diplomacy, alliances, conflicts
- Environmental factors: Climate, resources, sustainability
- Desktop GUI: Native tkinter application with matplotlib charts
- Web Dashboard: Real-time browser-based interface with D3.js visualizations
- Command Line: Batch processing and automation tools
- Live simulation: 1 real day = 1 simulated year (52 weeks)
- WebSocket updates: Real-time data streaming
- Persistent state: Save/load simulation progress
- Background processing: Non-blocking simulation execution
- Python 3.10 or higher
- pip package manager
git clone https://github.com/yourusername/nation-sim.git
cd nation-sim
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txtpython run_gui.py- Native desktop application
- Real-time charts and data
- Full simulation control
- No web server required
python webapp/app.pyThen open http://localhost:5001 in your browser
python run_loop.py # Basic simulation loop
python run_persistent.py # Persistent real-time simulation
python run_ai_loop.py # AI-focused simulationnation-sim/
โโโ ๐ docs/ # General documentation
โโโ ๐งฎ mathematics/ # Mathematical models and algorithms
โ โโโ algorithms/ # RL agents and training algorithms
โ โ โโโ rl_agents.py # Deep Q-Network implementations
โ โ โโโ rl_integration.py # RL integration with simulation
โ โ โโโ train_rl_agents.py # RL training procedures
โ โโโ models/ # AI agent models and reasoning
โ โ โโโ ai_agents.py # AI decision-making systems
โ โ โโโ llm_reasoning.py # LLM-enhanced reasoning
โ โโโ documentation/ # Mathematical frameworks
โ โ โโโ mathematical_framework.md
โ โ โโโ policy_mathematics.md
โ โ โโโ reinforcement_learning_algorithms.md
โ โ โโโ simulation_dynamics.md
โ โโโ README.md # Mathematics package documentation
โโโ ๐ง nationsim/ # Core simulation engine
โ โโโ world.py # Main world simulation
โ โโโ nation.py # Nation state management
โ โโโ ai_agent.py # AI decision-making
โ โโโ modules/ # Specialized simulation modules
โ โโโ ...
โโโ ๐ฅ๏ธ gui_app.py # Desktop GUI application
โโโ ๐ webapp/ # Web interface
โ โโโ app.py # Flask web server
โ โโโ templates/ # HTML templates
โ โโโ static/ # CSS, JS, images
โโโ ๐ visualize_nations.py # Data visualization tools
โโโ ๐ค train_rl_agents.py # Reinforcement learning training
โโโ ๐ requirements.txt # Python dependencies
from nationsim.world import World
# Initialize world
world = World("data/nations.yaml", "data/relations.yaml")
# Run simulation steps
for week in range(52): # One year
world.step(1)
print(f"Week {week}: {len(world.state.nations)} nations active")# Get nation statistics
for nation_id, nation in world.state.nations.items():
print(f"{nation.name}: GDP=${nation.gdp/1e12:.1f}T, Pop={nation.population/1e6:.1f}M")# View recent AI decisions
from nationsim.decision_journal import get_recent_decisions
decisions = get_recent_decisions(limit=10)
for decision in decisions:
print(f"{decision['nation_id']}: {decision['action']} - {decision['rationale']}")Edit data/nations.yaml to modify:
- Initial population, GDP, and economic indicators
- Political systems and governance styles
- Geographic and resource characteristics
- AI personality traits and decision preferences
Modify simulation constants in nationsim/world.py:
- Time scaling (real-time to simulation-time ratio)
- Economic growth rates and volatility
- Political stability factors
- International relationship dynamics
- Economic indicators: GDP, unemployment, inflation trends
- Social metrics: Legitimacy, unrest, rights scores
- International relations: Alliance networks, trade flows
- Policy impacts: Decision effectiveness over time
- PNG/SVG chart exports
- CSV data dumps
- JSON state snapshots
- Real-time data streaming
- Policy evaluation: Multi-criteria analysis of available actions
- Risk assessment: Probabilistic outcome modeling
- Learning adaptation: RL-based strategy refinement
- Reasoning transparency: Full decision rationale logging
- Local LLM integration: Ollama, GPT4All compatibility
- Cloud APIs: OpenAI GPT, Anthropic Claude support
- Hybrid approaches: LLM reasoning + RL optimization
python -m pytest tests/pip install black flake8
black .
flake8 .- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
- Simulation speed: ~100 weeks/second (7 nations)
- Memory usage: ~50MB base + ~10MB per saved state
- Web interface: <100ms response time for data queries
- GUI refresh rate: 60fps chart updates
- Supports up to 20 nations with linear performance degradation
- Configurable simulation complexity for performance tuning
- Distributed processing support for large-scale scenarios
Import errors with pydantic/typing_extensions
pip install --upgrade typing_extensions pydanticGUI not starting
# Ensure tkinter is available
python -c "import tkinter; print('โ
tkinter available')"Web dashboard not loading
pip install flask-socketio
python webapp/app.py- API Reference: See
docs/api.md - Architecture Guide: See
docs/architecture.md - Tutorial: See
docs/tutorial.md - Examples: See
examples/directory
We welcome contributions! Please see our Contributing Guide for details.
- New simulation modules (climate, technology, culture)
- AI agent improvements and new strategies
- Visualization enhancements
- Performance optimizations
- Documentation and examples
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by real-world geopolitical modeling systems
- Built with modern Python ecosystem tools
- Community feedback and contributions welcomed
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: your.email@example.com
Nation-Sim - Bringing AI-powered geopolitical simulation to everyone ๐