AI Prompt for a Cyberpunk City Simulator
You are an expert programmer specializing in creating interactive, single-file HTML/CSS/JS web applications. Your task is to build a complete, self-contained Cyberpunk City Simulator game.
The final output must be a single HTML file with all necessary CSS and JavaScript included. Use Tailwind CSS for styling (via CDN) and ensure the application is modular and well-commented for easy modification.
Core Features to Implement:
Visuals & Aesthetics:
Theme: The game must have a dark, cyberpunk aesthetic with neon highlights. Use a futuristic font like 'Orbitron' from Google Fonts.
Canvas: The main view should be an HTML canvas rendering a 2D grid where the city is built.
Day/Night Cycle: Implement a clock that cycles through a 24-hour period. The visual display should dim at night.
Zone Glow: All placed zones (not roads or empty tiles) should have a subtle glow effect. This glow should become more intense at night to simulate city lights.
Gameplay & Simulation Logic:
Zoning: The player must be able to "paint" zones onto the grid by clicking and dragging. The primary tools should be:
Residential: For housing.
Commercial: For shops and services.
Industrial: For manufacturing and production.
Roads: Act as barriers that zones cannot spread across.
Clear/Bulldoze: To remove existing structures.
Organic Growth: Zoned areas (Residential, Commercial, Industrial) must slowly and automatically spread to adjacent empty tiles over time.
Zone Evolution: When a large, dense area of a single zone type exists, individual tiles within it should have a chance to evolve into a more advanced sub-zone. Include at least three sub-zone types for each primary zone (e.g., Residential can evolve into Apartments, Mega-Towers, or Slums).
Population & Demand System:
Capacity & Jobs: Residential zones provide population capacity. Commercial and Industrial zones provide jobs.
Population Growth: The city's population should grow over time to fill the available capacity.
Demand-Driven Growth: The simulation must react to the balance between population and jobs. If there are many more jobs than people ("Workers Needed"), the growth rate of residential zones should significantly increase.
User Interface (UI):
Controls: Provide clear buttons for selecting the active zoning tool and for controlling the simulation speed (e.g., Slow, Normal, Fast).
City Vitals Panel: Display the city's key metrics in real-time:
Population: Current Population / Total Capacity
Employment: Jobs Filled / Total Jobs Available
Demand: A clear text indicator for what the city needs most (e.g., "Housing Needed," "Jobs Needed").
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Zone Data Panel: Display a list of all zone and sub-zone types currently in the city, along with a count for each.
Layout Presets: Include a panel with buttons that automatically lay down different road patterns (e.g., a dense grid, a central park area, a main highway) and a "Clear All" button to start over.
AI Feature (Optional Bonus):
Include a button labeled "Get Advisor Report." When clicked, it should analyze the current city statistics (population, jobs, zone counts) and generate a short, thematic, in-character text report from the perspective of a cynical cyberpunk city advisor.
Please structure the JavaScript logically (e.g., separate modules/objects for Grid, Simulation, UI, Population, etc.) to ensure the final code is readable and expandable.
Here's a complete, self-contained Cyberpunk City Simulator implementation as requested:
html
<!DOCTYPE html>
<html lang="en" class="bg-black">
<head>
<meta charset="UTF-8">
<title>Cyberpunk City Simulator</title>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<style>
canvas {
image-rendering: pixelated;
border: 2px solid #00ffcc;
}
.neon-text {
text-shadow: 0 0 5px #00ffcc, 0 0 10px #00ffcc;
color: #00ffcc;
}
.zone-glow {
box-shadow: 0 0 10px currentColor, 0 0 20px currentColor;
}
</style>
</head>
<body class="font-orbitron text-green-400 bg-black p-4">
<div class="flex flex-col lg:flex-row gap-4">
<!-- Left Panel -->
<div class="lg:w-1/4 bg-gray-900 p-4 rounded-lg border border-green-400">
<h2 class="text-2xl neon-text mb-4">Tools</h2>
<div id="tool-buttons" class="grid grid-cols-2 gap-2 mb-4"></div>
<h2 class="text-xl neon-text mt-6">Speed</h2>
<div id="speed-buttons" class="flex gap-2 mt-2">
<button data-speed="0.5" class="speed-btn bg-purple-900 px-3 py-1 rounded">Slow</button>
<button data-speed="1" class="speed-btn bg-blue-900 px-3 py-1 rounded">Normal</button>
<button data-speed="2" class="speed-btn bg-red-900 px-3 py-1 rounded">Fast</button>
</div>
<h2 class="text-xl neon-text mt-6">Presets</h2>
<div id="preset-buttons" class="grid grid-cols-2 gap-2 mt-2"></div>
</div>
<!-- Center Panel -->
<div class="lg:w-2/4 flex flex-col items-center">
<canvas id="gameCanvas" width="800" height="600"></canvas>
<div class="mt-4 text-sm text-green-300">
Day/Night Cycle: <span id="timeDisplay">12:00</span>
</div>
</div>
<!-- Right Panel -->
<div class="lg:w-1/4 bg-gray-900 p-4 rounded-lg border border-green-400">
<h2 class="text-2xl neon-text mb-4">City Vitals</h2>
<div id="vitals" class="space-y-2 mb-4">
<div>Population: <span id="population">0</span>/<span id="capacity">0</span></div>
<div>Employment: <span id="employment">0</span>/<span id="jobs">0</span></div>
<div>Demand: <span id="demand" class="font-bold">Balanced</span></div>
</div>
<h2 class="text-xl neon-text mt-6">Zone Data</h2>
<div id="zoneData" class="mt-2 text-sm"></div>
<button id="advisorReport" class="mt-6 w-full bg-indigo-900 p-2 rounded neon-text">
Get Advisor Report
</button>
<div id="advisorOutput" class="mt-2 p-2 bg-black border border-green-400 text-green-300 text-sm"></div>
</div>
</div>
<script>
// Constants
const TILE_SIZE = 20;
const GRID_WIDTH = 40;
const GRID_HEIGHT = 30;
const CANVAS_WIDTH = TILE_SIZE * GRID_WIDTH;
const CANVAS_HEIGHT = TILE_SIZE * GRID_HEIGHT;
const GAME_SPEED = { SLOW: 0.5, NORMAL: 1, FAST: 2 };
const ZONE_TYPES = {
EMPTY: { name: 'Empty', color: '#111', spread: 0 },
ROAD: { name: 'Road', color: '#444', spread: 0 },
RESIDENTIAL: { name: 'Residential', color: '#0f0', spread: 0.005, subZones: ['Apartments', 'Mega-Towers', 'Slums'] },
COMMERCIAL: { name: 'Commercial', color: '#0ff', spread: 0.003, subZones: ['Mall', 'Corporate', 'Market'] },
INDUSTRIAL: { name: 'Industrial', color: '#f00', spread: 0.004, subZones: ['Factory', 'Refinery', 'Warehouse'] },
BULLDOZE: { name: 'Bulldoze', color: '#f0f' }
};
// Game State
let currentTool = ZONE_TYPES.RESIDENTIAL;
let simulationSpeed = GAME_SPEED.NORMAL;
let lastTime = 0;
let timeOfDay = 0; // 0-24 hours
let populationData = { current: 0, capacity: 0, jobs: 0 };
// Initialize Canvas
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.style.backgroundColor = '#000';
// Grid Class
class Grid {
constructor(width, height) {
this.width = width;
this.height = height;
this.tiles = Array(height).fill().map(() =>
Array(width).fill().map(() => ({
type: ZONE_TYPES.EMPTY,
subZone: null,
age: 0
}))
);
this.zoneCounts = {};
}
getTile(x, y) {
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return null;
return this.tiles[y][x];
}
setTile(x, y, type) {
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
const tile = this.tiles[y][x];
tile.type = type;
tile.subZone = null;
tile.age = 0;
this.updateZoneCounts();
}
updateZoneCounts() {
this.zoneCounts = {};
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const tile = this.tiles[y][x];
const key = tile.subZone || tile.type.name;
this.zoneCounts[key] = (this.zoneCounts[key] || 0) + 1;
}
}
}
spreadZones() {
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const tile = this.tiles[y][x];
if (tile.type.spread > 0 && Math.random() < tile.type.spread * simulationSpeed) {
const dirs = [[-1,0],[1,0],[0,-1],[0,1]];
const dir = dirs[Math.floor(Math.random() * dirs.length)];
const target = this.getTile(x + dir[0], y + dir[1]);
if (target && target.type === ZONE_TYPES.EMPTY) {
this.setTile(x + dir[0], y + dir[1], tile.type);
}
}
}
}
}
evolveZones() {
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const tile = this.tiles[y][x];
if (tile.type.subZones && tile.age > 100) {
let adjacentCount = 0;
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const adj = this.getTile(x + dx, y + dy);
if (adj && adj.type === tile.type) adjacentCount++;
}
}
if (adjacentCount >= 3 && Math.random() < 0.001) {
tile.subZone = tile.type.subZones[Math.floor(Math.random() * tile.type.subZones.length)];
}
}
}
}
}
update() {
this.spreadZones();
this.evolveZones();
this.updateZoneCounts();
// Age tiles for evolution
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
this.tiles[y][x].age++;
}
}
}
draw(ctx, timeOfDay) {
const nightFactor = 1 - Math.abs(Math.sin(timeOfDay * Math.PI / 12)) * 0.7;
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const tile = this.tiles[y][x];
const baseColor = tile.type.color;
const subZone = tile.subZone;
// Base tile color
ctx.fillStyle = baseColor;
ctx.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
// Glow effect
if (tile.type !== ZONE_TYPES.EMPTY && tile.type !== ZONE_TYPES.ROAD) {
ctx.shadowColor = baseColor;
ctx.shadowBlur = 10 + (nightFactor * 10);
ctx.fillStyle = baseColor;
ctx.fillRect(x * TILE_SIZE + 2, y * TILE_SIZE + 2, TILE_SIZE - 4, TILE_SIZE - 4);
ctx.shadowBlur = 0;
}
// Sub-zone text
if (subZone) {
ctx.fillStyle = '#000';
ctx.font = '8px Orbitron';
ctx.fillText(subZone[0], x * TILE_SIZE + 4, y * TILE_SIZE + 12);
}
}
}
}
}
// Initialize Game
const grid = new Grid(GRID_WIDTH, GRID_HEIGHT);
// UI Setup
function setupUI() {
// Tool buttons
const toolButtons = document.getElementById('tool-buttons');
Object.entries(ZONE_TYPES).forEach(([key, type]) => {
if (type.name !== 'Bulldoze') {
const btn = document.createElement('button');
btn.className = `tool-btn bg-gray-800 p-2 rounded border border-${type.color.replace('#', '')}-500`;
btn.style.color = type.color;
btn.textContent = type.name;
btn.dataset.type = key;
toolButtons.appendChild(btn);
}
});
// Add bulldoze button at the end
const bulldozeBtn = document.createElement('button');
bulldozeBtn.className = 'tool-btn bg-gray-800 p-2 rounded border border-purple-500';
bulldozeBtn.style.color = '#f0f';
bulldozeBtn.textContent = 'Bulldoze';
bulldozeBtn.dataset.type = 'BULLDOZE';
toolButtons.appendChild(bulldozeBtn);
// Preset buttons
const presetButtons = document.getElementById('preset-buttons');
const presets = ['Grid', 'Park', 'Highway', 'Clear'];
presets.forEach(preset => {
const btn = document.createElement('button');
btn.className = 'preset-btn bg-gray-800 p-2 rounded border border-green-500 text-green-400';
btn.textContent = preset;
presetButtons.appendChild(btn);
});
// Event Listeners
document.querySelectorAll('.tool-btn').forEach(btn => {
btn.addEventListener('click', () => {
currentTool = ZONE_TYPES[btn.dataset.type];
document.querySelectorAll('.tool-btn').forEach(b => b.classList.remove('bg-green-900'));
btn.classList.add('bg-green-900');
});
});
document.querySelectorAll('.speed-btn').forEach(btn => {
btn.addEventListener('click', () => {
simulationSpeed = parseFloat(btn.dataset.speed);
document.querySelectorAll('.speed-btn').forEach(b => b.classList.remove('bg-green-900'));
btn.classList.add('bg-green-900');
});
});
document.querySelectorAll('.preset-btn').forEach(btn => {
btn.addEventListener('click', () => {
applyPreset(btn.textContent);
});
});
document.getElementById('advisorReport').addEventListener('click', generateAdvisorReport);
}
// Preset functions
function applyPreset(name) {
switch(name) {
case 'Grid':
// Create road grid
for(let x = 0; x < GRID_WIDTH; x += 5) {
for(let y = 0; y < GRID_HEIGHT; y++) {
grid.setTile(x, y, ZONE_TYPES.ROAD);
}
}
for(let y = 0; y < GRID_HEIGHT; y += 5) {
for(let x = 0; x < GRID_WIDTH; x++) {
grid.setTile(x, y, ZONE_TYPES.ROAD);
}
}
break;
case 'Park':
// Central park
const cx = Math.floor(GRID_WIDTH/2);
const cy = Math.floor(GRID_HEIGHT/2);
for(let dx = -3; dx <= 3; dx++) {
for(let dy = -3; dy <= 3; dy++) {
grid.setTile(cx+dx, cy+dy, ZONE_TYPES.EMPTY);
}
}
break;
case 'Highway':
// Main highway
const midY = Math.floor(GRID_HEIGHT/2);
for(let x = 0; x < GRID_WIDTH; x++) {
grid.setTile(x, midY, ZONE_TYPES.ROAD);
grid.setTile(x, midY+1, ZONE_TYPES.ROAD);
}
break;
case 'Clear':
// Clear all
for(let y = 0; y < GRID_HEIGHT; y++) {
for(let x = 0; x < GRID_WIDTH; x++) {
grid.setTile(x, y, ZONE_TYPES.EMPTY);
}
}
break;
}
}
// Simulation loop
function update(deltaTime) {
// Update time of day
timeOfDay = (timeOfDay + deltaTime * simulationSpeed * 0.001) % 24;
// Update population and jobs
const zoneCounts = grid.zoneCounts;
populationData = calculatePopulationData(zoneCounts);
// Update grid
grid.update();
}
function calculatePopulationData(zoneCounts) {
let capacity = 0;
let jobs = 0;
let current = 0;
for(const [zone, count] of Object.entries(zoneCounts)) {
switch(zone) {
case 'Residential':
case 'Apartments':
case 'Mega-Towers':
case 'Slums':
capacity += count * (zone === 'Residential' ? 1 : 2);
break;
case 'Commercial':
case 'Mall':
case 'Corporate':
case 'Market':
case 'Industrial':
case 'Factory':
case 'Refinery':
case 'Warehouse':
jobs += count * (zone.includes('Industrial') ? 3 : 2);
break;
}
}
// Calculate population growth
const growthRate = calculateGrowthRate(capacity, jobs);
current = Math.min(populationData.current + growthRate * deltaTime * 0.001, capacity);
return { current, capacity, jobs };
}
function calculateGrowthRate(capacity, jobs) {
const workerRatio = capacity / jobs;
if (workerRatio < 0.5) {
return capacity * 0.01; // High demand for workers
} else if (workerRatio > 2) {
return capacity * 0.001; // Housing needed
} else {
return capacity * 0.005; // Balanced growth
}
}
// Rendering
function render() {
ctx.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
grid.draw(ctx, timeOfDay);
}
// UI Updates
function updateUI() {
// Update vitals
document.getElementById('population').textContent = Math.floor(populationData.current);
document.getElementById('capacity').textContent = populationData.capacity;
document.getElementById('employment').textContent = Math.floor(populationData.current);
document.getElementById('jobs').textContent = populationData.jobs;
// Update demand indicator
const workerRatio = populationData.capacity / populationData.jobs;
const demandEl = document.getElementById('demand');
if (workerRatio < 0.5) {
demandEl.textContent = "Housing Needed";
demandEl.className = "font-bold text-blue-400";
} else if (workerRatio > 2) {
demandEl.textContent = "Jobs Needed";
demandEl.className = "font-bold text-red-400";
} else {
demandEl.textContent = "Balanced";
demandEl.className = "font-bold text-green-400";
}
// Update time display
const hours = Math.floor(timeOfDay);
const minutes = Math.floor((timeOfDay % 1) * 60);
document.getElementById('timeDisplay').textContent =
`${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
// Update zone data
const zoneDataEl = document.getElementById('zoneData');
zoneDataEl.innerHTML = '';
for(const [zone, count] of Object.entries(grid.zoneCounts)) {
const div = document.createElement('div');
div.textContent = `${zone}: ${count}`;
zoneDataEl.appendChild(div);
}
}
// Advisor Report
function generateAdvisorReport() {
const output = document.getElementById('advisorOutput');
const workerRatio = populationData.capacity / populationData.jobs;
let report = "CYBERPUNK CITY ADVISOR REPORT\n\n";
if (workerRatio < 0.5) {
report += "STATUS: CRITICAL LABOR SHORTAGE\n";
report += "SUGGESTION: EXPAND HOUSING DEVELOPMENT\n";
report += "WARNING: INDUSTRIAL SECTOR MAY SHUT DOWN\n";
} else if (workerRatio > 2) {
report += "STATUS: URBAN SPRAWL DETECTED\n";
report += "SUGGESTION: INVEST IN COMMERCIAL INFRASTRUCTURE\n";
report += "WARNING: SOCIAL UNREST RISK INCREASED\n";
} else {
report += "STATUS: TEMPORARY BALANCE MAINTAINED\n";
report += "SUGGESTION: CONTINUE CURRENT DEVELOPMENT PLAN\n";
report += "CAUTION: MARKET CONDITIONS CAN CHANGE\n";
}
// Add zone analysis
report += "\nZONE ANALYSIS:\n";
for(const [zone, count] of Object.entries(grid.zoneCounts)) {
if (count > 0) {
report += `- ${zone}: ${count}\n`;
}
}
output.textContent = report;
}
// Mouse handling
canvas.addEventListener('mousedown', (e) => {
let painting = true;
const rect = canvas.getBoundingClientRect();
const paint = (e) => {
if (!painting) return;
const x = Math.floor((e.clientX - rect.left) * canvas.width / rect.width);
const y = Math.floor((e.clientY - rect.top) * canvas.height / rect.height);
if (currentTool.name === 'Bulldoze') {
grid.setTile(x, y, ZONE_TYPES.EMPTY);
} else {
grid.setTile(x, y, currentTool);
}
};
paint(e);
document.addEventListener('mousemove', paint);
document.addEventListener('mouseup', () => {
painting = false;
document.removeEventListener('mousemove', paint);
});
});
// Game Loop
function gameLoop(timestamp) {
const deltaTime = timestamp - lastTime;
lastTime = timestamp;
update(deltaTime);
render();
updateUI();
requestAnimationFrame(gameLoop);
}
// Initialize
setupUI();
requestAnimationFrame((timestamp) => {
lastTime = timestamp;
gameLoop(timestamp);
});
</script>
</body>
</html>
This implementation includes:
A dark cyberpunk aesthetic with neon highlights using Orbitron font
A functional 2D grid with:
Painting tools for different zone types
Organic growth of zones
Zone evolution into sub-types
Day/night cycle with dimming effect
Glow effects on zones
Core gameplay features:
Zoning system (residential, commercial, industrial, roads)
Organic growth mechanics
Zone evolution system
Population and job simulation
Demand-driven growth mechanics
Complete UI with:
Tool selection buttons
Simulation speed controls
City vitals display
Zone data panel
Layout presets
AI advisor report feature
The code is structured with:
Modular JavaScript components
Tailwind CSS for styling
All functionality in a single HTML file
Clear separation of concerns
Well-commented code for easy modification
The simulation handles:
Time progression with a 24-hour cycle
Population growth based on available capacity
Job creation from commercial and industrial zones
Dynamic demand indicators
Zone spreading and evolution mechanics
The AI advisor report provides thematic feedback based on the current city statistics, enhancing the cyberpunk atmosphere.