Skip to content

Suhaas15/VillageSimulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

25 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒณ The Village Simulation

An autonomous AI-driven village simulation with dynamic grid-based world generation, resource management, intelligent Oracle and Builder agents, and evolving gameplay.

Grid System AI Agents Python React Flask


โœจ Features

๐Ÿ—บ๏ธ World System

  • 40x40 Dynamic Grid with viewport-based rendering for optimal performance
  • Multiple Tile Types: Grass, Dirt, Forest, and Water biomes
  • Random Tree Generation (1,000+ trees with 3 species: Oak, Pine, Birch)
  • Interactive Resource Gathering - click trees to harvest wood
  • Pan & Zoom Navigation for exploring the expansive world
  • AI-Generated Tiles via Freepik API integration

๐Ÿค– AI Agent System

  • Oracle Agent: Governing AI that analyzes environment and makes strategic decisions
  • Builder Agent: Autonomous villager that gathers resources and builds structures
  • Oracle-Builder Orchestration: Coordinated AI workflow where Oracle guides Builder actions
  • Environment Analysis: Oracle evaluates world state and provides contextual guidance
  • Personality-Driven Behavior: Each agent has unique characteristics and decision-making patterns

๐Ÿ“Š Resource Management

  • Wood: Harvested from trees (5-15 units per tree)
  • Stone: Mining resources (planned)
  • Food: Gathering system (planned)
  • Real-time tracking with visual resource panel

๐ŸŽฎ Gameplay

  • Interactive World: Click and drag to pan, click resources to gather
  • Agent Spawning: Spawn Oracle and Builder agents that interact autonomously
  • Activity Logging: Real-time feed of all agent actions and decisions
  • Dynamic State Management: Persistent village state across sessions

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.9+
  • Node.js 16+
  • npm or yarn

Installation

Option 1: One-Command Start (Recommended)

# Clone the repository
git clone https://github.com/Suhaas15/VillageSimulation.git
cd VillageSimulation

# Run the launcher
./start.sh

Open http://localhost:3000 in your browser! ๐ŸŽ‰

Option 2: Manual Start

Terminal 1 - Backend:

cd backend
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python app.py

Terminal 2 - Frontend:

cd frontend
npm install
npm run dev

๐Ÿ“– Usage

Basic Controls

Action How To
Pan camera Click and drag anywhere on the grid
Cut tree Click on any tree to harvest wood
Spawn Oracle Click "Spawn Oracle" button
Spawn Builder Click "Spawn Builder" button
Reset view Click "Reset View" button
Refresh grid Click "Refresh Grid" button

AI Agent Workflow

  1. Spawn Oracle: Creates the governing AI that analyzes the environment
  2. Oracle Analysis: Oracle evaluates resources, terrain, and strategic opportunities
  3. Spawn Builder: Creates a worker agent to execute tasks
  4. Builder Actions: Builder autonomously gathers resources and builds based on Oracle guidance
  5. Watch Activity Log: Real-time feed shows all agent decisions and actions

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     ๐ŸŒ Browser (React)                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  VillageGrid  โ”‚  ResourcePanel  โ”‚  ActivityLog       โ”‚  โ”‚
โ”‚  โ”‚     Tile      โ”‚      Oracle     โ”‚     Builder        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ HTTP/REST API
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 ๐Ÿ Flask Backend (Python)                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  app.py  โ”‚  grid_manager.py  โ”‚  village_state.py   โ”‚   โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค   โ”‚
โ”‚  โ”‚  oracle_agent.py  โ”‚  builder_agent.py               โ”‚   โ”‚
โ”‚  โ”‚  oracle_environment_analyzer.py                      โ”‚   โ”‚
โ”‚  โ”‚  builder_oracle_orchestrator.py                      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Components

  • app.py: Flask API server with CORS-enabled endpoints
  • grid_manager.py: 40x40 grid state management and tree generation
  • village_state.py: Persistent village state and resource tracking
  • oracle_agent.py: Oracle AI agent implementation
  • builder_agent.py: Builder AI agent with autonomous behaviors
  • oracle_environment_analyzer.py: Environment analysis for Oracle decision-making
  • builder_oracle_orchestrator.py: Coordination layer between Oracle and Builder
  • village_actions.py: Action system for agent behaviors
  • freepik_api.py: AI tile generation integration

๐Ÿ”Œ API Endpoints

Grid & World

Endpoint Method Description
/api/health GET Health check
/api/grid GET Get complete grid state (1,600 tiles)
/api/grid/viewport GET Get viewport slice for optimization
/api/grid/initialize POST Initialize grid with AI-generated tiles
/api/grid/reset POST Reset grid to initial state

Resources

Endpoint Method Description
/api/resources GET Get current resource counts
/api/tree/cut POST Cut down a tree and gain wood

AI Agents

Endpoint Method Description
/api/oracle/spawn POST Spawn Oracle agent
/api/oracle/analyze POST Trigger Oracle environment analysis
/api/builder/spawn POST Spawn Builder agent
/api/builder/act POST Execute Builder action
/api/village/state GET Get complete village state

๐ŸŽจ Customization

Change Grid Size

# backend/grid_manager.py
def __init__(self, grid_size: int = 40):  # Change to 50, 60, etc.

Change Tile Size

// frontend/src/components/VillageGrid.jsx
const TILE_SIZE = 64 // Change to 32, 48, 128, etc.

Change Tree Density

# backend/grid_manager.py - in _generate_trees_for_tile()
num_trees = random.randint(1, 3)  # More trees per tile

Add Custom Tile Images

  1. Get a Freepik API key from Freepik Developer Portal
  2. Create .env file in backend/ directory:
FREEPIK_API_KEY=your_api_key_here
  1. Call the initialization endpoint:
curl -X POST http://localhost:5001/api/grid/initialize

๐Ÿ“ Project Structure

VillageSimulation/
โ”œโ”€โ”€ backend/                          # Python Flask API
โ”‚   โ”œโ”€โ”€ app.py                       # Main Flask server
โ”‚   โ”œโ”€โ”€ grid_manager.py              # Grid state management
โ”‚   โ”œโ”€โ”€ village_state.py             # Village persistence
โ”‚   โ”œโ”€โ”€ oracle_agent.py              # Oracle AI agent
โ”‚   โ”œโ”€โ”€ builder_agent.py             # Builder AI agent
โ”‚   โ”œโ”€โ”€ oracle_environment_analyzer.py  # Environment analysis
โ”‚   โ”œโ”€โ”€ builder_oracle_orchestrator.py  # Agent orchestration
โ”‚   โ”œโ”€โ”€ village_actions.py           # Action system
โ”‚   โ”œโ”€โ”€ freepik_api.py               # AI tile generation
โ”‚   โ””โ”€โ”€ requirements.txt             # Python dependencies
โ”‚
โ”œโ”€โ”€ frontend/                         # React Frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx                  # Main app component
โ”‚   โ”‚   โ””โ”€โ”€ components/
โ”‚   โ”‚       โ”œโ”€โ”€ VillageGrid.jsx      # Grid renderer with viewport optimization
โ”‚   โ”‚       โ”œโ”€โ”€ Tile.jsx             # Individual tile component
โ”‚   โ”‚       โ”œโ”€โ”€ Tree.jsx             # Tree overlay with click handling
โ”‚   โ”‚       โ”œโ”€โ”€ ResourcePanel.jsx    # Resource counter UI
โ”‚   โ”‚       โ”œโ”€โ”€ ActivityLog.jsx      # Agent activity feed
โ”‚   โ”‚       โ”œโ”€โ”€ Oracle.jsx           # Oracle agent UI
โ”‚   โ”‚       โ””โ”€โ”€ Builder.jsx          # Builder agent UI
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ vite.config.js
โ”‚
โ”œโ”€โ”€ start.sh                         # One-command launcher
โ”œโ”€โ”€ README.md                        # This file
โ””โ”€โ”€ ARCHITECTURE.md                  # Detailed architecture docs

๐Ÿค– AI Agent System

Oracle Agent

The Oracle is the governing intelligence of the village:

  • Environment Analysis: Evaluates terrain, resources, and opportunities
  • Strategic Planning: Determines optimal village development
  • Builder Guidance: Provides instructions to Builder agents
  • Decision Making: Uses AI-powered analysis for contextual decisions

Builder Agent

The Builder is an autonomous worker:

  • Resource Gathering: Automatically finds and harvests resources
  • Construction: Builds structures based on Oracle guidance
  • Autonomous Behavior: Makes independent decisions within Oracle's framework
  • Activity Logging: Reports all actions to activity feed

Orchestration

  • Oracle analyzes environment and creates strategic plan
  • Builder receives guidance and executes tasks
  • Real-time coordination and feedback loop
  • Activity log tracks all interactions

๐Ÿ› ๏ธ Tech Stack

Backend:

  • Python 3.9+
  • Flask 3.0 (REST API)
  • Flask-CORS (Cross-origin support)
  • Requests (HTTP client for external APIs)
  • Python-dotenv (Environment management)

Frontend:

  • React 18 (UI framework)
  • Vite 5 (Build tool & dev server)
  • Axios (HTTP client)
  • CSS3 (Styling with no frameworks)

APIs:

  • Freepik API (AI tile generation)
  • AIRIA API (Agent workflows - optional)

๐Ÿ› Troubleshooting

Port Issues

Port 5001 already in use:

lsof -ti:5001 | xargs kill -9

Note: Port 5000 is used by macOS AirPlay, so we use 5001 instead.

Port 3000 already in use:

lsof -ti:3000 | xargs kill -9

Module Not Found

Python:

cd backend
source venv/bin/activate
pip install -r requirements.txt

Node:

cd frontend
rm -rf node_modules package-lock.json
npm install

Trees Not Appearing

  • Check browser console for errors
  • Ensure backend is running on port 5001
  • Try refreshing the grid with the "Refresh Grid" button

Grid Not Loading

  • Verify Flask server is running: curl http://localhost:5001/api/health
  • Check CORS is enabled in app.py
  • Open browser developer tools and check Network tab

Performance Issues

  • The viewport system only renders visible tiles (~100-200 instead of 1,600)
  • If still slow, reduce grid size in grid_manager.py
  • Close other resource-intensive applications

๐Ÿ—บ๏ธ Roadmap

โœ… Phase 1: World Foundation (COMPLETE)

  • 40x40 grid system
  • Tile types and generation
  • Tree placement and harvesting
  • Resource tracking
  • Pan/zoom navigation
  • Viewport optimization

โœ… Phase 2: AI Agents (COMPLETE)

  • Oracle agent implementation
  • Builder agent implementation
  • Environment analyzer
  • Oracle-Builder orchestration
  • Activity logging system
  • Agent spawning UI

๐Ÿšง Phase 3: Advanced Simulation (IN PROGRESS)

  • Building construction system
  • Multiple Builder agents
  • Agent pathfinding
  • Day/night cycle
  • Weather system

๐Ÿ”ฎ Phase 4: Evolution & Complexity (PLANNED)

  • Agent personality evolution
  • Villager relationships
  • Trade system
  • Technology tree
  • Multi-village interactions

๐Ÿ“ License

MIT License - Feel free to build awesome stuff with this!


๐ŸŽ‰ Contributing

Contributions are welcome! This project is perfect for:

  • AI/ML enthusiasts interested in agent-based systems
  • Game developers exploring procedural generation
  • Full-stack developers wanting to work with React + Flask
  • Anyone interested in autonomous simulation systems

To contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐ŸŒŸ Acknowledgments

Built with โค๏ธ for autonomous AI simulations and emergent gameplay.

Technologies & APIs:

Made with ๐ŸŒณ by the Village Simulation Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •