Skip to content

Commit

Permalink
feat: allow specifying number of games via arg
Browse files Browse the repository at this point in the history
Leverage click (already a dependency) to accept a command line argument for specifying the number of games to play.
  • Loading branch information
AndrewADev committed Aug 13, 2023
1 parent 5f9617f commit 6bb0e96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Once installed, you should be able to run it with:
$ python ./rps-sim.py
```

You can specify the number of games that should be played via the `--games` argument, e.g.:
```shell
$ python ./rps-sim.py --games 7
```
Run `python ./rps-sim.py --help` for a complete list of options

## Tests

Assuming you have an active `pipenv` shell:
Expand Down
22 changes: 15 additions & 7 deletions rps-sim.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import click
from rps.player import BotPlayer
from rps.play import human_readable
from rps.strategy import RandomPlayStrategy
from rps.game import play_games


player1 = BotPlayer(RandomPlayStrategy())
player2 = BotPlayer(RandomPlayStrategy())
results = play_games(player1, player2, 3)

# Hard-coded, simple demonstration of a play-through
for result in results:
print("Result: Player 1...", human_readable(result))
@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())
results = play_games(player1, player2, games)

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

print("Simulation finished.")
print("Simulation finished.")


if __name__ == '__main__':
simple_sim()

0 comments on commit 6bb0e96

Please sign in to comment.