An autonomous AI-driven village simulation with dynamic grid-based world generation, resource management, intelligent Oracle and Builder agents, and evolving gameplay.
- 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
- 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
- Wood: Harvested from trees (5-15 units per tree)
- Stone: Mining resources (planned)
- Food: Gathering system (planned)
- Real-time tracking with visual resource panel
- 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
- Python 3.9+
- Node.js 16+
- npm or yarn
# Clone the repository
git clone https://github.com/Suhaas15/VillageSimulation.git
cd VillageSimulation
# Run the launcher
./start.shOpen http://localhost:3000 in your browser! ๐
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.pyTerminal 2 - Frontend:
cd frontend
npm install
npm run dev| 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 |
- Spawn Oracle: Creates the governing AI that analyzes the environment
- Oracle Analysis: Oracle evaluates resources, terrain, and strategic opportunities
- Spawn Builder: Creates a worker agent to execute tasks
- Builder Actions: Builder autonomously gathers resources and builds based on Oracle guidance
- Watch Activity Log: Real-time feed shows all agent decisions and actions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ 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 โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
app.py: Flask API server with CORS-enabled endpointsgrid_manager.py: 40x40 grid state management and tree generationvillage_state.py: Persistent village state and resource trackingoracle_agent.py: Oracle AI agent implementationbuilder_agent.py: Builder AI agent with autonomous behaviorsoracle_environment_analyzer.py: Environment analysis for Oracle decision-makingbuilder_oracle_orchestrator.py: Coordination layer between Oracle and Buildervillage_actions.py: Action system for agent behaviorsfreepik_api.py: AI tile generation integration
| 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 |
| Endpoint | Method | Description |
|---|---|---|
/api/resources |
GET | Get current resource counts |
/api/tree/cut |
POST | Cut down a tree and gain wood |
| 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 |
# backend/grid_manager.py
def __init__(self, grid_size: int = 40): # Change to 50, 60, etc.// frontend/src/components/VillageGrid.jsx
const TILE_SIZE = 64 // Change to 32, 48, 128, etc.# backend/grid_manager.py - in _generate_trees_for_tile()
num_trees = random.randint(1, 3) # More trees per tile- Get a Freepik API key from Freepik Developer Portal
- Create
.envfile inbackend/directory:
FREEPIK_API_KEY=your_api_key_here- Call the initialization endpoint:
curl -X POST http://localhost:5001/api/grid/initializeVillageSimulation/
โโโ 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
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
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
- Oracle analyzes environment and creates strategic plan
- Builder receives guidance and executes tasks
- Real-time coordination and feedback loop
- Activity log tracks all interactions
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)
Port 5001 already in use:
lsof -ti:5001 | xargs kill -9Note: Port 5000 is used by macOS AirPlay, so we use 5001 instead.
Port 3000 already in use:
lsof -ti:3000 | xargs kill -9Python:
cd backend
source venv/bin/activate
pip install -r requirements.txtNode:
cd frontend
rm -rf node_modules package-lock.json
npm install- Check browser console for errors
- Ensure backend is running on port 5001
- Try refreshing the grid with the "Refresh Grid" button
- 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
- 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
- 40x40 grid system
- Tile types and generation
- Tree placement and harvesting
- Resource tracking
- Pan/zoom navigation
- Viewport optimization
- Oracle agent implementation
- Builder agent implementation
- Environment analyzer
- Oracle-Builder orchestration
- Activity logging system
- Agent spawning UI
- Building construction system
- Multiple Builder agents
- Agent pathfinding
- Day/night cycle
- Weather system
- Agent personality evolution
- Villager relationships
- Trade system
- Technology tree
- Multi-village interactions
MIT License - Feel free to build awesome stuff with this!
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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Built with โค๏ธ for autonomous AI simulations and emergent gameplay.
Technologies & APIs:
- React - Frontend framework
- Flask - Backend API
- Vite - Build tool
- Freepik API - AI image generation
Made with ๐ณ by the Village Simulation Team