Skip to content

Instantly share code, notes, and snippets.

@YavorK
Last active January 1, 2020 14:46
Show Gist options
  • Save YavorK/e3698ea960d406f2f7579a233d8e0708 to your computer and use it in GitHub Desktop.
Save YavorK/e3698ea960d406f2f7579a233d8e0708 to your computer and use it in GitHub Desktop.
<?php
$combos = [
'paper' => [
'vs_rock' => 'wins',
'vs_scissors' => 'loses',
],
'rock' => [
'vs_paper' => 'loses',
'vs_scissors' => 'wins',
],
'scissors' => [
'vs_rock' => 'loses',
'vs_paper' => 'wins',
]
];
function getRandom(){
$random = mt_rand(1, 3);
if ($random == 1){
return 'rock';
}
if ($random == 2){
return 'paper';
}
if ($random == 3){
return 'scissors';
}
}
$player = getRandom();
echo "Player chose $player. \n\r";
$computer = getRandom();
echo "Compter chose $computer. \n\r";
if($player == $computer) {
echo "Player and Computer are even.";
}
echo "Player ". $combos[$player]['vs_'.$computer]." \n\r";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment