incognitolm commited on
Commit
c3f1705
·
verified ·
1 Parent(s): ff5dfe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -91,6 +91,10 @@ async def handle_action(request: Request):
91
 
92
  game = games[pin]
93
 
 
 
 
 
94
  if action == 'getStatus':
95
  check_game_status(game)
96
  return {"success": True, "challenge": game.get("challenge", None)}
@@ -448,10 +452,20 @@ if __name__ == "__main__":
448
  uvicorn.run(app, host="0.0.0.0", port=8000)
449
 
450
  def check_game_status(game):
451
- # Remove any players without cards.
452
- game["players"] = [p for p in game.get("players", []) if p.get("cards")]
453
-
454
- # Update permissions: If a player has more than 10 coins, flag them to coup.
 
 
 
 
 
 
 
 
 
 
455
  for p in game["players"]:
456
  name = p["name"]
457
  if p.get("coins", 0) > 10:
@@ -461,4 +475,4 @@ def check_game_status(game):
461
  else:
462
  if name in game.get("permissions", {}):
463
  game["permissions"][name].pop("mustCoup", None)
464
- return game
 
91
 
92
  game = games[pin]
93
 
94
+ # If a challenge is pending, only allow challengeResponse (or getStatus) actions.
95
+ if game.get("challenge") and action not in ['challengeResponse', 'getStatus']:
96
+ return {"success": False, "message": "A challenge is pending, only challenge responses are allowed."}
97
+
98
  if action == 'getStatus':
99
  check_game_status(game)
100
  return {"success": True, "challenge": game.get("challenge", None)}
 
452
  uvicorn.run(app, host="0.0.0.0", port=8000)
453
 
454
  def check_game_status(game):
455
+ # Filter active players (only those who still have cards)
456
+ active_players = [p for p in game.get("players", []) if p.get("cards")]
457
+
458
+ # If the current turn player is no longer in the active players, update turn to the next available player's name.
459
+ if not any(p["name"] == game.get("turn") for p in active_players):
460
+ if active_players:
461
+ game["turn"] = active_players[0]["name"]
462
+ else:
463
+ game["turn"] = None
464
+
465
+ # Update the game players to only the active players.
466
+ game["players"] = active_players
467
+
468
+ # Update permissions: Flag players with more than 10 coins to coup.
469
  for p in game["players"]:
470
  name = p["name"]
471
  if p.get("coins", 0) > 10:
 
475
  else:
476
  if name in game.get("permissions", {}):
477
  game["permissions"][name].pop("mustCoup", None)
478
+ return game