CoolFace
Apppublic

matiqorb/spades-agent-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
simulate.py46 linesDownload Raw Back to spades_engine
1from __future__ import annotations2 3from typing import Dict, List4 5from .bots import BaseBot6from .engine import SpadesGame7 8 9def play_hand(game: SpadesGame, bots: Dict[int, BaseBot]) -> None:10    game.reset_hand()11    while game.phase == "bidding":12        p = game.current_player13        game.place_bid(p, bots[p].choose_bid(game, p))14    while game.phase == "playing":15        p = game.current_player16        game.play_card(p, bots[p].choose_card(game, p))17 18 19def play_match(bots: Dict[int, BaseBot], seed: int, target_score: int = 500, max_hands: int = 40) -> Dict:20    game = SpadesGame(seed=seed)21    for hand in range(max_hands):22        game.reset_hand(seed + hand)23        while game.phase == "bidding":24            p = game.current_player25            game.place_bid(p, bots[p].choose_bid(game, p))26        while game.phase == "playing":27            p = game.current_player28            game.play_card(p, bots[p].choose_card(game, p))29        winner = game.game_winner(target_score=target_score)30        if winner is not None:31            return {32                "winner_team": winner,33                "scores": game.scores[:],34                "hands_played": hand + 1,35            }36    winner_team = 0 if game.scores[0] >= game.scores[1] else 137    return {38        "winner_team": winner_team,39        "scores": game.scores[:],40        "hands_played": max_hands,41    }42 43 44def rotate_bot_pool(pool: List[BaseBot], seat0_bot: BaseBot) -> Dict[int, BaseBot]:45    return {0: seat0_bot, 1: pool[0], 2: pool[1], 3: pool[2]}46