Hi 🤗
You may have been asked to solve this assignment in a specific language, but beyond that you are completely free to use whatever frameworks and libraries you like. We look forward to seeing what you choose!
We expect you to spend about 3–6 hours on the assignment, and that the solution ends up at about 200–500 lines of code, depending on language and approach. This is not a requirement, just a rough guide to the expected scope.
Regardless of language, we care about code quality, and we hope you do too! We also hope you give this code the same care you would give production code.
If there is something you would have liked to do but didn't have time for, tell us about it in README.md. That way we can give you some bonus points for it anyway!
The assignment
Uncle Rolf has challenged you to a round, and you have decided to keep an honest scorecard for both of you.
You are going to build a golf game for two players, you and Uncle Rolf. The course and the shots are fetched from separate endpoints.
Rules
- The course is played hole by hole, in the order the holes come from the endpoint.
- On each hole, you finish the hole first, and then Rolf finishes the hole.
- The ball starts at the tee, and the distance to the hole is the hole's
length. - The type of shot you play depends on how far you are from the hole:
Distance to the hole Shot type More than 150 m Long shot From 20 m up to and including 150 m Approach shot Less than 20 m Putt - A shot uses the next value from the list for that shot type. The new distance to the hole is the distance before the shot minus the length of the shot. If you hit past the hole, the new distance is how far you overshot. Example: If you are 10 metres from the hole and putt 12 metres, you are 2 metres from the hole.
- If the distance becomes 0, the ball is in the hole. 🎉 If this happens on the first shot, it's a hole-in-one.
- If the distance becomes 3 metres or less, you get a "gimme": add one stroke for the putt, and the ball is in the hole.
- If you have used twice as many strokes as the hole's par without getting the ball in the hole, you pick up the ball. Your score on the hole is then double par.
- The player with the fewest strokes in total after all holes wins. An equal number of strokes is a draw.
- If a player needs a shot of a type whose list has run out before the round is finished, the rain has arrived. ☔ Only the holes that both players have finished count.
Uncle Rolf's scorecard
Rolf keeps his own scorecard, and he has one fixed rule:
On holes where Rolf uses more strokes than par, he writes down one stroke fewer than he actually used.
"The first one was just a practice swing."
Rolf's scorecard is not used to decide who wins, but the program must show what Rolf claims.
The course
The course is available at https://golf.trainops.net/course.
holesis a list of holes.- Each hole has the fields
number,par(3, 4 or 5) andlength(in metres). - A course has between 1 and 18 holes.
Example
{
"name": "Greenhill Golf Club",
"holes": [
{ "number": 1, "par": 3, "length": 150 },
{ "number": 2, "par": 4, "length": 340 },
{ "number": 3, "par": 5, "length": 480 }
]
}
The shots
The shots are available at https://golf.trainops.net/shots.
- There is one list per shot type:
long,approachandputts. - The order within each list is given. The shots in a list must be used in the order they come, by both players.
- Each list contains up to 100 shots.
- Each shot is a length in whole metres:
List Length long150–200 m approach20–120 m putts1–20 m
Example
{
"long": [190, 175, 160, 200],
"approach": [118, 30, 120, 25, 95, 60],
"putts": [4, 12, 7, 2, 18]
}
Requirements
- The solution must include tests.
- The solution must use a build tool.
- The game must be playable from the command line.
- The solution must fetch the course and the shots from the endpoints above.
- It must be possible to change the endpoints and restart the game without rebuilding.
- It is sufficient for the solution to write to standard output (for example
System.outorconsole.log). README.mdmust explain how to run the app locally.- The program must print the shots on each hole, a scorecard and who won.
- The program must also print what Rolf claims the result was.
Example output
Hole 1 (par 3, 150 m)
Joakim: 150 → 32 → 2, gimme ⛳ 3 strokes
Rolf: 150 → 30 → 5 → 1, gimme ⛳ 4 strokes (writes down 3 🙄)
...
Scorecard | 1 | 2 | 3 | Total
Joakim | 3 | 5 | 5 | 13
Rolf | 4 | 5 | 6 | 15
Rolf claims | 3 | 4 | 5 | 12
🏆 Joakim wins with 13 strokes against Rolf's 15.
🙄 According to Rolf, he won 12–13.
Delivery
- The assignment must be delivered as a URL to a version-controlled repository, for example on GitHub.
- The repository must not be publicly available. It should only be shared with agreed-upon people at our company. You will receive this information by email.
- On GitHub, you give us access under the Collaborators setting.