from fastapi import FastAPI from pydantic import BaseModel import subprocess import tempfile import json import random app = FastAPI() WORLD = {"tick": 0, "agents": []} class WorldInit(BaseModel): agents: int @app.get("/") def root(): return {"status": "BCN Civilization Engine Running"} @app.post("/world/init") def init_world(cfg: WorldInit): WORLD["tick"] = 0 WORLD["agents"] = [ {"id": f"node-{i}", "trust": 100, "credit": 0, "flow": 0} for i in range(cfg.agents) ] return {"status": "world initialized", "agents": cfg.agents} @app.post("/world/step") def step_world(): WORLD["tick"] += 1 for a in WORLD["agents"]: a["trust"] += random.randint(-5, 5) a["credit"] = max(0, a["credit"] + random.randint(-3, 3)) a["flow"] += random.randint(0, 20) return {"tick": WORLD["tick"], "agents": WORLD["agents"]} @app.get("/world/state") def world_state(): return WORLD