Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THE FOLLOWING PROGRAM SHOULD ONLY BE WRITTEN IN PHP. Create a game \"Rock, Paper

ID: 3708797 • Letter: T

Question

THE FOLLOWING PROGRAM SHOULD ONLY BE WRITTEN IN PHP.

Create a game "Rock, Paper, Scissors, Lizard, Spock" or RPSLS for short.

Two players have five choices to pick from, resulting in 25 unique combinations that must be evaluated.

Both players hand's must be chosen randomly by the program.

ALL rules (the 25 permutations) must be implemented and your code must calculate.

The output of your program must include the item picked by both players as well as the calculated winner.

Scissors cuts Paper
    Paper covers Rock
    Rock crushes Lizard
    Lizard poisons Spock
    Spock smashes Scissors
    Scissors decapitates Lizard
    Lizard eats Paper
    Paper disproves Spock
    Spock vaporizes Rock
    (and as it always has) Rock crushes scissors

Explanation / Answer

<?php
$p1=mt_rand(0,4);
$p2=mt_rand(0,4);
$choice = array("Rock", "Paper", "Scissor", "Lizard", "Spock");
echo "Player1 picked ".$choice[$p1].". ";
echo "Player2 picked ".$choice[$p2].". ";
if( ($p1==0 && $p2==0) || ($p1==1 && $p2==1) || ($p1==2 && $p2==2) || ($p1==3 && $p2==3) || ($p1==4 && $p2==4) )
   echo "Game Draw as both players picked same. ";
elseif ( ($p1==   2 && $p2==1) || ($p1==1 && $p2==0) || ($p1==0 && $p2==3) || ($p1==3 && $p2==4) || ($p1==4 && $p2==2) || ($p1==2 && $p2==3) || ($p1==3 && $p2==1) || ($p1==1 && $p2==4) || ($p1==4 && $p2==0) || ($p1==0 && $p2==2) )
   echo "Player 1 wins. ";
else
   echo "Player 2 wins. ";