AdditionalAssignment2018 2
AdditionalAssignment2018 2
1 Project Description
In this assignment there are 4 parts. For each part you should:
• Write the appropriate code.
• Include comments within the code to explain thewhatalgorithm.
the code does.
• Test the code to ensure its correctness.
• Format and stricture
structure the code to maximise its readability.
A report must be submitted containing a cover page, the solutions to each of the four parts, and your code, as
a PDF using the vUWS assignment submission page.
The cover page must contain your name, student number, unit number and name, and the declaration below.
Submission
Submissionis is
duedue
by Friday of weekMonday
by 11:59pm
11:59pm 12 using4th
Friday, the vUWS online
January
February system. Time)
25 (Sydney Late submissions
via emailwillto receive a 10%
Dr Barnes:
reduction in marks for each day late.
[email protected] . Late submissions will receive a 10% reduction in marks for each day late.
2 Marking Criteria
This assignment is worth 40% of the unit assessment tasks. There four problems to investigate and 10 marks
available for each of the four questions. The marking criteria for each question is given in Table 1.
When writing the solutions to each of the four parts, make sure to consult the marking criteria and check that
you have covered them. The project will be marked using this criteria.
Criteria Q1 Q2 Q3 Q4
Code Correctness (5 marks)
Comments explaining code (2 marks)
Code Testing (1 mark)
Code Style and Readability (2 marks)
Total (10 marks)
1
Batsman How Out Runs Balls 4s 6s SR
KL Rahul c Finch b Hazlewood 2 8 0 0 25.00
M Vijay c †Paine b Starc 11 22 1 0 50.00
CA Pujara run out (Cummins) 123 246 7 2 50.00
V Kohli (c) c Khawaja b Cummins 3 16 0 0 18.75
AM Rahane c Handscomb b Hazlewood 13 31 0 1 41.93
RG Sharma c Harris b Lyon 37 61 2 3 60.65
RR Pant † c †Paine b Lyon 25 38 2 1 65.78
R Ashwin c Handscomb b Cummins 25 76 1 0 32.89
I Sharma b Starc 4 20 1 0 20.00
Mohammed Shami c †Paine b Hazlewood 6 10 1 0 60.00
JJ Bumrah not out 0 0 0 0 -
3 Declaration
Before submitting the assignment, include the following declaration in a clearly visible and readable place on
the cover page of your project report.
Note: An examiner or lecturer/tutor has the right not to mark this project report if the above declaration has
not been added to the cover of the report.
4 Project �estions
The scorecard in Table 2 is from the �rst innings of the �rst cricket test in the Australia vs India 2018
series. http://www.espncricinfo.com/series/18693/scorecard/1144993/australia-vs-india-1st-test-india-in-aus-
2018-19
The columns show:
2
• Batsman: The name of the batsman.
• How Out: How the batsman was given out.
• Runs: The number of runs made by the batsman.
• Balls: The number of balls faced by the batsman.
• 4s: The number of 4s hit by the batsman.
• 6s: The number of 6s hit by the batsman.
• SR: The batsman’s strike rate (100*Runs/Balls).
Cricinfo believe that there is a bug in their code that computes the batsman’s strike rate (SR), and so they want
you to verify the numbers.
Write the code to:
1. Create a data frame in R containing the data from Table 2.
2. Compute the strike rate using the data frame from the Runs and Balls.
3. Subtract your computed strike rate from the data frame column SR.
Finally, state if your output shows errors in the data, and where the errors occur.
Cricinfo want to create a simple cricket simulator to test their scorecard and so have come to you for help.
After a ball is bowled, there are eight possible outcomes. Below we list the eight outcomes and each outcome’s
e�ect on the score:
• 0 runs: add 1 to the ball count
• 1 run: add 1 to the ball count, add 1 to the run count
• 2 runs: add 1 to the ball count, add 2 to the run count
• 4 runs: add 1 to the ball count, add 4 to the run count, add 1 to the 4s count
• 6 runs: add 1 to the ball count, add 6 to the run count, add 1 to the 6s count
• Wide: add 1 to the extras count
• No ball: add 1 to the extras count
• Out: add 1 to the ball count, mark batsman as out
Cricinfo store a batsman’s record using the variable:
state = list(balls = 0, runs = 0, fours = 0, sixes = 0, extras = 0, out = FALSE)
Write the function oneBall that takes the input state and one outcome and returns the updated state based
on the eight outcomes above.
A batsman keeps facing balls until the batsman is out. To simulate a single batsman, we need to:
1. Randomly sample one of the eight outcomes,
2. Update the score state,
3. Repeat until the outcome is Out.
3
Write the function oneBatsman that randomly samples one of the eight outcomes from above, updates the
score using your function oneBall, then repeats until the outcome is Out. Note that we can randomly sample
an outcome using:
outcome = sample(c("0 runs", "1 runs", "2 runs", "4 runs", "6 runs",
"Wide", "No Ball", "Out"), size = 1)
The �nal piece of the simulation is to simulate the score for the whole team, and compute the team score.
Write a function that contains the code to:
1. Simulate the scores for 10 batsmen (using the function oneBatsman).
2. Add the runs and extras from each batsman to obtain the team score.