Question
You need to write a shell script named stick which plays a matchstick-picking game. Given an initial number of sticks, players take turns picking either
You need to write a shell script named stick which plays a matchstick-picking game. Given an initial number of sticks, players take turns picking either 1, 2 or 3 sticks from a pile. Whoever picks the last stick wins.
Usage
You run stick with a single command line argument, which you can assume will be a positive integer, e.g. stick 15 would play a game with 15 sticks. If no number is given, ask the user to enter one. Your program makes the first pick, and then asks the user how many sticks they wish to pick. Play continues until there are no sticks left, at which point your program announces who won. You must show the set of sticks after each player's move. Show this as a set of pipes (|) side by side, followed by the number of sticks in (parenthesis).
Illegal Moves
You may assume the user enters an integer number of sticks, but you must make sure their entry is either 1, 2 or 3. If the user enters an illegal number, you should explain that that is illegal, and give them one more chance. If they enter another illegal number, announce that they have forfeited the game, and the program should exit. If the user entered a valid number the second try, gameplay continue. In this case, if later the user again enters an illegal number, you should again given them a second chance).
Algorithm Your algorithm for picking sticks is simple: given n remaining sticks, pick (n mod 4) sticks, unless (n mod 4)=0; in that case, pick 1 stick.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started