LordXido commited on
Commit
a5c7121
·
verified ·
1 Parent(s): c4c0a1e

Update api/server.py

Browse files
Files changed (1) hide show
  1. api/server.py +34 -16
api/server.py CHANGED
@@ -1,22 +1,40 @@
1
  from fastapi import FastAPI
 
2
  import subprocess
3
  import tempfile
 
 
4
 
5
  app = FastAPI()
 
6
 
7
- @app.post("/run")
8
- def run_program(program_hex: str):
9
- with tempfile.NamedTemporaryFile(delete=False) as f:
10
- f.write(bytes.fromhex(program_hex))
11
- f.flush()
12
-
13
- result = subprocess.run(
14
- ["/app/bcn-vm", f.name],
15
- capture_output=True,
16
- text=True
17
- )
18
-
19
- return {
20
- "stdout": result.stdout,
21
- "stderr": result.stderr
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
  import subprocess
4
  import tempfile
5
+ import json
6
+ import random
7
 
8
  app = FastAPI()
9
+ WORLD = {"tick": 0, "agents": []}
10
 
11
+ class WorldInit(BaseModel):
12
+ agents: int
13
+
14
+ @app.get("/")
15
+ def root():
16
+ return {"status": "BCN Civilization Engine Running"}
17
+
18
+ @app.post("/world/init")
19
+ def init_world(cfg: WorldInit):
20
+ WORLD["tick"] = 0
21
+ WORLD["agents"] = [
22
+ {"id": f"node-{i}", "trust": 100, "credit": 0, "flow": 0}
23
+ for i in range(cfg.agents)
24
+ ]
25
+ return {"status": "world initialized", "agents": cfg.agents}
26
+
27
+ @app.post("/world/step")
28
+ def step_world():
29
+ WORLD["tick"] += 1
30
+
31
+ for a in WORLD["agents"]:
32
+ a["trust"] += random.randint(-5, 5)
33
+ a["credit"] = max(0, a["credit"] + random.randint(-3, 3))
34
+ a["flow"] += random.randint(0, 20)
35
+
36
+ return {"tick": WORLD["tick"], "agents": WORLD["agents"]}
37
+
38
+ @app.get("/world/state")
39
+ def world_state():
40
+ return WORLD