🐐
This commit is contained in:
@@ -430,7 +430,10 @@ async def claim_timeout_win(game_id: str, user: UserModel = Depends(get_current_
|
||||
return {"message": "Win claimed"}
|
||||
|
||||
@app.post("/game/solo")
|
||||
async def start_solo_game(deck_id: str, user: UserModel = Depends(get_current_user), db: Session = Depends(get_db)):
|
||||
async def start_solo_game(deck_id: str, difficulty: int = 5, user: UserModel = Depends(get_current_user), db: Session = Depends(get_db)):
|
||||
if difficulty < 1 or difficulty > 10:
|
||||
raise HTTPException(status_code=400, detail="Difficulty must be between 1 and 10")
|
||||
|
||||
deck = db.query(DeckModel).filter(
|
||||
DeckModel.id == uuid.UUID(deck_id),
|
||||
DeckModel.user_id == user.id
|
||||
@@ -448,7 +451,7 @@ async def start_solo_game(deck_id: str, user: UserModel = Depends(get_current_us
|
||||
|
||||
ai_cards = db.query(CardModel).filter(
|
||||
CardModel.user_id == None
|
||||
).order_by(func.random()).limit(20).all()
|
||||
).order_by(func.random()).limit(100).all()
|
||||
|
||||
if len(ai_cards) < 20:
|
||||
raise HTTPException(status_code=503, detail="Not enough cards in pool for AI deck")
|
||||
@@ -458,7 +461,7 @@ async def start_solo_game(deck_id: str, user: UserModel = Depends(get_current_us
|
||||
|
||||
db.commit()
|
||||
|
||||
game_id = create_solo_game(str(user.id), user.username, player_cards, ai_cards, deck_id)
|
||||
game_id = create_solo_game(str(user.id), user.username, player_cards, ai_cards, deck_id, difficulty)
|
||||
|
||||
asyncio.create_task(fill_card_pool())
|
||||
|
||||
@@ -528,3 +531,33 @@ def refresh(req: RefreshRequest, db: Session = Depends(get_db)):
|
||||
"refresh_token": create_refresh_token(str(user.id)),
|
||||
"token_type": "bearer",
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
from ai import AIPersonality, choose_cards
|
||||
from card import generate_cards, Card
|
||||
from time import sleep
|
||||
|
||||
all_cards: list[Card] = []
|
||||
for i in range(30):
|
||||
print(i)
|
||||
all_cards += generate_cards(10)
|
||||
sleep(5)
|
||||
|
||||
all_cards.sort(key=lambda x: x.cost, reverse=True)
|
||||
|
||||
print(len(all_cards))
|
||||
def write_cards(cards: list[Card], file: str):
|
||||
with open(file, "w") as fp:
|
||||
fp.write('\n'.join([
|
||||
f"{c.name} - {c.attack}/{c.defense} - {c.cost}"
|
||||
for c in cards
|
||||
]))
|
||||
|
||||
write_cards(all_cards, "output/all.txt")
|
||||
|
||||
for personality in AIPersonality:
|
||||
print(personality.value)
|
||||
for difficulty in range(1,11):
|
||||
chosen_cards = choose_cards(all_cards, difficulty, personality)
|
||||
chosen_cards.sort(key=lambda x: x.cost, reverse=True)
|
||||
write_cards(chosen_cards, f"output/{personality.value}-{difficulty}.txt")
|
||||
|
||||
Reference in New Issue
Block a user