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-0.1.4.tar.gz (3.0 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-0.1.4-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file ping_game_theory-0.1.4.tar.gz.

File metadata

  • Download URL: ping_game_theory-0.1.4.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for ping_game_theory-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c983053bebf6acb6a948a1561113b70ed2d97e227b813fc06ac4ab91d22bd2e5
MD5 c3d2b6440e35889185033675fa861462
BLAKE2b-256 08bb367afdb397a54207a582afa21765cdd3cb6a38f01b0a05d8bf7b6b920ad3

See more details on using hashes here.

File details

Details for the file ping_game_theory-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ping_game_theory-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9fb692d6ab2ea0eafad5a37ce5c89014d3c452bc68c6453cf2ec16828c0cda24
MD5 15c918c9b4ea85175b9f78527a675040
BLAKE2b-256 98234924b2168319617797d526b81365271c499e4e1c41ec99db5fef8d7597e5

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