Guest User

Untitled

a guest
May 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ $# < 2 ]]; then
  4. echo "Wrong args amount"
  5. exit 1
  6. fi
  7.  
  8. if [[ $2 < 1 ]]; then
  9. echo "S lower than 1"
  10. exit 1
  11. fi
  12.  
  13. if [[ $2 > $1 ]]; then
  14. echo "S greater than N"
  15. exit 1
  16. fi
  17.  
  18. counter=0
  19. n=$1
  20.  
  21. while [ $licznik -lt $n ]
  22. do
  23. tab[$licznik]=_
  24. let "counter++"
  25. done
  26.  
  27. s=$2
  28.  
  29. while [ $s -gt 0 ]
  30. do
  31. a=$((RANDOM % ($1-0+1) + 0))
  32. if [[ ${tab[$a]} == _ ]]; then
  33. tab[$a]="X"
  34. let 's--'
  35. fi
  36. done
  37.  
  38. hits=0
  39. moves=0
  40.  
  41. while [ $hits -lt $2 ]
  42. do
  43. echo "Your move"
  44. read choice
  45. if [[ ${tab[$choice]} == "X" ]]; then
  46. echo "HIT"
  47. let 'hits++'
  48. else
  49. echo "Miss"
  50. fi
  51. let 'moves++'
  52. done
  53.  
  54. echo "Result: "$2"/"$moves
Add Comment
Please, Sign In to add comment