[comp.sources.games] v07i014: bidding3 - Bridge Bidder, Version 3.0, Part02/02

billr@saab.CNA.TEK.COM (Bill Randle) (07/12/89)

Submitted-by: Nathan Glasser <nathan@brokaw.lcs.mit.edu>
Posting-number: Volume 7, Issue 14
Archive-name: bidding3/Part02
Supersedes: bidding2: Volume 6, Issue 6


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 2)."
# Contents:  bidding.h deal.c exper.doc history.doc makefile.unx
#   readme.doc
# Wrapped by billr@saab on Thu Jul  6 07:50:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'bidding.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bidding.h'\"
else
echo shar: Extracting \"'bidding.h'\" \(3153 characters\)
sed "s/^X//" >'bidding.h' <<'END_OF_FILE'
X/* bidding.h */
X/*
X			Bridge Bidder	Version 3.0
X			by John Oswalt and Nathan Glasser
X			..!sun!megatest!jao (usenet)
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			June, 1989
X------------------------------------------------------------------------------
XCopyright 1988, 1989 by Nathan Glasser and John Oswalt.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X*/
X
X#include <stdio.h>
X#include <ctype.h>
X#ifdef MSDOS
X#include <string.h>
X#include <stdlib.h>
X#define random rand
X#define srandom srand
X#define index strchr
X#else
X#include <strings.h>
X#endif
X
X#define LOGFILE "bidding.log"
X
X/* Ranks */
X#define JACK 11
X#define QUEEN 12
X#define KING 13
X#define ACE 14
X
X/* Suits */
X#define SPADES 0
X#define HEARTS 1
X#define DIAMONDS 2
X#define CLUBS 3
X
X#define NOTRUMP 4
X#define RANK_USED 4
X
X/* More "Suits" */
X#define DOUBLE 5
X#define REDOUBLE 6
X#define PASS 7
X
X
X/* Vulnerabilities */
X#define FIRSTPAIR 0
X#define SECONDPAIR 1
X#define RELATIVE 1
X#define NEITHER 2
X#define BOTH 3
X
X/* Types of bidding display */
X#define BIDDING 0
X#define LEADING 1
X#define PASSING 2
X
X
Xstruct card_or_bid {
X    int rank;
X    int suit;
X};
X
Xtypedef struct card_or_bid card;
X
Xtypedef struct bid {
X    struct card_or_bid bid;
X    struct bid *next,*prev;
X} bid;
X
Xtypedef card hand[13];
X
Xtypedef struct deal {
X    hand hands[4];
X    int vulnerability;
X    bid *bids;
X    int num_bids;
X    int bidding_done;
X    card opening_lead;
X} deal;
X
X/* Pointer to function returning int */
Xtypedef int (*PFI)();
X
X
X/* Deal type information structure */
Xstruct deal_type {
X    char *deal_name;		/* Name of deal type */
X    PFI predeal_func,hand_func;	/* Predeal function and hand function */
X    int param_max;		/* Maximum parameter; Negative => none */
X				/* If 0, num_deals is supplied */
X    char *description;		/* Documentation string */
X};
X
X
Xextern int cardsused[52];
Xextern int hand_setup[4];
Xextern int cardsleft;
X
X
X
X
X/* Individual users may want to modify these values for their system
X   or their personal preferences. */
X
X
X/* If you wish to use formfeeds to clear the screen instead of repeated
X   newlines, comment out the definition of SCREEN_CLEAR_SIZE. Otherwise
X   this value indicates the number of newlines to use for this purpose. */
X#define SCREEN_CLEAR_SIZE 24
X
X
X/* If you wish the bids for the displayed hand to always be lined up
X   in the first column, with dashes on the first display line
X   for bids of players before the dealer, define LISTING_FIRST_COL.
X   If you wish the bids to always start in the first column, with the bids
X   for the displayed hand always appearing in the same column which can
X   be any column, as appropriate, define LISTING_ANY_COL. Make sure
X   exactly one of these two is defined. */
X/*
X
XUsing LISTING_FIRST_COL, a bidding sequence might look like this:
X
X		*You*	LHO	Partner	RHO
XBidding:	--------------------------------
X		-	-	-	1H
X		P	1S	2C	2H
X		?
X
XUsing LISTING_ANY_COL, the same sequence looks like:
X
X		RHO	*You*	LHO	Partner
XBidding:	--------------------------------
X		1H	P	1S	2C
X		2H
X*/
X
X#define LISTING_FIRST_COL
X/* #define LISTING_ANY_COL */
END_OF_FILE
if test 3153 -ne `wc -c <'bidding.h'`; then
    echo shar: \"'bidding.h'\" unpacked with wrong size!
fi
# end of 'bidding.h'
fi
if test -f 'deal.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'deal.c'\"
else
echo shar: Extracting \"'deal.c'\" \(2305 characters\)
sed "s/^X//" >'deal.c' <<'END_OF_FILE'
X/* deal.c */
X/*
X			Bridge Bidder	Version 3.0
X			by John Oswalt and Nathan Glasser
X			..!sun!megatest!jao (usenet)
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			June, 1989
X------------------------------------------------------------------------------
XCopyright 1988, 1989 by Nathan Glasser and John Oswalt.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X*/
X
X#include "bidding.h"
X
Xcard_compare(pcard1,pcard2)
Xcard *pcard1,*pcard2;
X{
X    return((pcard1->suit != pcard2->suit) ? (pcard1->suit - pcard2->suit) :
X	   (pcard2->rank - pcard1->rank));
X}
X
Xdeal_hands(pdeal)
Xdeal *pdeal;
X{
X    card *thehand;
X    int player,cardsinhand;
X    int cardnum;
X    int nextcard;
X    static vulnerability = 0;
X    
X    pdeal->num_bids = 0;
X    pdeal->bidding_done = 0;
X    vulnerability = ((pdeal->vulnerability = vulnerability) + 1) % 4;
X    pdeal->opening_lead.rank = pdeal->opening_lead.suit = -1;
X    
X    for (player = 0; player < 4; player++)
X    {
X	thehand = pdeal->hands[player];
X
X	if (!hand_setup[player])
X    	    for (cardsinhand = 0; cardsinhand < 13; cardsinhand++)
X    	    {
X    	    	nextcard = random() % (cardsleft--);
X    	    	for (cardnum = 0 ; cardsused[cardnum] || --nextcard >=0;
X    	    	  cardnum++);
X    	    	cardsused[cardnum] = 1;
X    	    	thehand[cardsinhand].suit = cardnum / 13;
X    	    	thehand[cardsinhand].rank = 2 + (cardnum % 13);
X    	    }
X	qsort(thehand,13,sizeof(card),card_compare);
X    }
X}
X
Xprint_hand(fp,thehand)
XFILE *fp;
Xcard *thehand;
X{
X    int i;
X    char bufs[4][80];
X    
X    format_hand(bufs,thehand);
X    for (i = 0; i < 4; i++)
X    {
X	fputs(bufs[i],fp);
X	putc('\n',fp);
X    }
X}
X
X/* Accepts an array of size four of strings, and formats into it */
Xformat_hand(bufs,thehand)
Xchar (*bufs)[80];
Xcard *thehand;
X{
X    extern char *suit_strings[];
X    static char card_chars[] = "xx23456789TJQKA";
X    int suit_num = -1;
X    int i;
X    static char card_str[3] = " A";
X    
X    bufs--;
X    for (i = 0; i < 13; i++)
X    {
X	while (thehand[i].suit != suit_num)
X	    sprintf(*++bufs,"%8s:  ",suit_strings[++suit_num]);
X	card_str[1] = card_chars[thehand[i].rank];
X	strcat(*bufs,card_str);
X    }
X    
X    while (suit_num < 3)
X	sprintf(*++bufs,"%8s:  ",suit_strings[++suit_num]);
X}
END_OF_FILE
if test 2305 -ne `wc -c <'deal.c'`; then
    echo shar: \"'deal.c'\" unpacked with wrong size!
fi
# end of 'deal.c'
fi
if test -f 'exper.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'exper.doc'\"
else
echo shar: Extracting \"'exper.doc'\" \(2935 characters\)
sed "s/^X//" >'exper.doc' <<'END_OF_FILE'
X			Bridge Bidder	Version 3.0
X			by John Oswalt and Nathan Glasser
X			..!sun!megatest!jao (usenet)
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			June, 1989
X------------------------------------------------------------------------------
XCopyright 1988, 1989 by Nathan Glasser and John Oswalt.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X==============================================================================
X
XINTRODUCTION
X
XBid works by dealing hands randomly, then throwing out deals which
Xdo not conform to specified criteria.
X
XThe file exper.c contains code to implement very specific deals.
XSince frequently what you want to do is set one hand exactly (the
Xone you held at the table), and to vary the others, a facility is
Xprovided to specify one hand, and let the program deal the other
Xthree randomly.  (You can also set two, and have the program deal two.)
X
XHOW TO WRITE A NEW EXPERIMENT
X
XCopy exper.c to some safe place, and then modify it to implement
Xyour new problem.
X
XYou must modify two routines.  experiment_predeal() places specific
Xcards in one (or two) hands, sets cardsused[] to indicate which
Xcards have already been dealt out (so when the program deals out
Xthe other hands randomly, it doesn't use them again), hand_setup[]
Xto indicate which hand has been pre-dealt, and decrements cardsleft.
Xexperiment_predeal() uses experiment_hand[] to set the set hand.
X
XIf you are setting one hand, all you need to is modify this array's
Xinitialization.  experiment_predeal() may be left as it is.
X
XThe second routine, experimentq(), is harder to write.  It is passed
Xa pointer to a deal, and returns TRUE if the deal qualifies, and
XFALSE if it does not.
X
Xpdeal->hand[0] is a pointer to the dealer's hand, pdeal->hand[1] to the
Xsecond hand, etc. experimentq() makes calls to functions in eval.c
Xto determine if the deal qualifies.  See the source in eval.c for
Xdetails.
X
XIn the example experimentq(), we make sure that the dealer has less
Xthat 11 high card points, and does not have 6 hearts, 6 spades, or 
X7 clubs.  (This approximates a non-opening hand.),  Second hand
Xis required to have 7 diamonds including the ace, not the spade ace,
Xless than 11 HCP, no four card major, and not five clubs.  This
Xapproximates a hand which might open 3 diamonds.  Third hand is required
Xto have 5 or 6 losers, and at least 5 spades.  This approximates a hand
Xwhich might overcall a second-seat 3D with 3S.  The fourth hand is not
Xchecked, since it is the set hand. (See example.exp for the rationale
Xfor all this.)
X
XIt is best to put the most restrictive tests first, for efficiency.
X
XEXAMPLE
X
Xexample.exp is a version of a usenet posting article by John Oswalt.
XIt is an example of how one might use the program to investigate a bidding
Xquestion.  The exper.c file as distributed contains the code used to
Xanalyze this problem.
END_OF_FILE
if test 2935 -ne `wc -c <'exper.doc'`; then
    echo shar: \"'exper.doc'\" unpacked with wrong size!
fi
# end of 'exper.doc'
fi
if test -f 'history.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'history.doc'\"
else
echo shar: Extracting \"'history.doc'\" \(1391 characters\)
sed "s/^X//" >'history.doc' <<'END_OF_FILE'
X			Bridge Bidder	Version 3.0
X			by John Oswalt and Nathan Glasser
X			..!sun!megatest!jao (usenet)
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			June, 1989
X------------------------------------------------------------------------------
XCopyright 1988, 1989 by Nathan Glasser and John Oswalt.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X==============================================================================
XHISTORY
X
XThis program was first written by Nathan Glasser (nathan@brokaw.lcs.mit.edu,
Xnathan@mit-eddie.uucp).  Version 1.0 was released in 5/88, and Version 2.0
Xwas released in 2/89.  Version 1.0 was then extensively modified by John
XOswalt (...!sun!megatest!jao), and worked over again by Nathan Glasser, to
Xproduce Version 3.0 in 6/89.  The basic mechanisms for dealing hands,
Xsoliciting bids from the user, checking them for validity, storing and
Xdisplaying them, are due to Nathan Glasser.  Most of bidding.c, deal.c, and
Xbidding.h are the product of Nathan Glasser, who also wrote the majority of
Xbidding.doc and readme.doc.
X
XAll the mechanisms for making a deal conform to criteria were written by John
XOswalt.  The files files eval.c, exper.c, exper.doc, and example.exp
Xare entirely John Oswalt's doing.  This file history.doc was written
Xjointly by John and Nathan.
END_OF_FILE
if test 1391 -ne `wc -c <'history.doc'`; then
    echo shar: \"'history.doc'\" unpacked with wrong size!
fi
# end of 'history.doc'
fi
if test -f 'makefile.unx' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.unx'\"
else
echo shar: Extracting \"'makefile.unx'\" \(549 characters\)
sed "s/^X//" >'makefile.unx' <<'END_OF_FILE'
X# Makefile (unix) for
X#			Bridge Bidder	Version 3.0
X#			by John Oswalt and Nathan Glasser
X#			..!sun!megatest!jao (usenet)
X#			nathan@brokaw.lcs.mit.edu (internet)
X#			nathan@mit-eddie.uucp (usenet)
X#
X#			June, 1989
X#-----------------------------------------------------------------------------
X#Copyright 1988, 1989 by Nathan Glasser.
X#You may feel free to distribute this program in its current form.
X#Please do not remove this copyright information.
X
XOBJS = bidding.o deal.o eval.o exper.o
X
Xbid:	$(OBJS)
X	$(CC) $(OBJS) -o bid
X
X$(OBJS):	bidding.h
END_OF_FILE
if test 549 -ne `wc -c <'makefile.unx'`; then
    echo shar: \"'makefile.unx'\" unpacked with wrong size!
fi
# end of 'makefile.unx'
fi
if test -f 'readme.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'readme.doc'\"
else
echo shar: Extracting \"'readme.doc'\" \(1403 characters\)
sed "s/^X//" >'readme.doc' <<'END_OF_FILE'
Xreadme.doc file for		Bridge Bidder	Version 3.0		6/89
X==============================================================================
XFiles included:
Xbidding.c		source
Xdeal.c			source
Xeval.c			source
Xexper.c			source
Xbidding.h		source
Xbidding.doc		general documentation
Xexper.doc		documentation of experiment feature
Xreadme.doc		this file
Xhistory.doc		evolution of this program
Xexample.exp		example of experiment feature
Xmakefile.unx		makefile (unix)
Xmakefile.dos		makefile (ibm-pc/ms-dos)
X
X
XCompiling information
X==============================================================================
XThere are some #define's in bidding.h which can be adjusted to suit your
Xdesires. All of these appear at the very end of bidding.h.
X
XThe defines which can be adjusted allow you to 
X1)	Choose method of screen clearing between bids.
X2)	Choose the style in which bids are displayed.
X
XIf you prefer options as they are, no adjustments should be
Xnecessary. Simply make sure the appropriate makefile is set up for
Xyour system, and run make.
X
X
XDifferences between version 3.0 and 2.0
X=======================================
XIntroduction of deal_types and experiments by John Oswalt.
XCompile-time option for bidding display style installed.
X
X
XDifferences between version 2.0 and 1.0
X========================================
XBetter display of current bidding sequence.
XCompile-time options for screen clearing installed.
END_OF_FILE
if test 1403 -ne `wc -c <'readme.doc'`; then
    echo shar: \"'readme.doc'\" unpacked with wrong size!
fi
# end of 'readme.doc'
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0