Skip to main content

Driver Code for @ping/game-theory-25

Project description

This package contains simple driver code + testing functionality for @ping/game-theory-25

Types

Move (Enum)

class Move(StrEnum):
    ROCK = "ROCK"
    PAPER = "PAPER"
    SCISSOR = "SCISSOR"

Represents a single move in the game.

HistoryEntry (Dataclass)

@dataclass
class HistoryEntry:
    self: Move
    other: Move

Represents the result of one round of play between two strategies.

Field Type Meaning
self Move The move played by this strategy
other Move The move played by the opponent

History (Type Alias)

History = Tuple[HistoryEntry, ...]

A read-only sequence of all previous rounds. Each element is a HistoryEntry. The most recent round is at the end of the tuple.

Strategy (Abstract Base Class)

class Strategy(ABC):
    @abstractmethod
    def begin(self) -> Move:
        ...

    @abstractmethod
    def turn(self, history: History) -> Move:
        ...

Base class for all strategies (bots). Every strategy must implement two methods:

Method Called When Purpose
begin() Before the first round Returns the first move
turn(history) Every round after the first Returns the next move based on previous history

Any class that does not implement both methods cannot be instantiated.

Example Strategy

class ILoveRocks(Strategy):
    def __init__(self) -> None:
        self.author_netid = "lm742"
        self.strategy_name = "ILoveRocks"
        self.strategy_desc = "I really love rocks"

    def begin(self) -> Move:
        return Move.ROCK

    def turn(self, history: History) -> Move:
        return Move.ROCK

Strategy Tester

To ensure every strategy follows the required interface and runs efficiently, the project includes a built-in tester: StrategyTester

The tester automatically checks:

Check What it verifies
Initialization Your strategy's __init__ runs without errors
Return types begin() and turn() must always return a valid Move
No exceptions Your strategy must never crash during play
Performance Must complete 10,000 rounds within 60 seconds

If your strategy passess all checks, you will see:

 PASS: 10000 rounds in X.XX seconds

How to Test your Strategy

You must pass in your strategy class without instantiating it

if __name__ == "__main__":
    tester = StrategyTester(ILoveRocks)
    tester.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ping_game_theory_25-0.1.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ping_game_theory_25-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file ping_game_theory_25-0.1.2.tar.gz.

File metadata

  • Download URL: ping_game_theory_25-0.1.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for ping_game_theory_25-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d42e87aa9e51f2fe41ff937efe0af1e2fabe007420c4a52bf13ada34fa68e059
MD5 b8c91c5591be22131a9d5a0dfa2d5f27
BLAKE2b-256 2bd9c5cc7faacc782e0e35449878fe2fa03ed4fb81697e461b6db9d2d58b404f

See more details on using hashes here.

File details

Details for the file ping_game_theory_25-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ping_game_theory_25-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e21e4c5ec6d8f67ce6ad56862db8d065b14513b8daa428fdbc322db840b79920
MD5 d4ba8073207322216c83998e12f5cfce
BLAKE2b-256 39e85f19b3ae030e8507603d988b68419af61ab1b52e27f553662e975f0bf424

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page