Advertisement
Guest User

rps

a guest
Oct 16th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #!/bin/bash
  2. echo "What will you choose? [rock/paper/scissors]"
  3. read response
  4. aiThought=$(echo $[ 1 + $[ RANDOM % 3 ]])
  5. case $aiThought in
  6. 1) aiResponse="rock" ;;
  7. 2) aiResponse="paper" ;;
  8. 3) aiResponse="scissors" ;;
  9. esac
  10. echo "AI - $aiResponse"
  11. responses="$response$aiResponse"
  12. case $responses in
  13. rockrock) isTie=1 ;;
  14. rockpaper) playerWon=0 ;;
  15. rockscissors) playerWon=1 ;;
  16. paperrock) playerWon=1 ;;
  17. paperpaper) isTie=1 ;;
  18. paperscissors) playerWon=0 ;;
  19. scissorsrock) playerWon=0 ;;
  20. scissorspaper) playerWon=1 ;;
  21. scissorsscissors) isTie=1 ;;
  22. esac
  23. if [[ $isTie == 1 ]] ; then echo "It's a tie!" && exit 1 ; fi
  24. if [[ $playerWon == 0 ]] ; then echo "Sorry, $aiResponse beats $response , try again.." && exit 1 ; fi
  25. if [[ $playerWon == 1 ]] ; then echo "Good job, $response beats $aiResponse!" && exit 1 ; fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement