Shell Scripting- UNIX
We will be writing a script to calculate bowling scores
– For an explanation of how it’s done please go to…
http://bowling.about.com/od/rulesofthegame/a/bowlingscoring.htm
There are two pages to this web site. The explanation of the special 10th frame is on the 2nd page.
– Familiarize yourself with the game by going to…
http://en.wikipedia.org/wiki/Bowling
– To watch some bowlers bowl go to..
http://www.youtube.com/watch?v=EFJGWWcz4Yw
Each script is worth 10 points…DO THE EASY ONES FIRST!!!!
We have provided some hints in bold at the end of the script explanation.
In bowling…the object of the game is to knock down the most pins in 10 frames. A frame is a set of 10 pins.
If all pins are knocked down with the first ball thrown in a frame, it is considered a strike which is symbolized by an “X” symbol.
If all pins are not knocked down with the first ball, the bowler can bowl again to try to knock down the remaining pins with a second ball. If the bowler knocks the remaining pins down, then it is considered a “spare” symbolized by the “/” symbol.
The number of pins knocked down by a bowler with each ball must be captured, because they are used to tally the scores in previous frames.
If a bowler gets a strike the next two balls he bowls are counted in the frame in which he got the strike, regardless if those balls are in the next frame or the next two frames )if he throws a second strike after the first).
If a bowler gets a spare the next ball only is counted in the frame in which he got the spare. That ball’s score is also counted in its own frame.
In the tenth frame a bowler can bowl up to three times. If he gets a strike in the first ball in the tenth, he may bowl two more times. If he bowls two strikes in the first two balls of the tenth frame or he gets a spare after the second ball of the tenth frame, he may bowl one more ball. If the bowler does not have a strike or spare after the second ball of the tenth frame then his game is over.
- (SC1) Write a shell script that accepts the name of a bowler on the command line. If the bowler does not put the name on the command line, your script should ask him for it. Once the name has been entered (either from the command line or interactively), the name is echoed back to the screen. [command line variables, echo, if, ]
- (SC2) Amend script 1 to give an error message if no name is given on the command line or interactively. The error message should have a “ usage” suggestion [if]
- (SC3) Amend Script 2 to prevent the user from not entering a name. The script should insist that a name is entered. [while]
- (SC4) Amend Script 3 to prevent the user for exiting the script before a name is entered via standard interrupts [trap].
- (SC5) Create another script that accepts scores from the one or two balls thrown and reports back to you the result of that that frame. The script should do data checking to make sure that the numbers entered are valid [0-9] and do not add up to more than 10. The script can also accept an “X” or “x” to indicate the bowler has thrown a strike (only on the first ball) . If after two balls the bowler’s score adds up to 10 then the script should report back that you rolled a “spare” or “/” [let]
- (SC6) Amend script 5 to allow the process in script 5 to happen 9 times sequentially. Capture a cumulative score of each frame and report it to the user as he bowls.[while, function, variable array]
- (SC7) Amend Script 6 to now capture the first 9 frames score in full accordance with the rules of bowling. You must now account for the special rules for spares and strikes. Please see my explanation above…
- (SC8) Amend Script 7 and add a 10thframe function to allow for up to 3 balls to be thrown in a special 10th frame handler. Please see my explanation of the 10thframe above….
- (SC9) Amend the script 8 to eliminate the alphanumeric input and present the user with a menu of choices for frames 1-9 and the 10thframe. Remember, you menu choices may change depending if you are throwing the 1st, 2nd or (in the 10th frame) 3rd ball. [select]
- (SC10) Combine Script 4 and script 9 for an interactive scoring session that captures a bowler’s name, and each of his rolls and then computes his final score. Please then add a function to redirect the score to a file call bowler.txt so we can look up the scores later on. bowler.txt should have the name in column 1, the date in column 2 (please use the “date” command to retrieve today’s date) followed by 21 columns each representing the score for each ball thrown with the final score in the 23rdcolumn. All data should be separated by a [Tab] [redirect]
- [EXTRA CREDIT – 5 points each]
write a nawk script or command that will find the bowler with the most strikes from bowlers.txt.
write a nawk script or command that will find the bowler with the best average from bowlers.txt
Do you have unix shell scripting code for this project/