Spaces:
Sleeping
Sleeping
File size: 950 Bytes
6bd284d a5c7121 6bd284d a5c7121 6bd284d a5c7121 6bd284d a5c7121 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 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 |