4 Tiger Woods - Phil Mickelson 2 Gene Simmons - Richard Simmons 1 Bill Gates - Warren Buffett 3 Cher - Madonna SCORES -430 -400 -520 -1100 -180 -130 -130 PASS -100 650 650 ---- |
Here is a fictious game composed of four pairs who play a three-board game. First, note that Bill Gates/Warren Buffett are pair 1, even though they are not the first pair listed. They scored -430 on the first board, -180 on the second, and -100 on the third. Tiger Woods/Phil Mickelson are pair 4, and they only played the first two boards. They went for a big negative number on board one, and scored 0 on board two.
Unfortunately, since we all do not play the same boards, and sometimes we don't play the same number of boards, total score is a bad metric. Instead, each score may be converted into a number of matchpoints. The number of matchpoints that a pair gets on a board is equal to the number of pairs that the pair scored better than on that board. For example, on board #1 above, Bill & Warren scored better than two other pairs (Cher & Madonna and Tiger & Phil). Therefore, they receive two matchpoints for that board. Tiger and Phil receive zero since they didn't beat anyone.
To be specific, a pair scores one matchpoint for each other pair that they beat on a board, and a half a matchpoint for each pair that they tie. For example, on board #3, Cher/Madonna and the two Simmons each get 1.5 matchpoints because they beat one pair and tied one pair.
Thus, a second way to score a bridge game is to total the matchpoints for each pair on each board. For example, on these four boards, Bill/Warren receive 2 matchpoints on board one, and zero on boards two and three -- that's 2 total matchpoints. Gene/Richard receive 3 matchpoints on board one, and 1.5 each on boards two and three. Thus, they have six total matchpoints.
Unfortunately, again, total matchpoints is not the best metric for comparing scores, because there are times where pairs play different numbers of boards, and, worse yet, sometimes the number of pairs that play different boards also differs. This happens in our example, because Tiger/Phil only play two boards. You would like to have a metric that, regardless of the number of pairs and boards, gives you an idea of well you did. The way to do that is to present a pair's score on a board as a percentage. This is a percentage of the pairs that the pair beat, and is equal to the number of matchpoints that the pair receives on the board, times 100, divided by the total number of players who played that board minus one.
For example, Gene/Richard beat all three other pairs, and thus get 100% for that board. Bill/Warren beat two out of three and thus get 66.67%. On board three, Bill/Warren beat no one, and thus get zero percent. Cher/Madonna and the Simmons each got 1.5 out of 2.0 total matchpoints, for 75%.
Using percentages, you may score a game by the average percentage of a pair on each board. Thus, in the example above, Bill/Warren would score (66.67+0+0)/3 = 22.22% for the game. Tiger/Phil would score (0+100)/2 = 50.00%. Gene/Richard would score (100+50+75)/3 = 75.00. And finally, Cher/Madonna would score (33.33+50+75)/3 = 52.78.
Here is simpscore running on our example:
UNIX> cd /home/plank/cs140/Labs/Lab3
UNIX> simpscore scores/Easy_Test.txt
-710 -236.67 2.0 22.22 3 Bill Gates - Warren Buffet
120 40.00 6.0 75.00 3 Gene Simmons - Richard Simmons
0 0.00 4.0 52.78 3 Cher - Madonna
-1100 -550.00 3.0 50.00 2 Tiger Woods - Phil Mickelson
UNIX>
Note, you can pipe the output to various incarnations of sort to
sort by the various types of total score. Below we sort by total score
and by average matchpoints:
UNIX> cd /home/plank/cs140/Labs/Lab3
UNIX> simpscore scores/Easy_Test.txt | sort -nr
120 40.00 6.0 75.00 3 Gene Simmons - Richard Simmons
0 0.00 4.0 52.78 3 Cher - Madonna
-710 -236.67 2.0 22.22 3 Bill Gates - Warren Buffet
-1100 -550.00 3.0 50.00 2 Tiger Woods - Phil Mickelson
UNIX> simpscore scores/Easy_Test.txt | sort -nr +3
120 40.00 6.0 75.00 3 Gene Simmons - Richard Simmons
0 0.00 4.0 52.78 3 Cher - Madonna
-1100 -550.00 3.0 50.00 2 Tiger Woods - Phil Mickelson
-710 -236.67 2.0 22.22 3 Bill Gates - Warren Buffet
UNIX>
If the score file is in the incorrect format, simpscore should exit with an error message denoting the offending line of the file. Think of what would consitute a bad file -- make sure that you handle all sorts (e.g. missing pair numbers, bad pair numbers, no names, not enough scores on a score line, non-numbers (or PASS or ----), etc.).
Score files will have no more than 100 pairs, and no more than 40 boards.
There is a working executable in /home/plank/cs140/Labs/Lab3/simpscore. There are also score files in the directory /home/plank/cs140/Labs/Lab3/scores -- these are scores of real games played in Knoxville/Maryville recently (although I've anonymous-ized the names). They are all in the proper format.
Make sure the output of your program matches the output of the /home/plank/cs140/Labs/Lab3/simpscore character for character. They may differ in error statements, but for correct input files, they should be exactly the same.
You should use the fields library for this program.
Calculating matchpoints may seem like a challenge to you. What I did was the following -- when reading a line of scores, I would allocate an array that holds all the scores for a board. Then, for each pair who played the board, I'd calculate their matchpoints by traversing the array, and adding 1 whenever I saw a score worse than the pair's score, and adding .5 whenever I saw a tie. Finally, I subtracted .5 (because I added .5 when I saw the pairs score in the array). You'll learn later that this is not the most efficient way to do this, but it will suffice for now.
The Knoxville Association of Bridge Clubs also has a web site at http://www.discoveret.org/bridge -- they have teachers there and games for newcomers to the game of bridge. If you are the type of person who likes cards and competition, give it a try!