Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -213,7 +213,7 @@ async def handle_action(request: Request):
|
|
| 213 |
total_opponents = len(game["players"]) - 1
|
| 214 |
if len(game["challenge"]["responses"]) == total_opponents:
|
| 215 |
ambassador_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 216 |
-
ambassador_player["cards"] = generate_cards()
|
| 217 |
game["challenge"] = None
|
| 218 |
return {"success": True, "message": f"Ambassador action accepted. {ambassador_player['name']} swaps cards with the deck."}
|
| 219 |
else:
|
|
@@ -224,7 +224,7 @@ async def handle_action(request: Request):
|
|
| 224 |
game["challenge"]["status"] = "choose"
|
| 225 |
game["challenge"]["challenger"] = player
|
| 226 |
game["challenge"]["target"] = ambassador_player["name"]
|
| 227 |
-
ambassador_player["cards"] = generate_cards()
|
| 228 |
game["challenge"] = None
|
| 229 |
return {"success": True, "message": f"Challenge failed. {player} must lose a card, while {ambassador_player['name']} swaps cards with the deck."}
|
| 230 |
else:
|
|
@@ -428,7 +428,7 @@ async def start_game(request: Request):
|
|
| 428 |
raise HTTPException(status_code=400, detail="No players in the game.")
|
| 429 |
|
| 430 |
# Initialize players with 2 coins and cards.
|
| 431 |
-
game["players"] = [{"name": name, "coins": 2, "cards": generate_cards()} for name in game["players"]]
|
| 432 |
# Reset permissions to a dictionary with proper keys for each player.
|
| 433 |
game["permissions"] = {player["name"]: {"steal": True, "gain": True} for player in game["players"]}
|
| 434 |
game["gameStarted"] = True
|
|
@@ -436,10 +436,13 @@ async def start_game(request: Request):
|
|
| 436 |
|
| 437 |
return {"success": True, "message": "Game started successfully!"}
|
| 438 |
|
| 439 |
-
def generate_cards():
|
| 440 |
cards = ['Duke', 'Assassin', 'Captain', 'Ambassador', 'Contessa']
|
| 441 |
shuffled = sorted(cards, key=lambda x: 0.5 - random.random())
|
| 442 |
-
|
|
|
|
|
|
|
|
|
|
| 443 |
|
| 444 |
if __name__ == "__main__":
|
| 445 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 213 |
total_opponents = len(game["players"]) - 1
|
| 214 |
if len(game["challenge"]["responses"]) == total_opponents:
|
| 215 |
ambassador_player = next(p for p in game["players"] if p["name"] == game["challenge"]["challenger"])
|
| 216 |
+
ambassador_player["cards"] = generate_cards(len(ambassador_player["cards"]))
|
| 217 |
game["challenge"] = None
|
| 218 |
return {"success": True, "message": f"Ambassador action accepted. {ambassador_player['name']} swaps cards with the deck."}
|
| 219 |
else:
|
|
|
|
| 224 |
game["challenge"]["status"] = "choose"
|
| 225 |
game["challenge"]["challenger"] = player
|
| 226 |
game["challenge"]["target"] = ambassador_player["name"]
|
| 227 |
+
ambassador_player["cards"] = generate_cards(len(ambassador_player["cards"]))
|
| 228 |
game["challenge"] = None
|
| 229 |
return {"success": True, "message": f"Challenge failed. {player} must lose a card, while {ambassador_player['name']} swaps cards with the deck."}
|
| 230 |
else:
|
|
|
|
| 428 |
raise HTTPException(status_code=400, detail="No players in the game.")
|
| 429 |
|
| 430 |
# Initialize players with 2 coins and cards.
|
| 431 |
+
game["players"] = [{"name": name, "coins": 2, "cards": generate_cards(2)} for name in game["players"]]
|
| 432 |
# Reset permissions to a dictionary with proper keys for each player.
|
| 433 |
game["permissions"] = {player["name"]: {"steal": True, "gain": True} for player in game["players"]}
|
| 434 |
game["gameStarted"] = True
|
|
|
|
| 436 |
|
| 437 |
return {"success": True, "message": "Game started successfully!"}
|
| 438 |
|
| 439 |
+
def generate_cards(numofcards):
|
| 440 |
cards = ['Duke', 'Assassin', 'Captain', 'Ambassador', 'Contessa']
|
| 441 |
shuffled = sorted(cards, key=lambda x: 0.5 - random.random())
|
| 442 |
+
if numofcards == 1:
|
| 443 |
+
return [shuffled[0]]
|
| 444 |
+
else:
|
| 445 |
+
return [shuffled[0], shuffled[1]]
|
| 446 |
|
| 447 |
if __name__ == "__main__":
|
| 448 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|