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.3.tar.gz (2.7 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.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ping_game_theory_25-0.1.3.tar.gz
Algorithm Hash digest
SHA256 44dfbf6df21b710f54d11623a9c8aab727f8f5170781ab3f9fe4949d1f5cee42
MD5 8c96ca16f3267e826ac6a794b4941bb5
BLAKE2b-256 0f4fc8ff4bce4841ff76d5235587f33d39153dfbaa54b307765ff7a588921caa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ping_game_theory_25-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dda7e017546589492b2056d10e008d74098898059404f851ccdc588693be2d84
MD5 1f4b60797c93a0713020cbee05a2003a
BLAKE2b-256 c778aa5f2e44ae4b8a67dcdd4717e8e47e4687365168d90c1b6d53954857689a

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