@lucadv/rock-paper-scissors

1.1.0 • Public • Published

Overview

A module to play Rock, Paper, Scissors game. Given Player 1 and Player 2 moves the module will decide who wins.

Usage

Call RPS with the 2 moves (if the second move is not passed one will be generated randomly) and you'll be returned with an object containing the following properties:

  • winner: the winner of the game if there is one (could be tie), either player 1 or `player 2``
  • tie: true if the 2 players played the same shape (e.g. rock vs rock). This field is mutually exclusive with winner
  • message: the result message of the game (e.g. paper beats rock)
  • moves: an object representing the moves of player 1 and player 2

Install @lucadv/rock-paper-scissors:

npm install --save @lucadv/rock-paper-scissors

Then use it like this:

const RPS = require('@lucadv/rock-paper-scissors');

const player1Move = 'rock';
const player2Move = 'paper';

const result = RPS(player1Move, player2Move); 
// { winner: 'player2', message: 'paper beats rock', moves: { player1: 'rock', 'player2': 'paper' } }

Readme

Keywords

Package Sidebar

Install

npm i @lucadv/rock-paper-scissors

Weekly Downloads

3

Version

1.1.0

License

ISC

Unpacked Size

11.1 kB

Total Files

8

Last publish

Collaborators

  • lucadv