[comp.sources.games] v06i045: bj2 - blackjack game

games@tekred.CNA.TEK.COM (04/06/89)

Submitted-by: Nathan Glasser <nathan@eddie.mit.edu>
Posting-number: Volume 6, Issue 45
Archive-name: bj2

	[Once again, two implementations arrive within days of each other.
	 They both have their advantages, so I'm posting both of them.  The first
	 one has a cute curses interface that draws little cards and prompts
	 you with the proper move when it thinks you've made a bad decision.
	 This version has configuration files for the rules specific to
	 several Las Vegas casinos and also has a makefile for Unix and MS-DOS. -br]

[from the author:]
[[Bj is a Blackjack game which fully supports all available options to
the player from a great many Las Vegas casinos. Bj allows many
different command line options so as to be able to specify the rules
corresponding to many different casinos.

Bj was developed independently of any other Blackjack games which were
posted in the past, in spite of possible naming similarities. (What
else is anyone going to name a blackjack game?)]]

#! /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 1 (of 1)."
# Contents:  README ballys.bat barbary.bat bj.c bj.doc bj.h bjalias.txt
#   caesars.bat flamingo.bat horsesho.bat makefile.dos makefile.unx
#   readme.doc shuffle.c stardust.bat
# Wrapped by billr@saab on Wed Apr  5 17:10:46 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1025 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
Xreadme.doc file for	BJ - Las Vegas Blackjack Version 1.0		4/89
X==============================================================================
XFiles included:
Xbj.c			source
Xshuffle.c		source
Xbj.h			source
Xbj.doc			documentation
Xreadme.doc		this file
Xmakefile.unx		makefile (unix)
Xmakefile.dos		makefile (ibm-pc/ms-dos)
Xbjalias.txt		casino aliases (unix)
Xballys.bat		casino batch file (ibm-pc/ms-dos)
Xbarbary.bat		casino batch file (ibm-pc/ms-dos)
Xcaesars.bat		casino batch file (ibm-pc/ms-dos)
Xflamingo.bat		casino batch file (ibm-pc/ms-dos)
Xhorseshoe.bat		casino batch file (ibm-pc/ms-dos)
Xstardust.bat		casino batch file (ibm-pc/ms-dos)
X
XCompiling information
X==============================================================================
XThis program is known to compile on 4.3bsd Unix, and under MS-DOS
Xusing MSC 5.0. It should probably work on almost any system with
Xalmost any C compiler.
X
XIf you wish to adjust the default values of the options, they are
Xnear the top of bj.c, though they're probably acceptable as is.
END_OF_FILE
if test 1025 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'ballys.bat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ballys.bat'\"
else
echo shar: Extracting \"'ballys.bat'\" \(20 characters\)
sed "s/^X//" >'ballys.bat' <<'END_OF_FILE'
Xcaesars %1 %2 %3 %4
END_OF_FILE
if test 20 -ne `wc -c <'ballys.bat'`; then
    echo shar: \"'ballys.bat'\" unpacked with wrong size!
fi
# end of 'ballys.bat'
fi
if test -f 'barbary.bat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'barbary.bat'\"
else
echo shar: Extracting \"'barbary.bat'\" \(48 characters\)
sed "s/^X//" >'barbary.bat' <<'END_OF_FILE'
Xbj -m3 -n2 -p66 -t0 -h0 -d1 -r1 -l0 %1 %2 %3 %4
END_OF_FILE
if test 48 -ne `wc -c <'barbary.bat'`; then
    echo shar: \"'barbary.bat'\" unpacked with wrong size!
fi
# end of 'barbary.bat'
fi
if test -f 'bj.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bj.c'\"
else
echo shar: Extracting \"'bj.c'\" \(10827 characters\)
sed "s/^X//" >'bj.c' <<'END_OF_FILE'
X/* bj.c */
X/*
X			B.J. - Las Vegas Blackjack, Version 1.0
X			by Nathan Glasser
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			April, 1989
X------------------------------------------------------------------------------
XCopyright 1989 by Nathan Glasser.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X*/
X
X#include "bj.h"
X
XCARDINFO cardinfo[] =
X{ {1,'A'}, {2,'2'}, {3,'3'}, {4,'4'}, {5,'5'}, {6,'6'}, {7,'7'},
X  {8,'8'}, {9,'9'}, {10,'T'}, {10,'J'}, {10,'Q'}, {10,'K'}};
X
X#define ACE 0
X
XCARD *deck;
XCARD *cardptr;
X
Xdouble bet;
Xdouble last_bet;
X
Xchar inpstring[80];
X
X
X/* Options */
Xdouble money = 100.0,
X       table_min = 3.0;
Xint num_decks = 6,
X    reshuffle_percentage = 66,
X    ten_check = 0,
X    hit_soft17 = 0,
X    double_split = 1,
X    resplit_pair = 1,
X    late_surrender = 1,
X    show_burn = 0,
X    show_pct = 1;
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X    process_args(argc,argv);
X
X    init_decks();
X
X    last_bet = money / 100.0;
X    if (last_bet < table_min)
X    	last_bet = table_min;
X
X    for (;;)
X    {
X	check_shuffle();
X
X	printf("\nMoney = $%.2lf; Enter your bet [%.2lf]: ",money,last_bet);
X	fgets(inpstring,80,stdin);
X	if (sscanf(inpstring,"%lf",&bet) < 1)
X	    bet = last_bet;
X        else
X	    last_bet = bet;
X	if (bet < table_min)
X	{
X	    printf("Illegal bet. Table minimum is $%.2lf.\n",table_min);
X	    continue;
X	}
X	money -= bet;
X	play_hand();
X    }
X}
X
X#define H_BJ_UTIL(c1,c2) (c1 == ACE && cardinfo[c2].bj_val == 10)
X#define HAS_BJ(c1,c2) (H_BJ_UTIL(c1,c2) || H_BJ_UTIL(c2,c1))
X
X#define MAX_SPLITS 10
X/* Note that all bets are subtracted from your money as soon as they
Xare made. */
Xplay_hand()
X{
X    CARD dealer_up,dealer_down;
X    CARD player_1,player_2;
X    CARD tmp;
X    int dealer_has_bj,player_has_bj;
X    int hand_totals[MAX_SPLITS];
X    int doubled_down[MAX_SPLITS];
X    int num_hands = 1;
X    int hand_num;
X    int got_ace,hit_already;
X    char response;
X    int didnt_bust = 0;
X    int dealer_total,dealer_got_ace;
X    int surrendered = 0;
X
X    player_1 = *cardptr++;
X    dealer_up = *cardptr++;
X    player_2 = *cardptr++;
X    dealer_down = *cardptr++;
X
X    printf("Dealer shows:\t%c ?\n",cardinfo[dealer_up].display_char);
X    printf("\nYou have:\t%c %c\n",
X	   cardinfo[player_1].display_char,cardinfo[player_2].display_char);
X    dealer_has_bj = HAS_BJ(dealer_up,dealer_down);
X    player_has_bj = HAS_BJ(player_1,player_2);
X    if (dealer_up == ACE)
X    {
X	printf("Do you wish to buy insurance? [n]: ");
X	fgets(inpstring,80,stdin);
X	if (sscanf(inpstring,"%1s",&response) < 1)
X	    response = 'n';
X	if (response == 'Y')
X	    response = 'y';
X	if (response == 'y')
X	    money -= 0.5 * bet;
X	if (dealer_has_bj)
X	{
X	    printf("Dealer's down card was %c -- Blackjack.\n",
X		   cardinfo[dealer_down].display_char);
X	    if (response == 'y')
X	    {
X		printf("Your insurance pays off.\n");
X		money += 1.5 * bet;
X	    }
X	    if (player_has_bj)
X	    {
X	    	printf("Since you also have Blackjack, you push.\n");
X	        money += bet;
X	    }
X	    return;
X	}
X	printf("No Blackjack.\n");
X    }
X    else if (cardinfo[dealer_up].bj_val == 10 && ten_check)
X    {
X        if (dealer_has_bj)
X	{
X	    printf("Dealer's down card was A -- Blackjack.\n");
X	    if (player_has_bj)
X	    {
X	    	printf("Since you also have Blackjack, you push.\n");
X		money += bet;
X	    }
X	    return;
X	}
X	printf("No Blackjack.\n");
X    }
X    if (player_has_bj)
X    {
X    	printf("You have Blackjack.\n");
X	if (dealer_has_bj)	/* Up card must be a 10 of some sort */
X	{
X	    printf("Dealer's down card was A.");
X	    printf(" Dealer has Blackjack, so you push.\n");
X	    money += bet;
X	    return;
X	}
X	printf("Dealer's down card was %c.\n",
X	  cardinfo[dealer_down].display_char);
X	money += bet * 2.5;
X	return;
X    }
X    
X
X    for (hand_num = 0; hand_num < num_hands; hand_num++)
X    {
X    	if (num_hands > 1)
X	{
X	    player_2 = *cardptr++;
X	    printf("Hand %d: You have %c and are dealt %c.\n",hand_num + 1,
X	      cardinfo[player_1].display_char,
X	      cardinfo[player_2].display_char);
X	}
X
X    	got_ace = player_1 == ACE || player_2 == ACE;
X	hit_already = 0;
X	hand_totals[hand_num] = cardinfo[player_1].bj_val +
X	  cardinfo[player_2].bj_val;
X	doubled_down[hand_num] = 0;
X
X	/* Only one card and no further splitting if you split Aces. */
X	if (num_hands > 1 && player_1 == ACE)
X	{
X	    if (hand_totals[hand_num] < 12)
X	    	hand_totals[hand_num] += 10;
X	    didnt_bust = 1;
X	    continue;
X	}
X
X	for (;;)
X	{
X	    printf("Your options are H(Hit), S(Stand)");
X	    if (!hit_already)
X	    {
X	    	if (num_hands == 1 || double_split)
X		    printf(", D(Double Down)");
X		if (player_1 == player_2 && (num_hands == 1 || resplit_pair))
X		    printf(", P(Split)");
X		if (num_hands == 1 && late_surrender)
X		    printf(", L(Late Surrender)");
X	    }
X	    printf(": ");
X	    do
X	    	fgets(inpstring,80,stdin);
X	    while (sscanf(inpstring,"%1s",&response) < 1);
X	    if (isupper(response))
X	    	response = tolower(response);
X
X	    switch (response)
X	    {
X	    	case 'h':
X		    hit_already = 1;
X		    if ((tmp = *cardptr++) == ACE)
X		    	got_ace = 1;
X		    printf("You get:\t%c\n",cardinfo[tmp].display_char);
X		    if ((hand_totals[hand_num] += cardinfo[tmp].bj_val) > 21)
X		    {
X		    	printf("Your total is %d -- you busted.\n",
X			  hand_totals[hand_num]);
X			break;
X		    }
X		    continue;
X		case 'd':
X		    if (hit_already || num_hands > 1 && !double_split)
X		    {
X		    	printf("Bad option.\n");
X			continue;
X		    }
X		    money -= bet;
X		    doubled_down[hand_num] = 1;
X		    if ((tmp = *cardptr++) == ACE)
X		    	got_ace = 1;
X		    printf("You get:\t%c\n",cardinfo[tmp].display_char);
X		    if ((hand_totals[hand_num] += cardinfo[tmp].bj_val) > 21)
X		    {
X		    	printf("Your total is %d -- you busted.\n",
X			  hand_totals[hand_num]);
X			break;
X		    }
X		    /* fall through... */
X		case 's':
X		    if (got_ace && hand_totals[hand_num] < 12)
X		    	hand_totals[hand_num] += 10;
X		    didnt_bust = 1;
X		    break;
X		case 'p':
X		    if (hit_already || player_1 != player_2 ||
X		      num_hands > 1 && !resplit_pair)
X		    {
X		    	printf("Bad option.\n");
X			continue;
X		    }
X		    num_hands++;
X		    hand_num--;
X		    money -= bet;
X		    break;
X		case 'l':
X		    if (hit_already || num_hands > 1 || !late_surrender)
X		    {
X		    	printf("Bad option.\n");
X			continue;
X		    }
X		    money += bet / 2.0;
X		    surrendered = 1;
X		    break;
X		default:
X		    printf("Bad option.\n");
X		    continue;
X	    }
X
X	    break;
X	}
X    }
X
X    if (dealer_has_bj)
X    {
X    	double tmp = 0;
X
X	printf("Dealer's down card was A. Dealer had Blackjack all along.\n");
X	for (hand_num = 0; hand_num < num_hands; hand_num++)
X	{
X	    if (hand_num > 1)
X	    	tmp += bet;
X	    if (doubled_down[hand_num])
X	    	tmp += bet;
X	}
X	money += tmp;
X	if (tmp > 0.0)
X	    printf("$%.2lf has been returned to you.\n",tmp);
X	if (surrendered)
X	    money -= bet / 2.0;
X	return;
X    }
X
X    if (!didnt_bust)
X    {
X	printf("Dealer's down card was %c.\n",
X	  cardinfo[dealer_down].display_char);
X	return;
X    }
X
X    dealer_got_ace = dealer_up == ACE || dealer_down == ACE;
X    dealer_total = cardinfo[dealer_up].bj_val + cardinfo[dealer_down].bj_val;
X    printf("Dealer:\t\t(%c) %c",cardinfo[dealer_up].display_char,
X      cardinfo[dealer_down].display_char);
X    for (;;)
X    {
X	if (dealer_total >= 17 || dealer_got_ace && dealer_total < 12 && 
X	  (dealer_total >= 8 || !hit_soft17 && dealer_total == 7))
X	    break;
X	tmp = *cardptr++;
X	printf(" %c",cardinfo[tmp].display_char);
X	dealer_total += cardinfo[tmp].bj_val;
X	if (dealer_total > 21)
X	    break;
X    }
X    if (dealer_total < 12)
X    	dealer_total += 10;
X    printf(" -> %d",dealer_total);
X    if (dealer_total > 21)
X    	printf(" -- busted");
X    printf(".\n");
X
X    for (hand_num = 0; hand_num < num_hands; hand_num++)
X    {
X    	if (num_hands > 1)
X	    printf("Hand %d:\t\t",hand_num + 1);
X	if (hand_totals[hand_num] > 21)
X	    printf("busted.\n");
X	else
X	{
X	    printf("Your total:\t%d -- you ",hand_totals[hand_num]);
X	    if (hand_totals[hand_num] > dealer_total || dealer_total > 21)
X	    {
X	    	printf("win.\n");
X		money += 2.0 * bet;
X		if (doubled_down[hand_num])
X		    money += 2.0 * bet;
X	    }
X	    else if (hand_totals[hand_num] == dealer_total)
X	    {
X	    	printf("push.\n");
X		money += bet;
X		if (doubled_down[hand_num])
X		    money += bet;
X	    }
X	    else
X	    	printf("lose.\n");
X	}
X    }
X}
X
Xprocess_args(argc,argv)
Xint argc;
Xchar **argv;
X{
X    int tmp;
X    char *rest;
X#ifndef MSDOS
X    double atof();
X#endif
X
X    while (++argv,--argc)
X    {
X    	if (argv[0][0] != '-' && argv[0][0] != '/' || strlen(argv[0]) < 3)
X	    show_usage();
X
X	if (isupper(tmp = argv[0][1]))
X	    tmp = tolower(tmp);
X
X	rest = &argv[0][2];
X
X	switch (tmp)
X	{
X	    case 'b':	/* money */
X	    	money = atof(rest);
X		break;
X	    case 'm':	/* table minimum */
X	    	table_min = atof(rest);
X		break;
X	    case 'n':	/* number of decks */
X	    	num_decks = atoi(rest);
X		break;
X	    case 'p':	/* pct after which to reshuffle */
X	    	reshuffle_percentage = atoi(rest);
X		break;
X	    case 't':	/* check for bj on tens */
X	    	ten_check = atoi(rest);
X		break;
X	    case 'h':	/* hit on soft 17's */
X	    	hit_soft17 = atoi(rest);
X		break;
X	    case 'd':	/* allow doubling down after splitting */
X	    	double_split = atoi(rest);
X		break;
X	    case 'r':	/* allow resplitting */
X	    	resplit_pair = atoi(rest);
X		break;
X	    case 'l':	/* allow late surrendering */
X	    	late_surrender = atoi(rest);
X		break;
X	    case 'c':	/* show burned card */
X	    	show_burn = atoi(rest);
X		break;
X	    case 's':	/* show remaining deck */
X	    	show_pct = atoi(rest);
X		break;
X	    default:
X	    	show_usage();
X	}
X    }
X}
X
Xshow_usage()
X{
X    printf("Usage: bj [-b<num>] [-m<num>] [-n<num>] [-p<num>] [-t<bit>]\n");
X    printf("          [-h<bit>] [-d<bit>] [-r<bit>] [-l<bit>] [-c<bit>]\n");
X    printf("          [-s<bit>]\n");
X    printf("-b: Specify starting bankroll [%.2lf].\n",money);
X    printf("-m: Specify minimum bet allowed [%.2lf].\n",table_min);
X    printf("-n: Specify number of decks [%d].\n",num_decks);
X    printf("-p: Specify percentage of cards after which to reshuffle [%d].\n",
X      reshuffle_percentage);
X    printf("-t: Whether dealer checks for Blackjack on tens [%d].\n",
X      ten_check);
X    printf("-h: Whether dealer hits on soft 17's [%d].\n",hit_soft17);
X    printf("-d: Whether player can double down after splitting [%d].\n",
X      double_split);
X    printf("-r: Whether player can split more than once [%d].\n",
X      resplit_pair);
X    printf("-l: Whether player can late surrender on two cards [%d].\n",
X      late_surrender);
X    printf("-c: Whether to show all burned cards [%d].\n",show_burn);
X    printf("-s: Whether to show the portion of the deck remaining [%d].\n",
X      show_pct);
X    exit(1);
X}
END_OF_FILE
if test 10827 -ne `wc -c <'bj.c'`; then
    echo shar: \"'bj.c'\" unpacked with wrong size!
fi
# end of 'bj.c'
fi
if test -f 'bj.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bj.doc'\"
else
echo shar: Extracting \"'bj.doc'\" \(10895 characters\)
sed "s/^X//" >'bj.doc' <<'END_OF_FILE'
X			B.J. - Las Vegas Blackjack, Version 1.0
X			by Nathan Glasser
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			April, 1989
X------------------------------------------------------------------------------
XCopyright 1989 by Nathan Glasser.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X==============================================================================
XBj is a Blackjack game (single player) which implements almost every
Xfeature to be found at Blackjack tables in various casinos in Las
XVegas.
X
XThere are a large number of options for controlling these features;
Xby using particular sets of these options you can emulate the rules
Xof your favorite casino, or you can simply use the default settings.
X
XAt the end of this document is a description of what Blackjack is,
Xin case you're unfamiliar.
X
XPlease send any comments or bug reports to me at one of the above e-mail
Xaddresses.
X==============================================================================
XWhat does bj do that other Blackjack games may not do?
X
XBj lets the player specify the number of decks to use for the game,
Xspecify the point at which they are reshuffled, and provides a visual
Xdisplay of how much of the deck remains during play. Bj actually
Xarranges the cards before play so that players who wish to do so may
Xattempt to "count cards" to increase their chances of winning. As in
Xcasinos, the top card of the deck is "burned" immediately after
Xshuffling; these cards may be optionally displayed.
X
XBj allows the player to specify some of the rules under which the
Xdealer plays, to allow for the variations between casinos. Bj will
Xoptionally force the dealer to hit on soft 17, and optionally to
Xcheck to check for Blackjack when a "ten" (ten or picture card) is
Xshowing. (Checking or not checking for Blackjack on tens does not
Xactually change the player's chance of winning. If the dealer does
Xnot check on tens, and a player splits and/or doubles down with a ten
Xshowing, if it turns out that dealer had Blackjack, any additional
Xmoney above the original bet is returned to the player.)
X
XBj allows the player to specify the minimum bet he may place, so that,
Xas at a casion, he can only reduce his bet so much and stay in the game.
XCard counters will thus not be able to "cheat" by betting less than
Xthe minimum. The default bet presented to the player at the start of
Xeach hand is the same as his previous bet. The default bet at the
Xstart of the game will be either 1/100 of his starting bankroll, or
Xthe table minimum, whichever is larger. The player's starting bankroll
Xmay be specified.
X
XBj allows the player to specify some of the options which will be
Xavailable to him at various times in play. Bj will optionally let the
Xplayer double down after splitting, and optionally let the player
Xresplit (split more than once). If resplitting is selected, there is
Xno limit to the number of times a player may split (except that there
Xare only so many of the same card in play). Bj always lets the player
Xdouble down on two cards (when appropriate) without restriction on
Xthe total of the two cards.
X
XBj optionally supports "late surrender". Late surrender is a
Xlittle-known option supported at some major casinos in which you are
Xpermitted to concede the hand and surrender only half of your bet,
Xbut only when you have just your original two cards. If you have hit
Xor split already, you cannot surrender.
X
XBj includes a number of aliases and batch files for running bj with
Xoptions options appropriate to specific casinos.
X
XBj does not support (at least in this version):
X
X  Resplitting aces: It is true at almost all casinos that when you
X  split aces, you get exactly one new card to go with each ace, and
X  your turn is over.
X
X  "6-card Charleys": This is an option that occurs very rarely at casinos.
X
X  Doubling down with more than 2 cards: This is an option that occurs
X  very rarely at casinos.
X==============================================================================
XThe usage of bj is:
X
Xbj [-b<num>] [-m<num>] [-n<num>] [-p<num>] [-t<bit>]
X   [-h<bit>] [-d<bit>] [-r<bit>] [-l<bit>] [-c<bit>]
X   [-s<bit>]
X
XWhere <num> appears you should substitute an appropriate number.
XWhere <bit> appears you should enter a bit, 0 or 1, to turn the option
Xoff or on.
X
XThe command line options and their meanings:
X
X-b: Specify starting bankroll.
X-m: Specify minimum bet allowed.
X-n: Specify number of decks.
X-p: Specify percentage of cards after which to reshuffle.
X-t: Whether dealer checks for Blackjack on tens.
X-h: Whether dealer hits on soft 17's.
X-d: Whether player can double down after splitting.
X-r: Whether player can split more than once.
X-l: Whether player can late surrender on two cards.
X-c: Whether to show all burned cards.
X-s: Whether to show the portion of the deck remaining.
X
XIf an option is not specified, its default value is used. To
Xdetermine the defaults for these options as compiled for your
Xversion, simply run bj with a meaningless argument to receive a usage
Xmessage with all the defaults displayed.
X
X
XWhen playing the game, you'll be asked to enter your bet. Enter your
Xnew bet, or hit return to get the default shown.
X
XWhen the hand has been dealt, simply pick the letter corresponding to
Xthe option displayed you wish to use. Only options legally available
Xto you by the rules of the game and those selected with the command
Xline options will be displayed.
X
XWhen the dealer has an ace showing, you'll be asked if you wish
Xto buy insurance. Simply hit return if you wish to select the
Xdefault answer ("No"). Otherwise enter y.
X
XThe game does not end when you reach $0; you can always get more
Xmoney from your credit card. Use ^C (or on Unix, your interrupt
Xcharacter) to end the game when you're done.
X==============================================================================
XThanks to extensive, expensive research done by #Ron (ronnie@eddie.mit.edu,
Xronnie@mit-eddie.uucp), I've got rules for a number of Las Vegas casinos.
X
XCurrently I've got rules for the Barbary Coast, Bally's, Caesar's Palace,
Xthe Flamingo Hilton, the Horseshoe, and the Stardust.
X
XIf you're on unix, you can use the aliases in the file bjalias.txt to
Xto run bj with the appropriate options for each of these casinos.
XSimply run the command "source alias.txt" to set up the aliases.
X
XIf you're on ms-dos, you can use the batch files (*.bat). There's one
Xbatch file for each casino.
X
XIn either case, all you have to do to use a given casino's rules is
Xtype the name of the casino (or whatever abbreviation was actually
Xpicked). E.g. to use the Barbary Coast rules, simply run "barbary".
X
XNote that the command line options -b (bankroll), -c (burned cards),
Xand -s (deck remaining) are not specified via the aliases and batch
Xfiles. These have nothing to do with the casinos, but rather with
Xwhat the player wants to do. If you wish, any or all of these options
Xmay be used with the predefined commands. E.g. barbary -b50 -c0 -s1.
X==============================================================================
XBlackjack rules summary:
X
XIn Blackjack, also known as 21, the player(s) compete with the dealer
Xto get higher totals of cards without going over 21. 
X
XThe values of the cards are:
X  Tens and picture cards = 10
X  Aces = 1 or 11
X  Spot cards = face value.
X
XThe player and dealer are each dealt two cards, and the first of the
Xdealer's cards is visible (the up card). Based on what cards the
Xplayer holds, and what dealer's up card is, the player has to make a
Xdecision among several options as to what he wants to do to try to
Xwin.
X
XThe options the player has are:
X  Stand: Don't take any more cards on this hand.
X  Hit: Take one more card on this hand. If you're total goes above 21,
X    you've "busted", and this hand has lost, no matter what happens to the
X    dealer.
X  Double Down: If you've got only two cards in this hand, you double
X    your bet and take exactly one more card. You may bust, as with
X    hitting normally. You may or may not be able to double down after
X    splitting (see below), depending on casino rules.
X  Split: If your hands consists of two cards with exactly the same
X    rank, (e.g. two 5's, two J's, two A's) you may split the hand
X    into two hands, each with one of the two cards you held, plus
X    a new one dealt to you. Your bet is doubled, with one bet applying to
X    each hand. Each hand is now independent and is won or lost separately.
X    In the case where the cards split were aces, each ace is given
X    a new card, and the play stops here. No further hitting, splitting,
X    or doubling down is permitted. There may be restrictions to
X    further splitting and doubling down, depending on casino rules.
X    Late surrendering (see below) is not permitted after splitting.
X  Late Surrender: When you have not hit or split yet, i.e. still have
X    your original two cards, you may concede the hand, surrendering
X    only half your bet, rather than playing the hand out and possibly
X    losing your entire bet. Some casinos do not allow this at all.
X
X(Note: a card combination containing an ace in which the score can
Xbe one of two because the ace is worth either 1 or 11, is known as "soft".
XThus the cards A 2 2 would be a soft 15.)
X
XAfter the player(s) have finished their hands, the dealer plays by
Xfollowing a predetermined algorithm. The dealer turns over the down
Xcard. He then continues to hit until his total becomes 17 or higher.
XIf the dealer busts, than all player hands which have not busted win.
XIf a player hand and the dealer have not busted, whichever one has
Xthe higher score wins. If it is a tie, this is known as a push, and
Xthe player's bet is returned. If the player wins, the payoff is 1:1.
X(In some casinos, the dealer must hit if the total is a soft 17.)
X
XException: a two-card combination totalling 21, that is, an ace and a
Xten or picture card, is worth more than any other 21 combination.
XThis is known as a Blackjack. If the player get a Blackjack, and the
Xdealer doesn't, the player wins, and in addition, gets paid 3:2. If
Xthe dealer gets Blackjack, there's no way for the player to win,
Xthough it will still be a push if the player also gets a Blackjack.
X(Note that if you split, and get a "Blackjack", this is not a
XBlackjack. This applies only two your original two cards.)
X
XIf the dealer's down card is an ace, then all players are immediately
Xgiven the option to buy insurance. This means that the player pays
Xout an additional 50% of his original bet. Whether insurance is
Xbought or not, the dealer immediately checks to see whether he has
XBlackjack. If dealer has Blackjack, all players lose their original
Xbets, but those with insurance get their insurance bet back, and get
Xpaid off at 2:1 for this bet. If the dealer does not have Blackjack,
Xthose players who bought insurance lose their insurance bets.
END_OF_FILE
if test 10895 -ne `wc -c <'bj.doc'`; then
    echo shar: \"'bj.doc'\" unpacked with wrong size!
fi
# end of 'bj.doc'
fi
if test -f 'bj.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bj.h'\"
else
echo shar: Extracting \"'bj.h'\" \(744 characters\)
sed "s/^X//" >'bj.h' <<'END_OF_FILE'
X/* bj.h */
X/*
X			B.J. - Las Vegas Blackjack, Version 1.0
X			by Nathan Glasser
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			April, 1989
X------------------------------------------------------------------------------
XCopyright 1989 by Nathan Glasser.
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 <stdlib.h>
X#endif
X
X#define NUM_SUITS 4
X#define NUM_RANKS 13
X
Xtypedef struct {
X    char bj_val;
X    char display_char;
X} CARDINFO;
X
Xtypedef int CARD;
X
X
Xextern CARDINFO cardinfo[];
Xextern CARD *deck;
X
Xextern CARD *cardptr;
X
Xextern int num_decks,reshuffle_percentage,show_burn,show_pct;
END_OF_FILE
if test 744 -ne `wc -c <'bj.h'`; then
    echo shar: \"'bj.h'\" unpacked with wrong size!
fi
# end of 'bj.h'
fi
if test -f 'bjalias.txt' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bjalias.txt'\"
else
echo shar: Extracting \"'bjalias.txt'\" \(312 characters\)
sed "s/^X//" >'bjalias.txt' <<'END_OF_FILE'
X# Aliases for bj for various casinos
Xalias barbary	bj -m3 -n2 -p66 -t0 -h0 -d1 -r1 -l0
Xalias ballys	caesars
Xalias caesars	bj -m3 -n6 -p66 -t0 -h0 -d1 -r1 -l1
Xalias flamingo	bj -m3 -n2 -p66 -t0 -h0 -d0 -r1 -l0
Xalias horseshoe	bj -m1 -n1 -p58 -t1 -h1 -d0 -r1 -l0
Xalias stardust	bj -m3 -n2 -p66 -t1 -h0 -d0 -r1 -l0
END_OF_FILE
if test 312 -ne `wc -c <'bjalias.txt'`; then
    echo shar: \"'bjalias.txt'\" unpacked with wrong size!
fi
# end of 'bjalias.txt'
fi
if test -f 'caesars.bat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'caesars.bat'\"
else
echo shar: Extracting \"'caesars.bat'\" \(48 characters\)
sed "s/^X//" >'caesars.bat' <<'END_OF_FILE'
Xbj -m3 -n6 -p66 -t0 -h0 -d1 -r1 -l1 %1 %2 %3 %4
END_OF_FILE
if test 48 -ne `wc -c <'caesars.bat'`; then
    echo shar: \"'caesars.bat'\" unpacked with wrong size!
fi
# end of 'caesars.bat'
fi
if test -f 'flamingo.bat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'flamingo.bat'\"
else
echo shar: Extracting \"'flamingo.bat'\" \(48 characters\)
sed "s/^X//" >'flamingo.bat' <<'END_OF_FILE'
Xbj -m3 -n2 -p66 -t0 -h0 -d0 -r1 -l0 %1 %2 %3 %4
END_OF_FILE
if test 48 -ne `wc -c <'flamingo.bat'`; then
    echo shar: \"'flamingo.bat'\" unpacked with wrong size!
fi
# end of 'flamingo.bat'
fi
if test -f 'horsesho.bat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'horsesho.bat'\"
else
echo shar: Extracting \"'horsesho.bat'\" \(48 characters\)
sed "s/^X//" >'horsesho.bat' <<'END_OF_FILE'
Xbj -m1 -n1 -p58 -t1 -h1 -d0 -r1 -l0 %1 %2 %3 %4
END_OF_FILE
if test 48 -ne `wc -c <'horsesho.bat'`; then
    echo shar: \"'horsesho.bat'\" unpacked with wrong size!
fi
# end of 'horsesho.bat'
fi
if test -f 'makefile.dos' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.dos'\"
else
echo shar: Extracting \"'makefile.dos'\" \(516 characters\)
sed "s/^X//" >'makefile.dos' <<'END_OF_FILE'
X# Makefile (ibm-pc/ms-dos) for
X#			B.J. - Las Vegas Blackjack, Version 1.0
X#			by Nathan Glasser
X#			nathan@brokaw.lcs.mit.edu (internet)
X#			nathan@mit-eddie.uucp (usenet)
X#
X#			April, 1989
X#-----------------------------------------------------------------------------
X#Copyright 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
XCFLAGS = -Ox
X
XOBJS = bj.obj shuffle.obj
X
Xbj.exe:	$(OBJS)
X	$(CC) -o bj $(OBJS)
X
X$(OBJS):	bj.h
END_OF_FILE
if test 516 -ne `wc -c <'makefile.dos'`; then
    echo shar: \"'makefile.dos'\" unpacked with wrong size!
fi
# end of 'makefile.dos'
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'\" \(495 characters\)
sed "s/^X//" >'makefile.unx' <<'END_OF_FILE'
X# Makefile (unix) for
X#			B.J. - Las Vegas Blackjack, Version 1.0
X#			by Nathan Glasser
X#			nathan@brokaw.lcs.mit.edu (internet)
X#			nathan@mit-eddie.uucp (usenet)
X#
X#			April, 1989
X#-----------------------------------------------------------------------------
X#Copyright 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
XCFLAGS = -O
X
XOBJS = bj.o shuffle.o
X
Xbj:	$(OBJS)
X	cc -o bj $(OBJS)
X
X$(OBJS):	bj.h
END_OF_FILE
if test 495 -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'\" \(1025 characters\)
sed "s/^X//" >'readme.doc' <<'END_OF_FILE'
Xreadme.doc file for	BJ - Las Vegas Blackjack Version 1.0		4/89
X==============================================================================
XFiles included:
Xbj.c			source
Xshuffle.c		source
Xbj.h			source
Xbj.doc			documentation
Xreadme.doc		this file
Xmakefile.unx		makefile (unix)
Xmakefile.dos		makefile (ibm-pc/ms-dos)
Xbjalias.txt		casino aliases (unix)
Xballys.bat		casino batch file (ibm-pc/ms-dos)
Xbarbary.bat		casino batch file (ibm-pc/ms-dos)
Xcaesars.bat		casino batch file (ibm-pc/ms-dos)
Xflamingo.bat		casino batch file (ibm-pc/ms-dos)
Xhorseshoe.bat		casino batch file (ibm-pc/ms-dos)
Xstardust.bat		casino batch file (ibm-pc/ms-dos)
X
XCompiling information
X==============================================================================
XThis program is known to compile on 4.3bsd Unix, and under MS-DOS
Xusing MSC 5.0. It should probably work on almost any system with
Xalmost any C compiler.
X
XIf you wish to adjust the default values of the options, they are
Xnear the top of bj.c, though they're probably acceptable as is.
END_OF_FILE
if test 1025 -ne `wc -c <'readme.doc'`; then
    echo shar: \"'readme.doc'\" unpacked with wrong size!
fi
# end of 'readme.doc'
fi
if test -f 'shuffle.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shuffle.c'\"
else
echo shar: Extracting \"'shuffle.c'\" \(2328 characters\)
sed "s/^X//" >'shuffle.c' <<'END_OF_FILE'
X/* shuffle.c */
X/*
X			B.J. - Las Vegas Blackjack, Version 1.0
X			by Nathan Glasser
X			nathan@brokaw.lcs.mit.edu (internet)
X			nathan@mit-eddie.uucp (usenet)
X
X			April, 1989
X------------------------------------------------------------------------------
XCopyright 1989 by Nathan Glasser.
XYou may feel free to distribute this program in its current form.
XPlease do not remove this copyright information.
X*/
X
X#include "bj.h"
X
Xstatic int num_cards;
X
X/* Fill the decks with (NUM_SUITS * num_decks) different occurances of
X   each of the numbers from 0 to NUM_RANKS-1. */
Xshuffle_decks()
X{
X    int i,j;
X    int pos;
X    CARD *tmp;
X    int tmp_num = num_cards;
X
X    printf("\n******    SHUFFLING CARDS    ******\n");
X    fflush(stdout);
X
X    for (i = 0; i < tmp_num; i++)
X	deck[i] = -1;
X
X    for (i = 0; i < NUM_RANKS; i++)
X	for (j = NUM_SUITS * num_decks; j > 0; j--)
X	{
X	    pos = rnum(tmp_num);
X	    tmp = deck;
X	    do
X	    {
X		while (*tmp >= 0)
X		    tmp++;
X		tmp++;
X	    }
X	    while (pos--);
X	    tmp[-1] = i;
X	    tmp_num--;
X	}
X
X    cardptr = deck + 1;
X
X    if (show_burn)
X    	printf("\nCard burned: %c\n",cardinfo[*deck].display_char);
X
X#if 0
X    for (i = 0; i < num_cards; i++)
X	printf("%c\t",cardinfo[deck[i]].display_char);
X    putchar('\n');
X#endif
X}
X
Xcheck_shuffle()
X{
X    if (100 * (cardptr - deck) / num_cards >= reshuffle_percentage)
X	shuffle_decks();
X
X    if (show_pct)
X    {
X#define DECK_SPACE 64
X	int i;
X	int limit = 0.5 +
X	  DECK_SPACE * (1.0 - ((double)(cardptr - deck)) / num_cards);
X	int shuf_pt = 0.5 + 
X	  DECK_SPACE * (1.0 - reshuffle_percentage / 100.0);
X
X	printf("Deck remaining: ");
X	for (i = 1; i <= limit; i++)
X	    putchar((i == shuf_pt) ? 'S' : '*');
X	putchar('\n');
X    }
X}
X
X/* Returns a random integer from 0 to max */
X/* This will be very slightly biased in favor of the lower numbers
X   if max isn't a power of 2 */
X#ifndef MSDOS
Xrnum(max)
Xint max;
X{
X    long random();
X    long tmp = random();
X
X    return((int)(tmp % max));
X}
X#else
Xrnum(max)
Xint max;
X{
X    int tmp = rand();
X
X    return((int)(tmp % max));
X}
X#endif
X
Xinit_decks()
X{
X    long time();
X    long tmp;
X
X    tmp = time(NULL);
X#ifndef MSDOS
X    srandom((int)tmp);
X#else
X    srand((int)tmp);
X#endif
X
X    num_cards = NUM_RANKS * NUM_SUITS * num_decks;
X    deck = (CARD *)malloc(sizeof(CARD) * num_cards);
X    cardptr = deck + num_cards;
X}
END_OF_FILE
if test 2328 -ne `wc -c <'shuffle.c'`; then
    echo shar: \"'shuffle.c'\" unpacked with wrong size!
fi
# end of 'shuffle.c'
fi
if test -f 'stardust.bat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'stardust.bat'\"
else
echo shar: Extracting \"'stardust.bat'\" \(48 characters\)
sed "s/^X//" >'stardust.bat' <<'END_OF_FILE'
Xbj -m3 -n2 -p66 -t1 -h0 -d0 -r1 -l0 %1 %2 %3 %4
END_OF_FILE
if test 48 -ne `wc -c <'stardust.bat'`; then
    echo shar: \"'stardust.bat'\" unpacked with wrong size!
fi
# end of 'stardust.bat'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    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