15
1
If you haven't played golf before, here's a list of golf-related terms I use in this question
- Shot, also called a stroke: Every time the ball is hit, this is a shot.
- Hole: A golf course is split into holes, in which the goal is to hit a ball from one designated location to another in as few shots as possible.
- Tee: Where you start a hole.
- Pin or Flag: Where you finish a hole
- Fairway, Rough, Water, and Green: Features on a golf course that affect how one plays the ball in real life. (How they affect the program is specified below)
I'm going out to play golf tomorrow, and I find that sometimes, I have trouble figuring out what club to use to hit a certain yardage. So I decided to write down my clubs and their yardages per shot.
First Assumption: All holes are due north of their tee boxes.
All of these yardages measure the possibilities for how far north the ball travels. The ball will travel a random integer distance between the bounds specified for each club (inclusive).
As a master golfer, none of my shots have any horizontal shift. This means that all of my shots go in a straight line directly at the flag.
Club # Club Yardage
1 Driver 300-330
2 3-Wood 270-299
3 5-Wood 240-269
4 3-Iron 220-239
5 4-Iron 200-219
6 5-Iron 180-199
7 6-Iron 160-179
8 7-Iron 140-159
9 8-Iron 120-139
10 9-Iron 100-119
11 P-Wedge 80-99
12 S-Wedge 50-79
13 L-Wedge 0-49
14 Putter (only on green)
As a person who enjoys programming, I decide that I want to model a round of golf and set a goal for how well I want to do tomorrow. However, like any amateur programmer, after ten minutes, I gave up and asked for help on Stack Overflow (just kidding). Here are some more data about the course.
Second Assumption: Hole Geography
All numbers that describe distances on the course are integers.
Each hole is a straight line. The straight line distance between each hole and the pin (the end of the hole) is
Length
.Fairways are segments with length defined by
flen
. The value listed forflen
is the range of yardages north from the tee where fairway is.Water hazards are segments that have length defined by
wlen
, which has the same properties asflen
.The green has a length defined by
glen
.All parts of the course that are not fairway, water, or green are rough.
Here is a chart describing each hole on the course.
Hole # Length flen wlen glen
1 401 54-390 391-425
2 171 1-165 166-179
3 438 41-392 393-420 421-445
4 553 30-281,354-549 282-353 550-589
5 389 48-372 373-404
6 133 125-138
7 496 37-413 414-484 484-502
8 415 50-391 392-420
9 320 23-258 259-303 304-327
How to play Golf (for this program)
- Always aim exactly at the flag.
- Hit the ball as close to the pin as possible, trying to keep the ball on the fairway or (preferably) on the green.
- When you land a shot in the water, your next shot must be played from the same place as the shot that went into the water.
- Once the ball lands on the green, only the putter can be used. If the ball lands strictly more than 5 yards from the pin, then I putt twice. Otherwise, I putt once.
- It is possible to hit a shot past the pin.
Scoring
My score on a hole is the number of shots I take, plus one stroke for every time I land in rough or the water.
The program
Okay, that was a lot of rules, now let's talk about the program.
The course should be defined as above in the program, because the course is constant. Different golfers, however, have different distances for each shot, so the input to STDIN should be a set of ranges of yardages, arranged in increasing order of club number and separated by commas (with no whitespace).
The output should be how I "play" the round of golf. The hold number should be specified at the beginning of each line as Hole #:
where #
is the current hole. Each shot that is not a putt is of the following form: {club,distance of shot,condition of ball,distance to pin}
. The details of the shot should be separated by commas but no whitespace in the above order. The shots themselves should be written in order of how they are played and separated by a space. Once the ball lands on the green, the program should print how many putts I take, in the format {# putts}
. At the end of each line, the number of shots I took on the hole should be separated from the other shots by a space and printed as (#)
. Each hole should be on its own line and written in order. Finally, on the last (tenth) line of the program, the total number of shots for the round should be printed as Total: # shots
.
There is no set "strategy" that your program is required to take. You can write a program with any strategy you want. Example strategies include maximizing the percent chance of landing on the green and maximizing the distance of each shot until reaching the hole.
SAMPLE INPUT
300-330,270-299,240-269,220-239,200-219,180-199,160-179,140-159,120-139,100-119,80-99,50-79,0-49
SAMPLE OUTPUT
Hole 1: {Driver,324,Fairway,77} {S-Wedge,70,Green,7} {Two putts} (4)
Hole 2: {6-Iron,162,Water,171} {6-Iron,168,Green,3} {One putt} (4)
Hole 3: {Driver,301,Fairway,137} {8-Iron,131,Green,6} {Two putts} (4)
Hole 4: {3-Wood,288,Water,553} {3-Wood,276,Fairway,277} {3-Wood,291,Green,14} {Two putts} (6)
Hole 5: {Driver,322,Fairway,67} {S-Wedge,62} {One putt} (3)
Hole 6: {8-Iron,120,Rough,18} {L-Wedge,10,Green,8} {Two putts} (5)
Hole 7: {Driver,325,Fairway,171] {6-Iron,170,Green,1} {One putt} (3)
Hole 8: {Driver,306,Fairway,109} {9-Iron,100,Green,9} {Two putts} (4)
Hole 9: {Driver,308,Green,12} {Two putts} (3)
Total: 36 shots
I'll admit, this is a rather ambitious challenge for a first post on CG.SE, so I'd be glad to talk about how to improve this challenge in comments. Thank you for your help.
2I'd really appreciate it if, for us non-golfers, you didn't use as many golfing terms (e.g. "tee boxes" and "horizontal shift"). :) – kirbyfan64sos – 2015-09-13T18:11:33.970
I'll add a list of golf-related terms. When playing golf, the ball doesn't always go straight, so I just said that the ball always goes directly towards the hole, and thus does not have any horizontal shift. – Arcturus – 2015-09-13T18:13:22.153
Say the pin is at 301 yards, and there is fairway from
0~299
yards, green from300~315
yards, and water from316~330
yards. What club will be chosen? What if the water is replaced by rough? – lirtosiast – 2015-09-13T19:09:16.043Ideally, the program should be able to come up with its own strategy. – Arcturus – 2015-09-13T19:10:56.663
What do you mean by "optimal strategy"? Minimizing average number of strokes? As for winning criterion I'd go with code-golf. – lirtosiast – 2015-09-13T19:14:25.070
I meant that the program should come up with its own strategy for playing the round. For the example you gave, the program could choose the "safe" option of trying to get on the green in two shots, or using a driver to go for the green in one as the "risky" option. – Arcturus – 2015-09-13T19:18:01.617
So either strategy is admissible there? What if the pin is at 300 yards, and there is green from
0~300
yards and water from 300 yards on? – lirtosiast – 2015-09-13T19:21:16.347@ThomasKwa I think OP means that some sort of standard risk factor applies. Say the shot has a 50% chance of success (ending up with one less shot), but a 75% chance of failing (landing in the water, +1 shot), the risk outweighs the gains and the shot shouldn't be attempted. Say that maybe the chance of a failed shot has to be
x%
less than the chance of "gaining" a shot for it to be attempted. You could then experiment with that value to create riskier or safer players. If this is what OP means though, it should be a requirement. – Jan – 2015-09-13T19:30:13.030@Jan I added that specification. – Arcturus – 2015-09-13T19:56:15.417
Does "choose a random club" count as a strategy? What about "choose the driver every time"? – lirtosiast – 2015-09-13T20:07:37.623
Those are possible strategies, but not great ones in terms of number of shots. "Driver every time" would probably do better in a golfing challenge than in shot-optimization, so I think I'm going to change this into a programming challenge. – Arcturus – 2015-09-13T20:31:53.433