home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
okbridge
/
part06
/
scoring.c
< prev
Wrap
C/C++ Source or Header
|
1992-01-12
|
6KB
|
222 lines
/* scoring.c -- scoring functions for the bridge program.
!
! Copyright (C) 1990,1991 by Matthew Clegg
!
! This program may be copied and distributed freely. Please do not
! charge money for this program or for any program derived from it.
! If you modify this program, then include a notice stating plainly
! that your program is derived from the okbridge program and is not
! the same as the official okbridge program.
!
! I welcome any suggestions for improvement to okbridge, and
! I would be especially happy to receive improved source code.
! If you have comments or suggestions, or if you would like to
! join the okbridge mailing list, then write to
!
! mclegg@cs.ucsd.edu
!
*
* This file defines the functions used for computing scores.
* We provide functions for scoring according to the rules of
* rubber bridge as well as according to the rules of Chicago style
* bridge. Instead of being passed parameters, these functions
* obtain most of their information from the global variables
* defined in globals.h.
*
* I would like to thank Tom Kronmiller for supplying the code
* for scoring according to the Chicago rules. Thanks Tom!
*/
#include "globals.h"
static int first_trick [] = {20, 20, 30, 30, 40};
static int subseq_tricks [] = {20, 20, 30, 30, 30};
int Rubber_score_above (extra)
int extra;
/* int Rubber_score_above (int extra, int vulnerable); */
/* Computes the above-the-line score for the current contract assuming
* that 'extra' many tricks below the required number were taken.
* Returns the computed above-the-line score.
*/
{
int above = 0; /* computed above-the-line points. */
int vul; /* true if contracting team is vulnerable. */
vul = vulnerable[side_of(declarer)];
if (doubled || redoubled) {
above = 100 * extra;
if (vul) above *= 2;
if (redoubled) above *= 2;
above += 50;
} else
above = subseq_tricks[trump_suit] * extra;
if (contract == 6)
above += vul? 750: 500;
else if (contract == 7)
above += vul? 1500: 1000;
return (above);
};
int Rubber_score_below ()
/* int Rubber_score_below (void); */
/* Computes the below-the-line score for the current contract,
* assuming that it was made.
*/
{
int below = 0; /* computed below-the-line points. */
below = first_trick[trump_suit] +
(contract - 1) * subseq_tricks[trump_suit];
if (redoubled)
below *= 4;
else if (doubled)
below *= 2;
return (below);
};
int Rubber_score_set (down)
int down;
/* int Rubber_score_set (int down); */
/* Computes the penalty score for the current contract assuming that
* 'down' too few tricks were taken. Returns the score.
*/
{
int penalty = 0; /* computed penalty points. */
int vul; /* true if contracting team is vulnerable. */
vul = vulnerable[side_of(declarer)];
down -= 1;
if (doubled || redoubled) {
if (vul) penalty = 200 + 300 * down;
else penalty = 100 + 200 * down;
if (redoubled) penalty *= 2;
} else {
if (vul) penalty = 100 + 100 * down;
else penalty = 50 + 50 * down;
};
return (penalty);
};
int Chicago_score_made (extra, vulnerable)
int extra, vulnerable;
/* int Chicago_score_made (int extra, int vulnerable); */
/* Computes the score for the current contract assuming that it was made
* and that an additional 'extra' tricks were taken. 'vulnerable' is a
* boolean flag which indicates whether the declaring team was
* vulnerable. Returns the score.
*/
{
int result = 0, perTrick;
/* How much is making the bid worth? */
perTrick = (MINOR(trump_suit))? 20:30;
result = perTrick * contract;
if (trump_suit == SUIT_NOTRUMP) result += 10;
if (redoubled) result *= 4;
else if (doubled) result *= 2;
/* Was it a game we made? */
if (result >= 100) result += (!vulnerable)? 300:500;
/* else result += 50; */
/* Was it a slam we made? */
if (contract == 6) result += (!vulnerable)? 500:750;
if (contract == 7) result += (!vulnerable)? 1000:1500;
/* Were we insulted by a double? */
if (redoubled) result += 100;
else if (doubled) result += 50;
/* How much do we get for overtricks? */
if (redoubled)
result += (extra * 100) * (vulnerable? 4: 2);
else if (doubled)
result += (extra * 100) * (vulnerable? 2: 1);
else
result += extra * perTrick;
return (result);
}
int Chicago_score_set (down, vulnerable)
int down, vulnerable;
/* int Chicago_score_set (int down, int vulnerable); */
/* Computes the score for the current contract assuming that it was
* set and that 'down' too few tricks were taken. 'vulnerable' is
* a boolean flag which indicates whether the declaring team was
* vulnerable. Returns the score.
*
* written by Tom Kronmiller
*/
{
int result = 0;
if (!doubled)
{
result = 50 * down;
if (vulnerable) result *= 2;
}
else
{
switch (down)
{
case 1:
result = (!vulnerable)? 100:200;
break;
case 2:
result = (!vulnerable)? 300:500;
break;
case 3:
result = (!vulnerable)? 500:800;
break;
default:
result = 500 + (300*(down-3))
+ ((!vulnerable)? 0:300);
break;
}
if (redoubled) result *= 2;
}
return (result);
}
int Duplicate_score_made (extra, vulnerable)
int extra, vulnerable;
/* int Duplicate_score_made (int extra, int vulnerable); */
/* Computes the score for the current contract assuming that it was made
* and that an additional 'extra' tricks were taken. 'vulnerable' is a
* boolean flag which indicates whether the declaring team was
* vulnerable. Returns the score.
*/
{
int score;
score = Chicago_score_made (extra, vulnerable);
if (score < 300)
score += 50;
return (score);
}
int Duplicate_score_set (down, vulnerable)
int down, vulnerable;
/* int Duplicate_score_set (int down, int vulnerable); */
/* Computes the score for the current contract assuming that it was
* set and that 'down' too few tricks were taken. 'vulnerable' is
* a boolean flag which indicates whether the declaring team was
* vulnerable. Returns the score.
*/
{
return (Chicago_score_set(down, vulnerable));
};