fork(2) download
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title></title>
  11. </head>
  12. <body>
  13. <?php
  14. //Присваиваем числа
  15. function number_to_name($number){
  16. if(0 == $number) {return "rock";}
  17. else if (1 == $number){return "Spock";}
  18. else if (2 == $number){return "paper";}
  19. else if (3 == $number){return "lizard";}
  20. else if (4 == $number){return "scissors";}
  21. else {return "Error number";}
  22. }
  23. //Присваиваем имена
  24. function name_to_number($name){
  25. if("rock" === $name) {return 0;}
  26. else if ("Spock" === $name){return 1;}
  27. else if ("paper" === $name){return 2;}
  28. else if ("lizard" === $name){return 3;}
  29. else if ("scissors" === $name){return 4;}
  30. else {return "Error unit";}
  31. }
  32. //Составляем правила
  33. function rpsls($name){
  34. $player_number = name_to_number($name);
  35. $comp_number = rand(0,4);
  36. $difference =($player_number - $comp_number);
  37. if ($difference == 0){
  38. $results='Player and computer tie!';
  39. }
  40. else if($difference >= 3){
  41. $results='Computer wins!';
  42. }
  43. else if($difference <= 2){
  44. $results='Player wins!';
  45. }
  46. $comp_name = number_to_name($comp_number);
  47. print("Player chooses ".$name.'<br/>');
  48. print("Computer chooses ".$comp_name.'<br/>');
  49. print($results.'<br/><br/>');
  50. }
  51.  
  52. rpsls("rock") ;
  53. rpsls("Spock") ;
  54. rpsls("paper") ;
  55. rpsls("lizard") ;
  56. rpsls("scissors") ;
  57. ?>
  58. </body>
  59. </html>
  60.  
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        Player chooses rock<br/>Computer chooses lizard<br/>Player wins!<br/><br/>Player chooses Spock<br/>Computer chooses paper<br/>Player wins!<br/><br/>Player chooses paper<br/>Computer chooses rock<br/>Player wins!<br/><br/>Player chooses lizard<br/>Computer chooses rock<br/>Computer wins!<br/><br/>Player chooses scissors<br/>Computer chooses Spock<br/>Computer wins!<br/><br/>    </body>
</html>