[comp.sources.games] v07i019: poker - five card draw poker, Part02/02

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

Submitted-by: Metal Head <csx43%seq1.keele.ac.uk@nsfnet-relay.ac.uk>
Posting-number: Volume 7, Issue 19
Archive-name: poker/Part02


#! /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:  input.c p_deal.c poker.h poker_rules
# Wrapped by billr@saab on Wed Jul 12 10:54:33 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'input.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'input.c'\"
else
echo shar: Extracting \"'input.c'\" \(2091 characters\)
sed "s/^X//" >'input.c' <<'END_OF_FILE'
X#include "poker.h"
X
X
X
Xvoid  get_input(des,val)
X      int des;
X      char *val;
X
X{/*  get a byte from the input descriptor */
X
X   do
X   {
X     while(read(des,val,1) != 1);
X     if(*val == '\012')
X	 redraw_screen();
X     if(*val == 'F')  /*  quitting  */
X	 really();
X    }
X    while (*val == '\012' );
X
X}/* get i/p  */
X
X
X
Xget_SDB(source,choice)
X      int   source;
X      char  *choice;
X
X{
X   do
X      get_input(source,choice);
X   while(*choice != 's' &&
X	 *choice != 'd' &&
X	 *choice != 'b');
X
X}/* get SDB */
X
X
X
X
Xget_RCD(source,choice,turn)
X      int   source;
X      char  *choice;
X      int   turn;
X
X{
X   do
X      get_input(source,choice);
X   while((*choice != 'r' && turn != 6) &&
X	 *choice != 'd' &&
X	 *choice != 'c');
X
X}/* get RCD */
X
X
X
Xget_increment(source,amount)
X      int  source;
X      int  *amount;
X
X/* This gets the bet value, as multiples of 5 units */
X{
X   char amt;
X
X   do
X     get_input(source,&amt);
X   while (amt < '1' || amt > '5');
X
X   *amount = ((amt - '0') * 5);
X
X}
X
X
Xget_user_changes(source,reject,exchange)
X
X       int    source;
X       int    *reject;
X       int    *exchange;
X
X/* Get the cards to be rejected by the user */
X
X{
X       int  no_of_cards,complete,count,ok,value;
X       char choice;
X
X       ask_which();
X
X       no_of_cards = 0;
X       complete = 0;
X       choice = ' ';
X
X       do
X       {
X	   do
X	     get_input(source,&choice);
X	   while ((choice < '1' || choice > '5') && 
X		   choice != '\n' && choice != '\b' && choice != '\177');
X	      
X		switch (choice) {
X
X		case '\n' :  complete = 1;
X                             *reject = no_of_cards;
X			     break;
X		case '\b' :  case '\177' :
X			     delete_line();
X		             no_of_cards = 0;
X			     break;
X		default : if(no_of_cards < 3)
X			    {
X			      value = choice - '1';
X			      ok = 1;
X			      for(count=0;count<no_of_cards;count++)
X				if(value == exchange[count])
X				     ok = 0;
X
X			      if(ok)
X				 {
X			         show_choice(choice,no_of_cards);
X			         exchange[no_of_cards++] = value;
X				 }
X			    }
X
X		}/* switch */
X
X       }
X       while(!complete);
X
X
X}/*get_users_changes*/
END_OF_FILE
if test 2091 -ne `wc -c <'input.c'`; then
    echo shar: \"'input.c'\" unpacked with wrong size!
fi
# end of 'input.c'
fi
if test -f 'p_deal.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'p_deal.c'\"
else
echo shar: Extracting \"'p_deal.c'\" \(3518 characters\)
sed "s/^X//" >'p_deal.c' <<'END_OF_FILE'
X#include "poker.h"
X
Xstatic playing_card  standard[DECK_SIZE];
X/* a template of the unshuffled pack */
X
Xstatic playing_card  deck[DECK_SIZE];
Xstatic int  top_of_pack;
X/* These are for the pack used to deal from */
X
X
Xlong rand();
X
X
Xopen_pack(packptr)
X
X    playing_card *packptr; 
X
X   /* This function initialises the deck of cards */
X{
X
X   int suit_count,face_count,card;
X
X   for(suit_count=0;suit_count<4;suit_count++)
X
X     for (face_count=1;face_count<14;face_count++)
X     {
X
X       card = (suit_count * 13) + face_count - 1;
X
X       packptr[card].face_value= face_count;
X       packptr[card].suit_value= suit_count;
X
X       switch (face_count) {
X	    case 1 : packptr[card].face = 'A';
X		     break;
X		     
X	    case 10: packptr[card].face = 'T';
X		     break;
X		     
X	    case 11: packptr[card].face = 'J';
X		     break;
X		     
X	    case 12: packptr[card].face = 'Q';
X		     break;
X		     
X	    case 13: packptr[card].face = 'K';
X		     break;
X		     
X	    default: packptr[card].face = ('0' + face_count); 
X		    
X	    }
X	
X	switch (suit_count) {
X	    case 0 : packptr[card].suit = 'H';
X		     break;
X
X	    case 1 : packptr[card].suit = 'C';
X		     break;
X
X	    case 2 : packptr[card].suit = 'S';
X                     break;
X
X	    case 3 : packptr[card].suit = 'D';
X
X	    }
X	
X       }
X   
X} /* open_pack */
X
X
X
Xinitialise_cards()
X
X     /* create an unshuffled static pack */
X{
X   open_pack(standard);
X
X}/*initialise_cards*/
X
X
Xnew_deal()
X
X   /* create a new pack, that can be manipulated	*/
X{
X   int count;
X
X   for(count=0;count < DECK_SIZE;count++)
X       deck[count] = standard[count];
X   
X
X}/* new_deal */
X   
X
X
Xvoid swap(a,b)
X     playing_card *a,*b;
X
X/* swap two cards around */
X{
X     playing_card temp;
X
X     temp = *a;
X     *a = *b;
X     *b = temp;
X
X}/* swap */
X
X
X
X
Xshuffle_pack()
X
X
X   /* This function will shuffle the deck that is used for manipulation	*/
X{
X
X   int count1,count2,swap_with;
X
X/* The pack is shuffled 500 times. The higher this value the more random */
X/* is the pack, but it is slower between deals */
X
X   for (count1=0;count1<500;count1++) {
X	  for (count2=0; count2<DECK_SIZE ;count2++) {
X	       swap_with = rand()%DECK_SIZE;
X	       swap(&deck[count2],&deck[swap_with]);
X	  }
X    }
X} /* shuffle_pack */
X
X
X
Xvoid sort(hand)
X     playing_card *hand;
X
X/* Sort the hand of cards */
X{
X   int count1,count2,smallest;
X
X   for (count1=0;count1 < HAND_SIZE -1;++count1)
X   {
X       smallest=count1;
X       for (count2=(count1 + 1) ;count2 < HAND_SIZE;++count2)
X	    if ((hand[count2].face_value < hand[smallest].face_value) ||
X                ((hand[count2].face_value == hand[smallest].face_value) &&
X                (hand[count2].suit < hand[smallest].suit)))
X
X	       smallest = count2;
X
X	if (smallest != count1)
X	    swap ((hand + count1),(hand + smallest));
X
X     }
X
X}/* sort */
X
X
X
X
Xdeal_two_hands(you,me)
X	playing_card *you,*me;
X
X{
X    /* deal out hands to YOU & ME from deck , starting at top_of_pack */
X
X    int count;
X
X    shuffle_pack();
X    top_of_pack = 0;
X
X    for (count=0;count< HAND_SIZE; top_of_pack += 2, count++)
X	{ you[count] = deck[top_of_pack];
X	  me[count] = deck[top_of_pack + 1];
X	}
X
X     sort(you);
X     sort(me);
X
X} /* deal_two_hands */
X
X
X
Xvoid  re_deal(hand,needs)
X
X      playing_card  *hand;
X      describe   needs;
X
X/* overwrite the cards that a player wants to change, by taking cards */
X/* from top of deck */
X{
X
X  int count;
X
X  for(count = 0;count<needs.reject;count++)
X     hand[needs.exchange[count]] = deck[top_of_pack++];
X
X  sort(hand);
X
X  
X}/* re-deal */
END_OF_FILE
if test 3518 -ne `wc -c <'p_deal.c'`; then
    echo shar: \"'p_deal.c'\" unpacked with wrong size!
fi
# end of 'p_deal.c'
fi
if test -f 'poker.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'poker.h'\"
else
echo shar: Extracting \"'poker.h'\" \(1183 characters\)
sed "s/^X//" >'poker.h' <<'END_OF_FILE'
X/*******************************************************/
X/* This must be altered to the location of the rules  */
X/* file, and the paging method used, e.g. more.	       */
X/*******************************************************/
X
X#define INSTRUCTIONS "/usr/ucb/more /usr/games/lib/poker_rules"
X
X/*  Leave the rest  */
X
X#include <stdio.h>
X#define HAND_SIZE 5
X#define DECK_SIZE 52
X
Xtypedef struct{ /* This is the structure of a single card */
X
X		char face;
X		char suit;
X		int  face_value;
X		int  suit_value;
X
X              } playing_card;
X
Xtypedef struct{/*  what is a flush made of */
X
X		 int  flush_of;  /* length of flush */
X		 int  cards[HAND_SIZE]; /* cards in flush */
X
X	      }  flush;
X
Xtypedef struct{/* pairs etc. */
X
X		 int  p_type;
X		 int  no_of_cards;
X		 int  cards[HAND_SIZE];
X
X	      }  prile;
X
Xtypedef struct{/* partial runs */
X
X		  int  length;
X		  int  card[HAND_SIZE];
X		  int  open_str;
X
X	      } run;
X
Xtypedef struct{/* high cards >= 10 */
X
X		  int  number;
X		  int  cards[HAND_SIZE];
X
X	      } high;
X
Xtypedef struct{/* hand description */
X
X		  int  hand_value;
X		  int  reject;
X		  int  exchange[3];  /* max number of cards to exchange */
X
X	      } describe;
X
X	
END_OF_FILE
if test 1183 -ne `wc -c <'poker.h'`; then
    echo shar: \"'poker.h'\" unpacked with wrong size!
fi
# end of 'poker.h'
fi
if test -f 'poker_rules' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'poker_rules'\"
else
echo shar: Extracting \"'poker_rules'\" \(4373 characters\)
sed "s/^X//" >'poker_rules' <<'END_OF_FILE'
X
X                       _R_u_l_e_s _o_f _P_o_k_e_r
X
X
X     This version of Poker, plays Five Card Draw Poker, with
Xno  wild  cards.   The game is played between two opponents,
Xalthough any reasonable number can usually play.  A standard
Xpack of 52 cards is used, Aces high, 2's low.
X
X     Poker is a gambling game, so each player  is  given  an
Xinitial  stake  of 300.  To ensure that betting does not get
Xunreasonably out of hand, bets are limited to  multiples  of
X5,  between  5 and 25, and there is a maximum of six bets or
Xraises allowed, after which, one player must stop  the  bet-
Xting by Calling.
X
X     At the start of each deal, each player must put an _a_n_t_e
Xof  5  units, into the _p_o_t.  This is to ensure that there is
Xalways some money at stake, as an incentive to play.
X
X     Each player is dealt five cards.   The  object  of  the
Xgame  is  to win the contents of the pot, with the best hand
Xof cards.  There are two rounds of betting (adding money  to
Xthe  pot).   The  betting  choices available to a player are
Xexplained below, and are the same in each round,  but  after
Xthe  first round of betting, a maximum of three cards can be
Xdiscarded from the hand, and replaced, in order  to  improve
Xit.   The  second  round of betting then takes place, and at
Xthe end of this, the person with the best hand wins the pot.
X
X     When betting, the person who goes first has the choices:
X
Xa)   Bet : add money to the pot, which the other player will
X     have to equal.
X
Xb)   Drop : Throw in your hand, adding no  more  money,  and
X     automatically lose the pot.
X
Xc)   Stay : Do nothing, and see what the opponent does.   In
X     this case the opponent will get these same options.  If
X     s/he chooses to stay as well, then both hands are  dis-
X     carded,  and  two new ones dealt.  The pot is left, but
X     there is another ante, for the new hand, added to it.
X
X     If the first player chooses to Bet, then on each subse-
Xquent player's turn, the options are :
X
Xa)   Drop : as above, losing automatically.
X
Xb)   Raise : equal the last bet and add more  to  it.   This
X     option is not allowed after a certain number of bets.
X
Xc)   Call : equal the last bet, then compare hands with  the
X     opponent to see who wins the pot.
X
X
XIf a player chooses to drop, he does not reveal the cards he
Xheld.
X
X     The order of the hands, used to determine who wins,  is:
X
X
X          Hand value :-
X
X        Royal Flush        :  a Straight Flush in Hearts.
X        Straight Flush     :  a sequence of five cards in the same suit, 
X			      Ace may count as high or low for this.
X        Four of a Kind     :  a hand containing four cards of the same rank.
X                              Four Aces is highest, 2's lowest.
X        Full House         :  a hand containing 3 cards of one rank, and two 
X			      of another. The rank of the three card set 
X			      determines the better Full House.
X        Flush              :  a hand containing five cards of the same suit.
X        Straight           :  a sequence of five cards, in any suit.
X        Three of a Kind    :  a hand containing three cards of the same rank.
X        Two pair           :  a hand containing two cards of one rank, and 
X			      two of another. The highest pair determines
X			      precedence. If the same, the low pair does, 
X			      else the fifth card.
X        Pair               :  a hand containing two cards of the same rank.
X                              The highest pair wins, and if the same, the 
X			      highest remaining card decides.
X        High card          :  an assortment of cards that does not satisy 
X			      any of the above. The highest card determines 
X			      precedence, if the same, then the next and so on.
X
X
X
XIn the unlikely event of a draw, the pot will be  untouched,
Xand another hand played.
X
X     Each player is allowed to build up a deficit  (a  negative
Xstake)  during one hand. This is the equivalent of accepting
Xcollateral to cover a bet, and prevents a player from being forced
Xout through lack of money. Any player on, or less than, zero 
Xat the start of a deal has lost the overall game. The game will 
Xthen restart, after informing the player of this.
X
X
XExtra Commands Available :
X
X		<cntrl>R   redraws screen
X		<cntrl>C   escape from game.
X		F	   escape from game.
X
X
X------Press Space to continue-----------------------
X
X
END_OF_FILE
echo shar: 19 control characters may be missing from \"'poker_rules'\"
if test 4373 -ne `wc -c <'poker_rules'`; then
    echo shar: \"'poker_rules'\" unpacked with wrong size!
fi
# end of 'poker_rules'
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