This script implements the Rock, Paper, Scissors game based on a protocol described here.
After following the root prerequisites, make sure to install the additional requirements:
uv sync --extra rpsSample out of Rock-Paper-Scissors extra packages being installed
$ uv sync --extra rps
> Resolved 30 packages in 0.36ms
> Installed 1 package in 1ms
> + python-dotenv==0.13.0The game can be played as either Alice or Bob, and you can specify your move (rock, paper, scissors). Additionally, other options like non-interactive mode and automatic mining can be set.
python examples/rps/rps.py --alice/--bob [--rock/--paper/--scissors] [--non-interactive] [--mine-automatically] [--host HOST] [--port PORT]Sample output of command with backend-image running
$ python examples/rps/rps.py --alice --rock --non-interactive --mine-automatically --host localhost --port 18443
> ...
> ...
> ...
> ...
> ...
$ python examples/rps/rps.py --bob --paper --non-interactive --mine-automatically --host localhost --port 18443
> ...
> ...
> ...
> ...
> ...In order to play a game, run python examples/rps/rps.py --alice on a shell,
and python examples/rps/rps.py --bob on a separate shell.
The two scripts will establish a socket to communicate and negotiate a game UTXO.
Once the UTXO is funded (NOTE: it must be funded externally), the two scripts proceed to play the game.
--alice/--bob: Specify the player you want to play as.--rock/--paper/--scissors: Specify your move. If ommitted, a random move is chosen.--non-interactive: Run in non-interactive mode (if not enabled, the user has to confirm each action).--mine-automatically: Enable automatic mining when transactions are broadcast.--host: Specify the host address (default islocalhost).--port: Specify the port number (default is12345).