Infinite-Deck Card Game
Frequency: Reported
Reported prompt and starter code
python
"""
Problem: Card Game Simulation
You are tasked with simulating a card game using object-oriented design principles.
There are initially two players, each drawing multiple cards per round from an infinite deck
(i.e., a deck that never runs out of cards). Each card has a numeric value.
After each round, the player with the highest card value wins the round.
The game continues until one player leads the other by at least 2 wins,
at which point that player is declared the champion.
Your goal is to design the classes and logic to simulate 100 games and determine the overall champion frequency for each player.
import random
from typing import List, Dict
class InfiniteDeck:
def __init__(self):
"""Initialize an infinite deck that can draw random cards."""
pass
def draw_card(self) -> int:
"""Return a random integer card value between 1 and 1000."""
pass
class CardGame:
def __init__(self, num_players: int = 2, cards_per_round: int = 1):
"""
Initialize the game with a given number of players and cards per round.
Each player will draw from the same InfiniteDeck.
"""
pass
def play_round(self) -> int:
"""
Simulate one round of the game.
Each player draws 'cards_per_round' cards.
Return the index of the player who wins the round.
"""
pass
def play_game(self) -> int:
"""
Simulate one complete game until a player leads by >= 2 wins.
Return the index of the champion.
"""
pass
def simulate(num_games: int = 100) -> Dict[int, int]:
"""
Run multiple games and count how many times each player wins overall.
Return a dictionary mapping player index to champion count.
"""
pass
if __name__ == "__main__":
print(simulate())As reported, the opening triple-quoted prompt string has no closing delimiter before the imports. No completed implementation was supplied.
Follow-ups
- Extend the simulation from two players to
nplayers. Make the player count dynamic and update win tracking so every round compares all players. - Introduce multiple infinite decks. Model either multiple
InfiniteDeckinstances or a shared deck carrying deck metadata, and explain how the design preserves fair and consistent draws across decks.