CSC171语言

CSC171 — Project 2
TTY Golf
In this project you will build on your first project experience and develop a TTY program to
play the game of Golf. It doesn’t matter if you know how golf works—the rules of the game
that you need to implement our version are described below. And of course you can look it
up on Wikipedia: Golf.
As with Project 1, the basic idea is that the program will tell the player the game situation and
offer them a choice of various actions. The player will type their choices and the program will
read them, compute the result, and inform the user. This is essentially what you did last time,
only for a more complicated and realistic game. You may also, for extra credit, implement a
computer opponent that plays against the human.
This document contains a lot of information. First it describes the game of golf generally, and
then the abstract version of it that we will use for our TTY game. An example of what the
output of your program might look like is provided. You should be able to start thinking about
your program after reading these.
The section “Specifications” provides all the details that you need to put into your program in
order to actually play the game. The section “Project Design and Requirements” describes
the main aspects of the project and gives some suggestions on how to approach them. The
section “Specific Requirements” spells out exactly what your program must do. Grading
details, opportunities for extra credit, and other policy details are at the end of the document.
The Game of Golf (Simplified)
The game of golf is played on a mostly grass-covered golf course (see Figure ). A course
consists of 18 holes. Each hole is a more or less linear span of the course’s grassy terrain.
Each hole has a tee at one end, where the players start, and a green, where the grass is
cut very short, at the other end. Someplace on the green is an actual, physical hole (or cup)
marked by a flag.
Each player uses a set of golf clubs to hit their ball around the course. Each club has different
characteristics, but roughly speaking the farther a club can hit, the less accurate it is. Each
hit is called a shot or stroke.
The first shot on each hole is taken from the tee. Most holes are too long for the tee shot to
reach the green and get into the hole. Subsequent shots are played from where the previous
shot lands and stops. Once the ball reaches the green, the player uses a special club called
1
Map of the Old Course at St. Andrews, Scotland.
Source: supersport.com
Schematic of a golf hole. 1=tee, 2=water
hazard, 3=rough, 4=out of bounds, 5=sand
bunker, 6=water hazard, 7=fairway, 8=putting
green, 9=flag, 10=hole (cup). Source:
Wikipedia
Figure 1: Golf course example and definitions
a putter (PUH-ter) to putt (PUHT) or tap the ball towards the hole. Getting the ball to fall into
the hole is called “sinking the putt.”
The goal of the game is to get the ball into the hole in as few strokes (shots) as possible.
Each hole is assigned an “expected” number of strokes, called its par. Completing a hole in
that number of strokes is called “making par.” Completing a hole in fewer strokes is called
being “under par;” completing it in more strokes is called being “over par.”
A full game, also called a round, involves playing all 18 holes of a course in turn. A player’s
score for a round is the total number of strokes they used to complete the course. This is
traditionally expressed as the difference from the total par for the course. Thus finishing in
one less stroke than par is “-1” (“one under”), while finishing in one more stroke is “+1” (“one
over”).
In the real game, each hole is a part of the landscape of the course. For our game, we will
ignore almost everything about the physical topography of the course. The holes will simply
have a distance from tee to hole. All greens will be a fixed size and it won’t matter where on
the green the hole is placed.
TTY Golf
In TTY Golf, a course is represented as a set of 18 holes, each of which has a yardage
(number of yards from tee to hole) and a par for the hole.
2
The player will play each hole of the course in turn to complete their round.
For each stroke (shot) other than putting, the player will select a club (a number 1–10) and
the power with which to hit the ball (also a number 1–10). Your program will compute the
distance of the shot (details below) and inform the user of the result.
The player will continue to take shots like this until ball is within 20 yards (60 feet) of the hole,
at which point it is on the green.
Once the ball is on the green, the player putts by specifying the power with which to hit the
ball (1–10). Your program will compute the distance of the putt and whether it goes in the
hole (details below). The player continues to putt until the ball is in the hole.
Your program will keep track of the number of strokes (shots) and the player’s score relative
to the total par of the holes they have played so far.
When the game is over, your program should offer to play a new round or quit.
Sample Transcript
The following transcript is a purely hypothetical example of the sort of gameplay that your
program might provide. It should give you some idea of the sorts of messages and prompts
that are necessary. But you do NOT have to make your game play exactly like this. The
important thing is to keep the player informed about the game situation. Be very clear what
you’re asking for when prompting for user input.
Welcome to TTY Golf!
Please select a course:

  1. Genesee Valley Park North Course
  2. The Old Course at St. Andrews
    Your choice [1-2]: 2
    You are playing The Old Course at St. Andrews.
    You are at the first tee. 376 yards, par 4.
    Choose your club [1-10]: 1
    Power [1-10]: 10
    You hit the ball 236 yards. Nice!
    You are in the fairway.
    Second shot. 140 yards to the hole.
    3
    Choose your club [1-10]: 7
    Power [1-10]: 6
    You hit the ball 130 yards.
    You are on the green.
    Third shot. 30 feet to the hole.
    Putt power [1-10]: 5
    Your putt went 27 feet.
    You are on the green.
    Fourth shot. 3 feet to the hole.
    Putt power [1-10]: 2
    It’s in the hole!
    You made par on this hole.
    Your score after the first hole is: par.
    Type RETURN to continue to the next hole:
    You are at the second tee. 453 yards, par 4.
    Choose your club [1-10]: 1
    Power [1-10]: 10
    You hit the ball 260 yards. Nice!
    ...
    Your final score for the round is: 3 under. Good job!
    Would you like play another round [Y/N]? Y
    Please select a course:
    ...
    4
    Specifications
    Courses
    You can lookup the yardage and par of many golf courses online. To get you started, here
    are the specifications for the Genesee Valley Park North Course (in Rochester) and the Old
    Course at St. Andrews in Scotland, the oldest golf course in the world.
    Genesee Valley Park North Course
    Hole Yards Par Hole Yards Par
  3. 530 5 10 433 4
  4. 305 4 11 363 4
  5. 331 4 12 174 3
  6. 201 3 13 545 5
  7. 500 5 14 419 4
  8. 226 3 15 512 5
  9. 409 4 16 410 4
  10. 410 4 17 320 4
  11. 229 3 18 170 3
    The Old Course at St. Andrews (yes, each hole has its own name)
    Hole Name Yards Par Hole Name Yards Par
  12. Burn 376 4 10 Bobby Jones 386 4
  13. Dyke 453 4 11 High (In) 174 3
  14. Cartgate (Out) 397 4 12 Heathery (In) 348 4
  15. Ginger Beer 480 4 13 Hole O’Cross (In) 465 4
  16. Hole O’Cross (Out) 568 5 14 Long 618 5
  17. Heathery (Out) 412 4 15 Cartgate (In) 455 4
  18. High (Out) 371 4 16 Corner of the Dyke 423 4
  19. Short 175 3 17 Road 495 4
  20. End 352 4 18 Tom Morris 357 4
    Clubs
    Obviously in real-life, how far the ball travels when it is hit depends on the player, the club,
    and how the ball is hit. For TTY Golf, things are much simpler. We will assume the following
    specifications for the different golf clubs (based on source: about.com):

你可能感兴趣的