@nickgraffis/roshambo

1.0.2Β β€’Β PublicΒ β€’Β Published

Roshambo

Rock πŸ—Ώ, Paper πŸ“„, Scissors βœ‚!

Demo

~> npm install -g @nickgraffis/roshambo
~> roshambo

Game Play

You can play Rock, Paper, Scissors!

How it works?

At the heart, it accepts two responses. One from player a and one from player b. It assigns the response a numeric value: //rock = 0, paper = 1, scissors = 2 It then computes ((player a - player b) + total_options(3)) % 3. If the answer is 1, player a wins, if not, player b wins. If the numbers are equal, it is a tie.

function rockPaperScissors (playerA, playerB) {
  var options = ['rock', 'paper', 'scissors'];
  var a = options.indexOf(playerA);
  var b = options.indexOf(playerB);
  if (a == b) {
    return 2;
  } else if (((a - b) + 3) % 3 == 1) {
    return 0;
  } else {
    return 1;
  }
}

Have Fun!

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @nickgraffis/roshambo

      Weekly Downloads

      0

      Version

      1.0.2

      License

      MIT

      Unpacked Size

      55.3 kB

      Total Files

      5

      Last publish

      Collaborators

      • nickgraffis