incognitolm commited on
Commit
9b6b96a
·
verified ·
1 Parent(s): 1a50057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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["challenge"] = {
114
- "action": 'coup',
115
- "challenger": target,
116
- "target": player,
117
- "challengeType": 'coup',
118
- "status": 'choose'
119
- }
120
- return {"success": True, "message": f"Coup initiated by {player} targeting {target}."}
 
 
 
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