Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow specifying names of players #38

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions rps-sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

@click.command
@click.option("--games", default=3, type=click.IntRange(min=1, max=1000), help="Number of games to play")
def simple_sim(games: int) -> None:
player1 = BotPlayer(RandomPlayStrategy())
player2 = BotPlayer(RandomPlayStrategy())
@click.option("--p1-name", default="Player 1", help="Name of first player")
@click.option("--p2-name", default="Player 2", help="Name of second player")
def simple_sim(games: int, p1_name: str, p2_name: str) -> None:
player1 = BotPlayer(RandomPlayStrategy(), p1_name)
player2 = BotPlayer(RandomPlayStrategy(), p2_name)
results = play_games(player1, player2, games)

for result in results:
# Simple message with results
print("Result: Player 1", human_readable(result))
print("Result:", player1.name, human_readable(result))

print("Simulation finished.")

Expand Down
5 changes: 4 additions & 1 deletion rps/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@


class Player(object):
name: str

@abc.abstractmethod
def play(self) -> Play:
"""Required method"""


class BotPlayer(Player):
def __init__(self, play_strategy: PlaySelectionStrategy):
def __init__(self, play_strategy: PlaySelectionStrategy, name: str = "Bot Player"):
self.__strategy = play_strategy
self.name = name

def play(self) -> Play:
return self.__strategy.play()