Skip to content

Normboy1/Nation-Sim

Repository files navigation

๐ŸŒ Nation-Sim: AI-Powered Geopolitical Simulation

A sophisticated, max-realism seven-nation simulator featuring AI-driven governance, real-time decision-making, and comprehensive economic, social, and political modeling.

Python 3.10+ License: MIT

โœจ Features

๐Ÿค– AI-Powered Nations

  • 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

๐Ÿ“Š Comprehensive Simulation

  • 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

๐Ÿ–ฅ๏ธ Multiple Interfaces

  • 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

โšก Real-Time Operation

  • 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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10 or higher
  • pip package manager

Installation

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.txt

Running the Simulation

๐Ÿ–ฅ๏ธ Desktop GUI (Recommended)

python run_gui.py
  • Native desktop application
  • Real-time charts and data
  • Full simulation control
  • No web server required

๐ŸŒ Web Dashboard

python webapp/app.py

Then open http://localhost:5001 in your browser

๐Ÿ’ป Command Line

python run_loop.py          # Basic simulation loop
python run_persistent.py    # Persistent real-time simulation
python run_ai_loop.py       # AI-focused simulation

๐Ÿ“ Project Structure

nation-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

๐ŸŽฎ Usage Examples

Start a Real-Time Simulation

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")

Access Nation Data

# 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")

AI Decision Monitoring

# 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']}")

๐Ÿ”ง Configuration

Nation Customization

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

Simulation Parameters

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

๐Ÿ“Š Visualization

Built-in Charts

  • Economic indicators: GDP, unemployment, inflation trends
  • Social metrics: Legitimacy, unrest, rights scores
  • International relations: Alliance networks, trade flows
  • Policy impacts: Decision effectiveness over time

Export Options

  • PNG/SVG chart exports
  • CSV data dumps
  • JSON state snapshots
  • Real-time data streaming

๐Ÿค– AI System

Decision-Making Architecture

  • 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

Supported AI Models

  • Local LLM integration: Ollama, GPT4All compatibility
  • Cloud APIs: OpenAI GPT, Anthropic Claude support
  • Hybrid approaches: LLM reasoning + RL optimization

๐Ÿ› ๏ธ Development

Running Tests

python -m pytest tests/

Code Style

pip install black flake8
black .
flake8 .

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

๐Ÿ“ˆ Performance

Benchmarks

  • 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

Scaling

  • Supports up to 20 nations with linear performance degradation
  • Configurable simulation complexity for performance tuning
  • Distributed processing support for large-scale scenarios

๐Ÿ” Troubleshooting

Common Issues

Import errors with pydantic/typing_extensions

pip install --upgrade typing_extensions pydantic

GUI 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

๐Ÿ“š Documentation

  • API Reference: See docs/api.md
  • Architecture Guide: See docs/architecture.md
  • Tutorial: See docs/tutorial.md
  • Examples: See examples/ directory

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Areas for Contribution

  • New simulation modules (climate, technology, culture)
  • AI agent improvements and new strategies
  • Visualization enhancements
  • Performance optimizations
  • Documentation and examples

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by real-world geopolitical modeling systems
  • Built with modern Python ecosystem tools
  • Community feedback and contributions welcomed

๐Ÿ“ž Support


Nation-Sim - Bringing AI-powered geopolitical simulation to everyone ๐ŸŒ

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors