Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -88,24 +88,11 @@ async def handle_action(request: Request):
|
|
| 88 |
|
| 89 |
if pin not in games:
|
| 90 |
raise HTTPException(status_code=404, detail="Game not found.")
|
|
|
|
| 91 |
game = games[pin]
|
| 92 |
|
| 93 |
-
# --- getStatus: update coins & remove players with no cards ---
|
| 94 |
if action == 'getStatus':
|
| 95 |
-
|
| 96 |
-
removed = []
|
| 97 |
-
for p in game["players"][:]:
|
| 98 |
-
if not p["cards"]:
|
| 99 |
-
removed.append(p["name"])
|
| 100 |
-
game["players"].remove(p)
|
| 101 |
-
game["permissions"].pop(p["name"], None)
|
| 102 |
-
# Update required coup: if a player has 10+ coins, mark them.
|
| 103 |
-
for p in game["players"]:
|
| 104 |
-
if p["coins"] >= 10:
|
| 105 |
-
game["permissions"][p["name"]]["requiredCoup"] = True
|
| 106 |
-
else:
|
| 107 |
-
game["permissions"][p["name"]]["requiredCoup"] = False
|
| 108 |
-
return {"success": True, "challenge": game.get("challenge", None), "players": game["players"]}
|
| 109 |
|
| 110 |
if action == 'steal':
|
| 111 |
if game["permissions"].get(player, {}).get("steal", True):
|
|
@@ -122,7 +109,6 @@ async def handle_action(request: Request):
|
|
| 122 |
return {"success": False, "message": "You can only steal once per turn."}
|
| 123 |
|
| 124 |
if action == 'coup':
|
| 125 |
-
# Regular coup process – assume caller has already paid coins.
|
| 126 |
player_data = next((p for p in game["players"] if p["name"] == player), None)
|
| 127 |
if not player_data:
|
| 128 |
return {"success": False, "message": "Player not found."}
|
|
@@ -139,188 +125,143 @@ async def handle_action(request: Request):
|
|
| 139 |
return {"success": True, "message": f"Coup initiated by {player} targeting {target}."}
|
| 140 |
|
| 141 |
if action == 'assassin':
|
|
|
|
| 142 |
if game["turn"] != player:
|
| 143 |
return {"success": False, "message": "Not your turn."}
|
| 144 |
-
#
|
| 145 |
game["challenge"] = {
|
| 146 |
"action": "assassin",
|
| 147 |
-
"challenger": player,
|
| 148 |
-
"target": target,
|
| 149 |
"challengeType": "assassin",
|
| 150 |
"status": "pending",
|
| 151 |
-
"phase": "target_decision" # awaiting target's decision: allow
|
| 152 |
}
|
| 153 |
return {"success": True, "message": f"Assassin action initiated by {player} targeting {target}. Awaiting target's response."}
|
| 154 |
|
| 155 |
-
if action == 'duke':
|
| 156 |
-
if game["turn"] != player:
|
| 157 |
-
return {"success": False, "message": "Not your turn."}
|
| 158 |
-
# Create a Duke challenge so that all opponents may challenge or allow.
|
| 159 |
-
game["challenge"] = {
|
| 160 |
-
"action": "duke",
|
| 161 |
-
"challenger": player,
|
| 162 |
-
"challengeType": "duke",
|
| 163 |
-
"status": "pending",
|
| 164 |
-
"responses": {}
|
| 165 |
-
}
|
| 166 |
-
return {"success": True, "message": f"{player} is claiming Duke for Tax. Waiting for opponents to respond."}
|
| 167 |
-
|
| 168 |
-
# --- challengeResponse branch: handle various challenge types ---
|
| 169 |
if action == 'challengeResponse':
|
| 170 |
if not game.get("challenge"):
|
| 171 |
return {"success": False, "message": "No challenge pending."}
|
| 172 |
|
| 173 |
-
# Handle
|
| 174 |
if game["challenge"]["challengeType"] == "steal":
|
| 175 |
-
|
| 176 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 177 |
if response == 'accept':
|
| 178 |
coins_to_steal = min(target_player["coins"], 2)
|
| 179 |
target_player["coins"] -= coins_to_steal
|
| 180 |
-
|
| 181 |
game["challenge"] = None
|
| 182 |
-
return {"success": True, "message": f"Steal accepted. {coins_to_steal} coins transferred from {target_player['name']} to {
|
| 183 |
elif response == 'challenge':
|
| 184 |
-
if "Captain" in
|
| 185 |
coins_to_steal = min(target_player["coins"], 2)
|
| 186 |
target_player["coins"] -= coins_to_steal
|
| 187 |
-
|
| 188 |
game["challenge"]["status"] = 'choose'
|
| 189 |
game["challenge"]["challenger"] = target_player['name']
|
| 190 |
-
game["challenge"]["target"] =
|
| 191 |
-
return {"success": True, "message": f"Challenge failed. {target_player['name']} loses {coins_to_steal} coins to {
|
| 192 |
else:
|
| 193 |
game["challenge"]["status"] = 'choose'
|
| 194 |
-
return {"success": True, "message": f"Challenge successful. {
|
| 195 |
|
| 196 |
-
# Handle
|
| 197 |
-
elif game["challenge"]["challengeType"] == "
|
| 198 |
if response == 'allow':
|
| 199 |
if "responses" not in game["challenge"]:
|
| 200 |
game["challenge"]["responses"] = {}
|
| 201 |
game["challenge"]["responses"][player] = 'allow'
|
| 202 |
total_opponents = len(game["players"]) - 1
|
| 203 |
if len(game["challenge"]["responses"]) == total_opponents:
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
# Prevent further gain actions.
|
| 207 |
-
game["permissions"][duke_player["name"]]["gain"] = False
|
| 208 |
game["challenge"] = None
|
| 209 |
-
return {"success": True, "message": f"{
|
| 210 |
else:
|
| 211 |
-
return {"success": True, "message": f"{player} allowed
|
| 212 |
elif response == 'challenge':
|
| 213 |
-
|
| 214 |
-
if "
|
| 215 |
-
game["challenge"]["status"] = "choose"
|
| 216 |
-
game["challenge"]["challenger"] = player # the challenger must lose a card.
|
| 217 |
-
return {"success": True, "message": f"Challenge failed. {player} must choose a card to lose.", "challenge": game["challenge"]}
|
| 218 |
-
else:
|
| 219 |
game["challenge"]["status"] = "choose"
|
| 220 |
-
game["challenge"]["challenger"] =
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
# Handle Foreign Aid challenge/duke block.
|
| 224 |
-
elif game["challenge"]["challengeType"] == "foreignAid":
|
| 225 |
-
if game["challenge"].get("phase") == "foreignAid_duke":
|
| 226 |
-
if response == "accept":
|
| 227 |
game["challenge"] = None
|
| 228 |
-
return {"success": True, "message": f"
|
| 229 |
-
elif response == "challenge":
|
| 230 |
-
blocker_player = next(p for p in game["players"] if p["name"] == game["challenge"]["blocker"])
|
| 231 |
-
if "Duke" in blocker_player["cards"]:
|
| 232 |
-
game["challenge"]["status"] = "choose"
|
| 233 |
-
game["challenge"]["challenger"] = game["challenge"]["challenger"]
|
| 234 |
-
return {"success": True, "message": f"Challenge failed. {game['challenge']['challenger']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 235 |
-
else:
|
| 236 |
-
game["challenge"]["status"] = "choose"
|
| 237 |
-
game["challenge"]["challenger"] = blocker_player["name"]
|
| 238 |
-
return {"success": True, "message": f"Challenge successful. {blocker_player['name']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 239 |
-
else:
|
| 240 |
-
if player == game["challenge"]["challenger"]:
|
| 241 |
-
return {"success": False, "message": "Challenger cannot respond to their own action."}
|
| 242 |
-
game["challenge"]["responses"][player] = response
|
| 243 |
-
if response == "block":
|
| 244 |
-
game["challenge"]["phase"] = "foreignAid_duke"
|
| 245 |
-
game["challenge"]["blocker"] = player
|
| 246 |
-
return {"success": True, "message": f"{player} is blocking Foreign Aid by claiming Duke. {game['challenge']['challenger']} may now challenge or accept."}
|
| 247 |
else:
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
challenger_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 251 |
-
challenger_player["coins"] += 2
|
| 252 |
-
game["challenge"] = None
|
| 253 |
-
return {"success": True, "message": f"Foreign Aid accepted. {challenger_player['name']} gains 2 coins."}
|
| 254 |
-
else:
|
| 255 |
-
return {"success": True, "message": f"{player} allowed Foreign Aid. Awaiting other responses."}
|
| 256 |
|
| 257 |
-
# Handle Assassin/Contessa responses
|
| 258 |
elif game["challenge"]["challengeType"] == "assassin":
|
|
|
|
| 259 |
if game["challenge"].get("phase") == "target_decision":
|
| 260 |
if response == "allow":
|
|
|
|
| 261 |
game["challenge"]["status"] = "choose"
|
| 262 |
-
#
|
| 263 |
game["challenge"]["challenger"] = game["challenge"]["target"]
|
| 264 |
return {"success": True, "message": f"{game['challenge']['target']} must now choose a card to lose."}
|
| 265 |
elif response == "challenge":
|
|
|
|
| 266 |
assassin_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 267 |
if "Assassin" in assassin_player["cards"]:
|
|
|
|
| 268 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 269 |
-
target_player["cards"] = [] #
|
| 270 |
game["challenge"] = None
|
| 271 |
return {"success": True, "message": f"Challenge failed. {target_player['name']} loses both cards."}
|
| 272 |
else:
|
|
|
|
| 273 |
game["challenge"]["status"] = "choose"
|
| 274 |
game["challenge"]["challenger"] = assassin_player["name"]
|
| 275 |
return {"success": True, "message": f"Challenge successful. {assassin_player['name']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 276 |
elif response == "contessa":
|
|
|
|
| 277 |
game["challenge"]["phase"] = "assassin_contessa"
|
| 278 |
return {"success": True, "message": f"{game['challenge']['challenger']} must now choose to challenge or accept the Contessa."}
|
|
|
|
| 279 |
elif game["challenge"].get("phase") == "assassin_contessa":
|
| 280 |
if response == "accept":
|
|
|
|
| 281 |
game["challenge"]["status"] = "choose"
|
| 282 |
game["challenge"]["challenger"] = game["challenge"]["target"]
|
| 283 |
return {"success": True, "message": f"{game['challenge']['target']} must now choose a card to lose."}
|
| 284 |
elif response == "challenge":
|
|
|
|
| 285 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 286 |
if "Contessa" in target_player["cards"]:
|
|
|
|
| 287 |
game["challenge"]["status"] = "choose"
|
| 288 |
-
#
|
| 289 |
game["challenge"]["challenger"] = game["challenge"]["challenger"]
|
| 290 |
return {"success": True, "message": f"Contessa challenge successful. {game['challenge']['challenger']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 291 |
else:
|
|
|
|
| 292 |
target_player["cards"] = []
|
| 293 |
game["challenge"] = None
|
| 294 |
return {"success": True, "message": f"Contessa challenge failed. {target_player['name']} loses both cards."}
|
| 295 |
|
| 296 |
-
# Handle
|
| 297 |
-
elif game["challenge"]["challengeType"] == "
|
| 298 |
-
if
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
total_opponents = len(game["players"]) - 1
|
| 303 |
if len(game["challenge"]["responses"]) == total_opponents:
|
| 304 |
-
|
| 305 |
-
|
| 306 |
game["challenge"] = None
|
| 307 |
-
return {"success": True, "message": f"
|
| 308 |
else:
|
| 309 |
-
return {"success": True, "message": f"{player} allowed
|
| 310 |
-
|
| 311 |
-
ambassador_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 312 |
-
if "Ambassador" in ambassador_player["cards"]:
|
| 313 |
-
game["challenge"]["status"] = "choose"
|
| 314 |
-
game["challenge"]["challenger"] = player
|
| 315 |
-
game["challenge"]["target"] = ambassador_player["name"]
|
| 316 |
-
ambassador_player["cards"] = generate_cards()
|
| 317 |
-
game["challenge"] = None
|
| 318 |
-
return {"success": True, "message": f"Challenge failed. {player} must lose a card, while {ambassador_player['name']} swaps cards with the deck."}
|
| 319 |
-
else:
|
| 320 |
-
game["challenge"]["status"] = "choose"
|
| 321 |
-
return {"success": True, "message": "Challenge successful. Ambassador user must choose a card to lose.", "challenge": game["challenge"]}
|
| 322 |
-
# End of challengeResponse branch.
|
| 323 |
-
|
| 324 |
if action == 'ambassador':
|
| 325 |
if game["turn"] != player:
|
| 326 |
return {"success": False, "message": "Not your turn."}
|
|
@@ -343,16 +284,16 @@ async def handle_action(request: Request):
|
|
| 343 |
return {"success": False, "message": f"Card {target} not found in {acting_player['name']}'s hand."}
|
| 344 |
|
| 345 |
if action == 'income':
|
| 346 |
-
|
| 347 |
for p in game["players"]:
|
| 348 |
if p["name"] == player:
|
| 349 |
-
|
| 350 |
if not game["permissions"].get(player, {}).get("gain", True):
|
| 351 |
return {"success": False, "message": "You can only earn money once per turn."}
|
| 352 |
p["coins"] += 1
|
| 353 |
game["permissions"][player]["gain"] = False
|
| 354 |
return {"success": True, "message": f"You now have {p['coins']} coins."}
|
| 355 |
-
if not
|
| 356 |
raise HTTPException(status_code=404, detail="Player not found in the game.")
|
| 357 |
|
| 358 |
if action == 'foreignAid':
|
|
|
|
| 88 |
|
| 89 |
if pin not in games:
|
| 90 |
raise HTTPException(status_code=404, detail="Game not found.")
|
| 91 |
+
|
| 92 |
game = games[pin]
|
| 93 |
|
|
|
|
| 94 |
if action == 'getStatus':
|
| 95 |
+
return {"success": True, "challenge": game.get("challenge", None)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
if action == 'steal':
|
| 98 |
if game["permissions"].get(player, {}).get("steal", True):
|
|
|
|
| 109 |
return {"success": False, "message": "You can only steal once per turn."}
|
| 110 |
|
| 111 |
if action == 'coup':
|
|
|
|
| 112 |
player_data = next((p for p in game["players"] if p["name"] == player), None)
|
| 113 |
if not player_data:
|
| 114 |
return {"success": False, "message": "Player not found."}
|
|
|
|
| 125 |
return {"success": True, "message": f"Coup initiated by {player} targeting {target}."}
|
| 126 |
|
| 127 |
if action == 'assassin':
|
| 128 |
+
# Assassin action: must be the player's turn.
|
| 129 |
if game["turn"] != player:
|
| 130 |
return {"success": False, "message": "Not your turn."}
|
| 131 |
+
# Create an assassin challenge waiting for the target's decision.
|
| 132 |
game["challenge"] = {
|
| 133 |
"action": "assassin",
|
| 134 |
+
"challenger": player, # the assassin
|
| 135 |
+
"target": target, # the chosen target
|
| 136 |
"challengeType": "assassin",
|
| 137 |
"status": "pending",
|
| 138 |
+
"phase": "target_decision" # awaiting target's decision: allow/challenge/contessa
|
| 139 |
}
|
| 140 |
return {"success": True, "message": f"Assassin action initiated by {player} targeting {target}. Awaiting target's response."}
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
if action == 'challengeResponse':
|
| 143 |
if not game.get("challenge"):
|
| 144 |
return {"success": False, "message": "No challenge pending."}
|
| 145 |
|
| 146 |
+
# --- Handle existing steal response ---
|
| 147 |
if game["challenge"]["challengeType"] == "steal":
|
| 148 |
+
challenger_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 149 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 150 |
if response == 'accept':
|
| 151 |
coins_to_steal = min(target_player["coins"], 2)
|
| 152 |
target_player["coins"] -= coins_to_steal
|
| 153 |
+
challenger_player["coins"] += coins_to_steal
|
| 154 |
game["challenge"] = None
|
| 155 |
+
return {"success": True, "message": f"Steal accepted. {coins_to_steal} coins transferred from {target_player['name']} to {challenger_player['name']}."}
|
| 156 |
elif response == 'challenge':
|
| 157 |
+
if "Captain" in challenger_player["cards"]:
|
| 158 |
coins_to_steal = min(target_player["coins"], 2)
|
| 159 |
target_player["coins"] -= coins_to_steal
|
| 160 |
+
challenger_player["coins"] += coins_to_steal
|
| 161 |
game["challenge"]["status"] = 'choose'
|
| 162 |
game["challenge"]["challenger"] = target_player['name']
|
| 163 |
+
game["challenge"]["target"] = challenger_player['name']
|
| 164 |
+
return {"success": True, "message": f"Challenge failed. {target_player['name']} loses {coins_to_steal} coins to {challenger_player['name']}."}
|
| 165 |
else:
|
| 166 |
game["challenge"]["status"] = 'choose'
|
| 167 |
+
return {"success": True, "message": f"Challenge successful. {challenger_player['name']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 168 |
|
| 169 |
+
# --- Handle Ambassador response (existing) ---
|
| 170 |
+
elif game["challenge"]["challengeType"] == "ambassador":
|
| 171 |
if response == 'allow':
|
| 172 |
if "responses" not in game["challenge"]:
|
| 173 |
game["challenge"]["responses"] = {}
|
| 174 |
game["challenge"]["responses"][player] = 'allow'
|
| 175 |
total_opponents = len(game["players"]) - 1
|
| 176 |
if len(game["challenge"]["responses"]) == total_opponents:
|
| 177 |
+
ambassador_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 178 |
+
ambassador_player["cards"] = generate_cards()
|
|
|
|
|
|
|
| 179 |
game["challenge"] = None
|
| 180 |
+
return {"success": True, "message": f"Ambassador action accepted. {ambassador_player['name']} swaps cards with the deck."}
|
| 181 |
else:
|
| 182 |
+
return {"success": True, "message": f"{player} allowed the Ambassador action. Awaiting other responses."}
|
| 183 |
elif response == 'challenge':
|
| 184 |
+
ambassador_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 185 |
+
if "Ambassador" in ambassador_player["cards"]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
game["challenge"]["status"] = "choose"
|
| 187 |
+
game["challenge"]["challenger"] = player # challenger loses card
|
| 188 |
+
game["challenge"]["target"] = ambassador_player["name"]
|
| 189 |
+
ambassador_player["cards"] = generate_cards()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
game["challenge"] = None
|
| 191 |
+
return {"success": True, "message": f"Challenge failed. {player} must lose a card, while {ambassador_player['name']} swaps cards with the deck."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
else:
|
| 193 |
+
game["challenge"]["status"] = "choose"
|
| 194 |
+
return {"success": True, "message": "Challenge successful. Ambassador user must choose a card to lose.", "challenge": game["challenge"]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
+
# --- Handle Assassin/Contessa responses ---
|
| 197 |
elif game["challenge"]["challengeType"] == "assassin":
|
| 198 |
+
# Phase 1: target's decision on assassination
|
| 199 |
if game["challenge"].get("phase") == "target_decision":
|
| 200 |
if response == "allow":
|
| 201 |
+
# Target accepts assassination: must lose one card.
|
| 202 |
game["challenge"]["status"] = "choose"
|
| 203 |
+
# Set the losing player to the target.
|
| 204 |
game["challenge"]["challenger"] = game["challenge"]["target"]
|
| 205 |
return {"success": True, "message": f"{game['challenge']['target']} must now choose a card to lose."}
|
| 206 |
elif response == "challenge":
|
| 207 |
+
# Target challenges the assassin's claim.
|
| 208 |
assassin_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 209 |
if "Assassin" in assassin_player["cards"]:
|
| 210 |
+
# Assassin is truthful: target loses both cards.
|
| 211 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 212 |
+
target_player["cards"] = [] # remove all cards (eliminated)
|
| 213 |
game["challenge"] = None
|
| 214 |
return {"success": True, "message": f"Challenge failed. {target_player['name']} loses both cards."}
|
| 215 |
else:
|
| 216 |
+
# Assassin is lying: assassin must lose one card.
|
| 217 |
game["challenge"]["status"] = "choose"
|
| 218 |
game["challenge"]["challenger"] = assassin_player["name"]
|
| 219 |
return {"success": True, "message": f"Challenge successful. {assassin_player['name']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 220 |
elif response == "contessa":
|
| 221 |
+
# Target opts to block with Contessa. Shift phase.
|
| 222 |
game["challenge"]["phase"] = "assassin_contessa"
|
| 223 |
return {"success": True, "message": f"{game['challenge']['challenger']} must now choose to challenge or accept the Contessa."}
|
| 224 |
+
# Phase 2: assassin responding to contessa claim.
|
| 225 |
elif game["challenge"].get("phase") == "assassin_contessa":
|
| 226 |
if response == "accept":
|
| 227 |
+
# Assassin accepts contessa block: target loses one card.
|
| 228 |
game["challenge"]["status"] = "choose"
|
| 229 |
game["challenge"]["challenger"] = game["challenge"]["target"]
|
| 230 |
return {"success": True, "message": f"{game['challenge']['target']} must now choose a card to lose."}
|
| 231 |
elif response == "challenge":
|
| 232 |
+
# Assassin challenges contessa.
|
| 233 |
target_player = next(p for p in game["players"] if p["name"] == game["challenge"]["target"])
|
| 234 |
if "Contessa" in target_player["cards"]:
|
| 235 |
+
# Contessa is truthful: assassin loses one card.
|
| 236 |
game["challenge"]["status"] = "choose"
|
| 237 |
+
# Losing player is the assassin.
|
| 238 |
game["challenge"]["challenger"] = game["challenge"]["challenger"]
|
| 239 |
return {"success": True, "message": f"Contessa challenge successful. {game['challenge']['challenger']} must choose a card to lose.", "challenge": game["challenge"]}
|
| 240 |
else:
|
| 241 |
+
# Contessa is bluffing: target loses both cards.
|
| 242 |
target_player["cards"] = []
|
| 243 |
game["challenge"] = None
|
| 244 |
return {"success": True, "message": f"Contessa challenge failed. {target_player['name']} loses both cards."}
|
| 245 |
|
| 246 |
+
# --- Handle Foreign Aid responses ---
|
| 247 |
+
elif game["challenge"]["challengeType"] == "foreignAid":
|
| 248 |
+
if player == game["challenge"]["challenger"]:
|
| 249 |
+
return {"success": False, "message": "Challenger cannot respond to their own action."}
|
| 250 |
+
game["challenge"]["responses"][player] = response
|
| 251 |
+
if response == "block":
|
| 252 |
+
game["challenge"]["status"] = "blocked"
|
| 253 |
+
game["challenge"] = None
|
| 254 |
+
return {"success": True, "message": f"Foreign Aid blocked by {player}."}
|
| 255 |
+
else:
|
| 256 |
total_opponents = len(game["players"]) - 1
|
| 257 |
if len(game["challenge"]["responses"]) == total_opponents:
|
| 258 |
+
challenger_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 259 |
+
challenger_player["coins"] += 2
|
| 260 |
game["challenge"] = None
|
| 261 |
+
return {"success": True, "message": f"Foreign Aid accepted. {challenger_player['name']} gains 2 coins."}
|
| 262 |
else:
|
| 263 |
+
return {"success": True, "message": f"{player} allowed Foreign Aid. Awaiting other responses."}
|
| 264 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
if action == 'ambassador':
|
| 266 |
if game["turn"] != player:
|
| 267 |
return {"success": False, "message": "Not your turn."}
|
|
|
|
| 284 |
return {"success": False, "message": f"Card {target} not found in {acting_player['name']}'s hand."}
|
| 285 |
|
| 286 |
if action == 'income':
|
| 287 |
+
player_found = False
|
| 288 |
for p in game["players"]:
|
| 289 |
if p["name"] == player:
|
| 290 |
+
player_found = True
|
| 291 |
if not game["permissions"].get(player, {}).get("gain", True):
|
| 292 |
return {"success": False, "message": "You can only earn money once per turn."}
|
| 293 |
p["coins"] += 1
|
| 294 |
game["permissions"][player]["gain"] = False
|
| 295 |
return {"success": True, "message": f"You now have {p['coins']} coins."}
|
| 296 |
+
if not player_found:
|
| 297 |
raise HTTPException(status_code=404, detail="Player not found in the game.")
|
| 298 |
|
| 299 |
if action == 'foreignAid':
|