Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,6 +74,7 @@ async def get_game_status(pin: str):
|
|
| 74 |
game = games.get(pin)
|
| 75 |
if not game:
|
| 76 |
raise HTTPException(status_code=404, detail="Game not found.")
|
|
|
|
| 77 |
return {"success": True, "game": game}
|
| 78 |
|
| 79 |
@app.post("/api/handleAction")
|
|
@@ -434,3 +435,19 @@ def generate_cards():
|
|
| 434 |
|
| 435 |
if __name__ == "__main__":
|
| 436 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
game = games.get(pin)
|
| 75 |
if not game:
|
| 76 |
raise HTTPException(status_code=404, detail="Game not found.")
|
| 77 |
+
check_game_status(game)
|
| 78 |
return {"success": True, "game": game}
|
| 79 |
|
| 80 |
@app.post("/api/handleAction")
|
|
|
|
| 435 |
|
| 436 |
if __name__ == "__main__":
|
| 437 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 438 |
+
|
| 439 |
+
def check_game_status(game):
|
| 440 |
+
# Remove any players without cards.
|
| 441 |
+
game["players"] = [p for p in game.get("players", []) if p.get("cards")]
|
| 442 |
+
|
| 443 |
+
# Update permissions: If a player has more than 10 coins, flag them to coup.
|
| 444 |
+
for p in game["players"]:
|
| 445 |
+
name = p["name"]
|
| 446 |
+
if p.get("coins", 0) > 10:
|
| 447 |
+
if name not in game.get("permissions", {}):
|
| 448 |
+
game.setdefault("permissions", {})[name] = {}
|
| 449 |
+
game["permissions"][name]["mustCoup"] = True
|
| 450 |
+
else:
|
| 451 |
+
if name in game.get("permissions", {}):
|
| 452 |
+
game["permissions"][name].pop("mustCoup", None)
|
| 453 |
+
return game
|