See the assignment turn-in page for instructions on turning in your assignment.
A deck of cards is the set of cards forming all possible combinations of suit and rank; a deck of cards contains 13*4 = 52 cards (there are no jokers). A hand is a subset of cards taken from a deck of cards; the size of a hand is the number of cards in the hand.
int count_hand(int ranks[], char suits[], int hand_size);
count_hand()
accepts as input ranks
, suits
, and hand_size
and returns as output the number of points in the hand described by
ranks
and suits
.
The hand contains hand_size
cards; hand_size
should be between 0 and
52 inclusive. The i-th card in the hand, 1 <= i <= hand_size
has
rank ranks[
i - 1]
and suit suits[
i - 1]
. The
return value from count_hand()
is the number of points in the hand, or
-1
if something's wrong (illegal rank or suit, or bad hand size).
There are three ways for a hand to score points: by runs, pairs, and kinds.
Because a run is determined by the card and not just the rank, it is possible to form several runs using different cards of the same rank. For example, the hand 9H 10D JD 10C contains two runs: 9H 10D JD and 9H 10C JD.
To be valid, a run must be the largest possible run in the hand. For example, the hand 1C 2C 3D 4S contains one run of four cards; it does not contain a run of three cards.
Each run in an hand contributes points equal to the number of cards in the run. In the first example, the run contributes three points; in the second example, two runs of three cards contributes six points total; in the third example, the run contributes four points.
Each pair in a hand contributes two points to the hand.
An n-of-a-kind hand contributes n points to the hand.
The points in a hand is the sum of points contributed by all runs, pairs, and kinds in the hand.
test-cnt.o
with your
implementation of count_hand()
to test your implementation. If you're on
rockhopper or one of the other linux machines in the PC labs, you can access
the object file directly at
/export/home/us/csfac/cs176-summer2001/pa/1/test-cnt.o
You can also download test-cnt.o
using a browser by
left clicking on the test-cnt.o
link while holding down
the shift key (this works for Netscape and, I'm assuming, Internet Explorer
too). If you forget to hold down the shift key while clicking the left mouse
button, you will get a page starting with "ELF" and followed by stuff.
If your implementation is in the source file count-hand.cc
, you can link
the two using a command such as
$ g++ -o count-hand test-hand.o count-hand.cc
if you've made a local copy of the object file or
$ g++ -o count-hand /export/home/us/cs176-summer2001/pa/1/test-hand.o count-hand.cc
if you're accessing the object file directly. If everything goes well you'll
have the executable count-hand
, which you can run to test your code.
The object file test-cnt.o
will only work on rockhopper
or related linux machines; it will not work on Suns and it will not work on
Windows systems (you may be able to copy it to your own linux system, assuming
you're running a sufficiently up-to-date version of linux).
This page last modified on 4 June 2001.