A PHP class implementation of Rock Paper Scissors Spock Lizard as created by Sam Kass and Karen Bryla and popularized by "Big Bang Theory."
Add as many players (or bots) as you want. Then play them all against each other at the same time!
Packagist can be found here: jarrett/rockpaperscissorsspocklizard
Install via composer:
composer install jarrett/rockpaperscissorsspocklizard
and require composer autoloader
require 'vendor/autoload.php';
use Jarrett\RockPaperScissorsSpockLizard;
use Jarrett\RockPaperScissorsSpockLizard\Player;
// ...
$player = new Player();
$player->move('rock');
$bot = new Player();
$bot->isBot(true);
$game = new RockPaperScissorsSpockLizard();
$game->addPlayers($player, $bot)
->play();
$outcome = $game->getOutcomes();
use Jarrett\RockPaperScissorsSpockLizard;
use Jarrett\RockPaperScissorsSpockLizard\Player;
// ...
$player1 = new Player();
$player1->move('rock');
$player2 = new Player();
$player2->move('scissors');
$game = new RockpaperScissorsSpockLizard();
$game->setRounds(3)
->addPlayers($player1, $player2);
->play();
$outcome = $this->getOutcomes()
use Jarrett\RockPaperScissorsSpockLizard;
use Jarrett\RockPaperScissorsSpockLizard\Player;
// ...
// human
$player1 = new Player();
$player1->move('rock');
// human
$player2 = new Player();
$player2->move('paper');
// and 3 bots
$player3 = new Player();
$player4 = new Player();
$player5 = new Player();
$game = new RockpaperScissorsSpockLizard();
$game->addPlayers($player1, $player2, $player3, $player4, $player5)
->play();
// returns an array containing all wins, ties, and losses
$outcomes = $this->getOutcomes()
... or just throw the player instantiation directly into the addPlayers() method
$game = new RockpaperScissorsSpockLizard();
$game->addPlayers($player1, $player2, (new Player), (new Player), (new Player))
->play();
Set your move
Set player name. Can also be passed via the constructor. Generic "Player 1, 2, 3" will be used if name is empty.
Get player name.
Get player's move history
Get player's last move
Play the round
Restarts the game
Set the number of rounds for this game. Default is 1 if not specified.
- The maximum number of rounds before a winner is chosen
- If true, don't allow the number of rounds to change for this game
- If false (default), the maximum number of rounds can be changed during the game, even after a winner is determined.
Returns all round results.
Returns last round outcome.
Add player to the game.
Add multiple players to the game.
Return players for game.
Returns the number of players playing
Returns the player who won the last round.
Returns the outcomes for all players.
Returns the player who won the game.