Skip to content

Commit

Permalink
feat: allow specifying names of players
Browse files Browse the repository at this point in the history
We allow specifying both, though for now only Player 1's name is shown.
  • Loading branch information
AndrewADev committed Aug 13, 2023
1 parent f0f4784 commit ad300ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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()

0 comments on commit ad300ef

Please sign in to comment.