Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -110,20 +110,22 @@ async def handle_action(request: Request):
|
|
| 110 |
return {"success": False, "message": "You can only steal once per turn."}
|
| 111 |
|
| 112 |
if action == 'coup':
|
| 113 |
-
game["
|
| 114 |
-
"
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
if action == 'challengeResponse':
|
| 123 |
if not game.get("challenge"):
|
| 124 |
return {"success": False, "message": "No challenge pending."}
|
| 125 |
|
| 126 |
-
# Assuming game["players"] now contains player dictionaries with a "name" key.
|
| 127 |
challenger = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 128 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 129 |
|
|
@@ -156,12 +158,10 @@ async def handle_action(request: Request):
|
|
| 156 |
return {"success": False, "message": f"Card {target} not found in {challenger['name']}'s hand."}
|
| 157 |
|
| 158 |
if action == 'income':
|
| 159 |
-
# Find the player in the players list
|
| 160 |
player_found = False
|
| 161 |
for p in game["players"]:
|
| 162 |
if p["name"] == player:
|
| 163 |
player_found = True
|
| 164 |
-
# If gain permission is not available, then income has already been taken.
|
| 165 |
if not game["permissions"].get(player, {}).get("gain", True):
|
| 166 |
return {"success": False, "message": "You can only earn money once per turn."}
|
| 167 |
p["coins"] += 1
|
|
|
|
| 110 |
return {"success": False, "message": "You can only steal once per turn."}
|
| 111 |
|
| 112 |
if action == 'coup':
|
| 113 |
+
if (game["players"].get(player, {}).get("coins", {}) > 6):
|
| 114 |
+
game["challenge"] = {
|
| 115 |
+
"action": 'coup',
|
| 116 |
+
"challenger": target,
|
| 117 |
+
"target": player,
|
| 118 |
+
"challengeType": 'coup',
|
| 119 |
+
"status": 'choose'
|
| 120 |
+
}
|
| 121 |
+
return {"success": True, "message": f"Coup initiated by {player} targeting {target}."}
|
| 122 |
+
else:
|
| 123 |
+
return {"success": False, "message": "You don't have enough coins to coup another player."}
|
| 124 |
|
| 125 |
if action == 'challengeResponse':
|
| 126 |
if not game.get("challenge"):
|
| 127 |
return {"success": False, "message": "No challenge pending."}
|
| 128 |
|
|
|
|
| 129 |
challenger = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 130 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 131 |
|
|
|
|
| 158 |
return {"success": False, "message": f"Card {target} not found in {challenger['name']}'s hand."}
|
| 159 |
|
| 160 |
if action == 'income':
|
|
|
|
| 161 |
player_found = False
|
| 162 |
for p in game["players"]:
|
| 163 |
if p["name"] == player:
|
| 164 |
player_found = True
|
|
|
|
| 165 |
if not game["permissions"].get(player, {}).get("gain", True):
|
| 166 |
return {"success": False, "message": "You can only earn money once per turn."}
|
| 167 |
p["coins"] += 1
|