[comp.sources.games] v03i076: miles - another version of Mille Bournes, Part02/02

games-request@tekred.TEK.COM (01/26/88)

Submitted by: Brett K. Carver <hpsrlc!brett@hplabs.HP.COM>
Comp.sources.games: Volume 3, Issue 76
Archive-name: miles/Part02a

	[This got truncated at an awful lot of sites.  -br]

#! /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:  card.c data.c io.c main.c miles.h random.c
# Wrapped by billr@tekred on Wed Jan 20 10:20:50 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f card.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"card.c\"
else
echo shar: Extracting \"card.c\" \(6064 characters\)
sed "s/^X//" >card.c <<'END_OF_card.c'
X/* card.c */
X/* transportable    */
X
X/**********************************************************************/
X/*                                                                    */
X/*           MM   MM  IIIIIII  L        L        EEEEEEE              */
X/*           M M M M     I     L        L        E                    */
X/*           M  M  M     I     L        L        EEEE                 */
X/*           M     M     I     L        L        E                    */
X/*           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              */
X/*                                                                    */
X/*      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          */
X/*      B     B  O     O  R     R  N N   N  E        S                */
X/*      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           */
X/*      B     B  O     O  R    R   N   N N  E              S          */
X/*      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           */
X/*                                                                    */
X/*                                                                    */
X/* Creation: Edmond Dujardin                                          */
X/*           (c) 1962 Parker Brothers, Inc.                           */
X/*                                                                    */
X/* Written by: Brett K. Carver                                        */
X/*             Hewlett-Packard, 1983.                                 */
X/*                                                                    */
X/* Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             */
X/*                                                                    */
X/**********************************************************************/
X
X#include "miles.h"
X
X/**********************************/
X/* external procedure definitions */
X/**********************************/
X
Xextern rand();
X
X/*********************************/
X/* external variable definitions */
X/*********************************/
X
Xextern int deck[20];            /* shufled deck of cards */
Xextern int hand[2][15];         /* current status of players */
X
X/**********************************************************************/
X/*                                                                    */
X/*              CARD DECK HANDLING UTILITIES                          */
X/*                                                                    */
X/**********************************************************************/
X
X/*********************************************************/
X/* initilaizes a card_set structure with the card counts */
X/*********************************************************/
Xinitialize_card_set (cards)
Xint cards[20];
X{
Xcards[0]              = 101;    /* total cards */
Xcards[extra_tank]     = 1;      /* safeties */
Xcards[puncture_proof] = 1;
Xcards[driving_ace]    = 1;
Xcards[right_of_way]   = 1;
Xcards[gasoline]       = 6;      /* remedies */
Xcards[spare_tire]     = 6;
Xcards[repairs]        = 6;
Xcards[end_of_limit]   = 6;
Xcards[roll]           = 14;
Xcards[out_of_gas]     = 2;      /* hazards */
Xcards[flat_tire]      = 2;
Xcards[accident]       = 2;
Xcards[speed_limit]    = 3;
Xcards[stop]           = 4;
Xcards[miles_200]      = 4;      /* distance */
Xcards[miles_100]      = 12;
Xcards[miles_75]       = 10;
Xcards[miles_50]       = 10;
Xcards[miles_25]       = 10;
X}
X
X/********************************************/
X/* removes a card from the deck and returns */
X/* card if it could, 0 if it couldn't       */
X/********************************************/
Xremove_card (cards,card)
Xint cards[20];
Xint card;
X{
Xif (cards[card] > 0) {          /* any more cards */
X    cards[card]--;              /* decrement card count */
X    cards[0]--;                 /* decrement total card count */
X    return(card);
X    }
Xelse
X    return(0);
X}
X
X/*********************************************/
X/* given a random number, return a card type */
X/*********************************************/
Xget_card (number)
Xint number;
X{
Xnumber = number % 101;          /* 0 - 101 */
Xif (number >= 28 && number <= 41)
X    return(roll);
Xif (number >= 59 && number <= 70)
X    return(miles_100);
Xif (number >= 71 && number <= 80)
X    return(miles_75);
Xif (number >= 81 && number <= 90)
X    return(miles_50);
Xif (number >= 91 && number <= 100)
X    return(miles_25);
Xif (number >= 4 && number <= 9)
X    return(gasoline);
Xif (number >= 10 && number <= 15)
X    return(spare_tire);
Xif (number >= 16 && number <= 21)
X    return(repairs);
Xif (number >= 22 && number <= 27)
X    return(end_of_limit);
Xif (number >= 51 && number <= 54)
X    return(stop);
Xif (number >= 55 && number <= 58)
X    return(miles_200);
Xif (number >= 48 && number <= 50)
X    return(speed_limit);
Xif (number >= 42 && number <= 43)
X    return(out_of_gas);
Xif (number >= 44 && number <= 45)
X    return(flat_tire);
Xif (number >= 46 && number <= 47)
X    return(accident);
Xif (number == 0)
X    return(extra_tank);
Xif (number == 1)
X    return(puncture_proof);
Xif (number == 2)
X    return(driving_ace);
Xif (number == 3)
X    return(right_of_way);
Xwhile (TRUE) ;                  /* error case */
X}
X
X/********************************************/
X/* deals a card, if no cards left, return 0 */
X/* 1. gets a random number                  */
X/* 2. gets the card                         */
X/* 3. removes the card from the deck        */
X/* 4. if successful, return card            */
X/********************************************/
Xdeal_card ()
X{
Xint card;
Xint more_cards;
Xint i;
Xmore_cards = FALSE;
Xfor (i=0; i<20; i++)
X    if (deck[i] > 0)
X         more_cards = TRUE;
Xif (more_cards)
X    while ((card = remove_card(&deck[0],get_card(rand()))) == 0)
X         ;
Xelse
X    card = 0;
Xreturn(card);
X}
X
X/*******************************************/
X/* checks to see if who has any cards left */
X/*******************************************/
Xany_cards_left(who)
Xint who;
X{
Xint i;
Xfor (i=0; i<7; i++)
X    if (hand[who][i] > 0)
X         return(TRUE);
Xreturn(FALSE);
X}
X
X/*********** end of program **********/
END_OF_card.c
if test 6064 -ne `wc -c <card.c`; then
    echo shar: \"card.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f data.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"data.c\"
else
echo shar: Extracting \"data.c\" \(11398 characters\)
sed "s/^X//" >data.c <<'END_OF_data.c'
X/* data.c */
X/* transportable */
X
X/**********************************************************************/
X/*                                                                    */
X/*           MM   MM  IIIIIII  L        L        EEEEEEE              */
X/*           M M M M     I     L        L        E                    */
X/*           M  M  M     I     L        L        EEEE                 */
X/*           M     M     I     L        L        E                    */
X/*           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              */
X/*                                                                    */
X/*      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          */
X/*      B     B  O     O  R     R  N N   N  E        S                */
X/*      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           */
X/*      B     B  O     O  R    R   N   N N  E              S          */
X/*      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           */
X/*                                                                    */
X/*                                                                    */
X/* Creation: Edmond Dujardin                                          */
X/*           (c) 1962 Parker Brothers, Inc.                           */
X/*                                                                    */
X/* Written by: Brett K. Carver                                        */
X/*             Hewlett-Packard, 1983.                                 */
X/*                                                                    */
X/* Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             */
X/*                                                                    */
X/**********************************************************************/
X
X/**********************************************************************/
X/*                                                                    */
X/*              CONSTANTS AND VARIABLES                               */
X/*                                                                    */
X/**********************************************************************/
X
X/********************/
X/* global variables */
X/********************/
X
Xchar temp_screen_buffer[32];
Xchar * temp_screen = &temp_screen_buffer[0];
Xint cards_played[20];           /* set of cards already played */
Xint deck[20];                   /* shufled deck of cards */
Xint hand[2][15];                /* current status of players */
Xint change[2][15];              /* parallel structure of booleans */
Xint discard;                    /* card being discarded */
Xint play;                       /* play=TRUE, discard=FALSE, drawn=-1 */
Xint card_number;                /* card to play */
Xint extension;                  /* boolean for extension */
Xint delayed_action;             /* boolean for delayed action game */
Xint whose_turn;                 /* you, me, or -1 if game done */
Xint debug;                      /* flag for debug output */
X
X/*****************************/
X/* card names and other text */
X/*****************************/
X
Xchar *card_names[] =            /* array of pointers to pointers to text */
X                {
X                " ",
X                "extra tank",           /* safeties */
X                "puncture-proof",
X                "driving ace",
X                "right-of-way",
X                "gasoline",             /* remedies */
X                "spare tire",
X                "repairs",
X                "end of limit",
X                "roll",
X                "out of gas",           /* haxards */
X                "flat tire",
X                "accident",
X                "speed limit",
X                "stop",
X                "200",                  /* distance */
X                "100",
X                "75",
X                "50",
X                "25",
X                "  YOUR STATUS ",       /* screen text */
X                "  MY STATUS ",
X                " Miles",
X                " Hand",
X                " Game",
X                " Last Discard",
X                " Cards Left",
X                "drawn -->",
X                "play --->",
X                "discard >",
X                "safe trip",            /* game messages */
X                "one 200",
X                "two 200's",
X                "coup fourre'",
X                " scoring",            /* scoring */
X                "miles, 1/",
X                "safety, 100/",
X                "all 4 safeties, 300",
X                "coup fourre, 300/",
X                "trip complete, 400",
X                "delayed action, 300",
X                "safe trip, 300",
X                "extension, 200",
X                "shut-out, 500"
X                };
X
X/****************/
X/* message text */
X/****************/
X
Xchar * T_shuffling_cards = "shuffling cards ";
Xchar * T_dealing_cards   = "dealing cards ";
Xchar * T_make_play       = "play/discard a card ";
Xchar * T_no_card         = "there's no card there ";
Xchar * T_cant_play       = "you can't play a                         ";
Xchar * T_dont_need       = "you don't need a                         ";
Xchar * T_exact_700       = "you need exactly 700 miles ";
Xchar * T_exact_1000      = "you need exactly 1000 miles ";
Xchar * T_only_two_200    = "you may only play two 200's ";
Xchar * T_extension_yes   = "go for extension? YES ";
Xchar * T_extension_no    = "go for extension? NO  ";
Xchar * T_another_yes     = "another game? YES ";
Xchar * T_another_no      = "another game? NO  ";
Xchar * T_match_yes       = "another match? YES ";
Xchar * T_match_no        = "another match? NO  ";
Xchar * T_you_won         = "congratulations: you won ";
Xchar * T_me_won          = "sorry about that, I won ";
Xchar * T_anychar         = "any character for more, return to start game ";
Xchar * T_endgame         = "No more playable cards, hit any character for score ";
Xchar * T_version         = "Mille Bornes, (c) Brett Carver, 1986. Version: 3.0. ";
X
X/***************/
X/* screen text */
X/***************/
X
Xchar * B_intro[] = {
X/* screen 1 */
X"     **********************************************************************",
X"     *                                                                    *",
X"     *           MM   MM  IIIIIII  L        L        EEEEEEE              *",
X"     *           M M M M     I     L        L        E                    *",
X"     *           M  M  M     I     L        L        EEEE                 *",
X"     *           M     M     I     L        L        E                    *",
X"     *           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              *",
X"     *                                                                    *",
X"     *      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          *",
X"     *      B     B  O     O  R     R  N N   N  E        S                *",
X"     *      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           *",
X"     *      B     B  O     O  R    R   N   N N  E              S          *",
X"     *      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           *",
X"     *                                                                    *",
X"     *                                                                    *",
X"     * Creation: Edmond Dujardin, (c) 1962 Parker Brothers, Inc.          *",
X"     *                                                                    *",
X"     * Written by: Brett K. Carver, Hewlett-Packard, 1983.                *",
X"     *                                                                    *",
X"     * Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             *",
X"     *                                                                    *",
X"     **********************************************************************",
X" ",
X/* screen 2 */
X"A BRIEF summary of the rules for Mille Bornes (pronounced Meel-Born) follows:",
X" ",
X"The first player to reach 10,000 points wins the match.  The first player to",
X"reach either 700 or 1,000 Miles exactly wins a game.  (There is an option at",
X"700 Miles to continue the game onto 1,000 Miles.)",
X" ",
X"The cards:",
X"     Hazards           Remedies           Safeties",
X"        2 Out of Gas      6 Gasoline         1 Extra Tank",
X"        2 Flat Tire       6 Spare Tire       1 Puncture Proof",
X"        2 Accident        6 Repairs          1 Driving Ace",
X"        3 Speed Limit     6 End of Limit   \\",
X"        4 Stop           14 Roll           / 1 Right of way",
X" ",
X"You need a green light (Roll) to play distance cards (Miles).  If you have a",
X"Speed Limit then you can only go 25 or 50 Miles (per turn) until you get an",
X"End Of Limit.  If you have a red light (Stop) then you must get a green light.",
X"If you have an Accident, you must get Repairs and then a green light.  If you",
X"run Out Of Gas, you must get Gasoline and a green light.  If you have a Flat",
X"Tire, you must get a Spare Tire and a green light.  Makes sense, doesn't it.",
X" ",
X"A Speed Limit card may be played on your 'opponent' even when 'he' has a hazard",
X"or a Stop.  No more than two 200 Mile cards may be played.",
X/* screen 3 */
X"A safety card prevents the corresponding hazard to be played on you.  For",
X"example, once you have played the Driving Ace safety, you cannot get into an",
X"Accident.  If you still have the Driving Ace card in your hand and get into an",
X"Accident, you can play it to get a Coup Fourre' (pronounced Coo-Foo-Ray) and",
X"remove the Accident.  Whenever a safety card is played, you get another turn.",
X"The Right Of Way safety prevents both stops and speed limits.  Note: The safety",
X"card must be in your hand when your 'opponent' plays the hazard and therefore",
X"the draw card is not eligible for a Coup Fourre'.",
X" ",
X"Do not keep unnecessary cards.  If you have the Driving Ace card, do not keep",
X"Repair cards.  If both Out Of Gas cards have been played, do not keep Gasoline",
X"cards.",
X" ",
X"Scoring:",
X"     Milestones played                Face Value",
X"     Each safety card played                 100",
X"     All 4 safeties played                   300",
X"     Each coup fourre'                       300",
X"     Trip complete (700 or 1000)             400",
X"     Delayed action (no draw cards left)     300",
X"     Safe trip (no 200's)                    300",
X"     Extension (making it to 1000)           200",
X"     Shut-out (opponent has 0 miles)         500",
X/* screen 4 */
X"The game input is designed so that the whole game may be played without moving",
X"your hand around the keyboard. Cards are played by: moving a pointer to the",
X"card of choice, toggling between play/discard, and performing the action.",
X"There are three places your hand may be placed. In all cases, the same fingers",
X"will perform the same actions.",
X" ",
X"action:  doit         up     toggle  down",
X" ",
X"finger:  thumb/       index  middle  ring",
X"         little",
X" ",
X"key:     ' ' or ';'   'j'    'k'     'l'   right hand on the home position",
X"         ' ' or 'a'   'f'    'd'     's'   left hand on the home position",
X"         '0' or ','   '4'    '5'     '6'   right hand on the numeric key pad",
X" ",
X"In addition:",
X"    ! - shell escape,  ? - help,  ^L - redraw screen,  Q - quit,  V - version",
X" ",
X"The game is fairly easy to pick up by just diving in and playing it. Watching",
X"how the computer plays will help also.",
X" ",
X"Good luck!",
X0 };
X
X/*********** end of program **********/
END_OF_data.c
if test 11398 -ne `wc -c <data.c`; then
    echo shar: \"data.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f io.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"io.c\"
else
echo shar: Extracting \"io.c\" \(13076 characters\)
sed "s/^X//" >io.c <<'END_OF_io.c'
X/* io.c */
X/* machine dependent */
X
X/**********************************************************************/
X/*                                                                    */
X/*           MM   MM  IIIIIII  L        L        EEEEEEE              */
X/*           M M M M     I     L        L        E                    */
X/*           M  M  M     I     L        L        EEEE                 */
X/*           M     M     I     L        L        E                    */
X/*           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              */
X/*                                                                    */
X/*      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          */
X/*      B     B  O     O  R     R  N N   N  E        S                */
X/*      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           */
X/*      B     B  O     O  R    R   N   N N  E              S          */
X/*      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           */
X/*                                                                    */
X/*                                                                    */
X/* Creation: Edmond Dujardin                                          */
X/*           (c) 1962 Parker Brothers, Inc.                           */
X/*                                                                    */
X/* Written by: Brett K. Carver                                        */
X/*             Hewlett-Packard, 1983.                                 */
X/*                                                                    */
X/* Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             */
X/*                                                                    */
X/**********************************************************************/
X/*                                                                    */
X/* WARNING                                                            */
X/*                                                                    */
X/* The following file may be offensive to UNIX purists. The original  */
X/* implementation was created on a non-UNIX machine that did not have */
X/* any of the standard I/O facilities. Many of the shortcomings of    */
X/* its previous life live on in this ported version.                  */
X/*                                                                    */
X/* You have been warned...                                            */
X/*                                                                    */
X/**********************************************************************/
X
X#include <curses.h>
X#include <signal.h>
X#include "miles.h"
X
X/**********************************************************************/
X/*                                                                    */
X/*              CONSTANTS AND VARIABLES                               */
X/*                                                                    */
X/**********************************************************************/
X
X/**********************************/
X/* external procedure definitions */
X/**********************************/
X
Xextern display_pick();
Xextern random();
Xextern refresh_screen();
X
X/*********************************/
X/* external variable definitions */
X/*********************************/
X
Xextern int play;                /* play=TRUE, discard=FALSE, drawn=-1 */
Xextern int extension;           /* boolean for extension */
Xextern int debug;               /* flag for debug output */
Xextern char * temp_screen;
X
Xextern char *T_extension_yes;
Xextern char *T_extension_no;
Xextern char *T_another_yes;
Xextern char *T_another_no;
Xextern char *T_match_yes;
Xextern char *T_match_no;
Xextern char *T_anychar;
Xextern char *T_version;
Xextern char *B_intro[];
X
X/**********************************************************************/
X/*                                                                    */
X/*              DISPLAY AND FORMATTING UTILITIES                      */
X/*                                                                    */
X/**********************************************************************/
X
X/*************************/
X/* cleanup the screen io */
X/*************************/
Xcleanup_io()
X{
Xclear();
Xrefresh();
Xendwin();
Xexit(0);
X}
X
X/****************************/
X/* initialize the screen io */
X/****************************/
Xinitialize_io()
X{
Xsignal(SIGINT,cleanup_io);
Xsignal(SIGQUIT,cleanup_io);
Xsignal(SIGTERM,cleanup_io);
Xinitscr();
Xnoecho();
Xcbreak();
X}
X
X/************************/
X/* write out the screen */
X/************************/
Xwrite_screen()
X{
Xrefresh();
X}
X
X/***************************/
X/* write out screen banner */
X/***************************/
Xdisplay_banner()
X{
Xchar **s;
Xint i;
Xclear();
Xs = B_intro;
Xmove(0,0);
Xi = 0;
Xwhile (*s) {
X    printw("%s\n",*s++);
X    i++;
X    if (i>22) {
X         move(23,0);
X         printw("%s",T_anychar);
X         refresh();
X         if (getch() == '\n') {
X              clear();
X              return;
X              }
X         clear();
X         move(0,0);
X         i = 0;
X         }
X    }
Xmove(23,0);
Xprintw("%s",T_anychar);
Xrefresh();
Xgetch();
Xclear();
X}
X
X/***************************************/
X/* blank screen from location thru end */
X/***************************************/
Xclear_screen(row,column)
Xint row;
Xint column;
X{
Xmove(row,column);
Xclrtobot();
X}
X
X/************************************/
X/* write out a status/error message */
X/************************************/
Xmessage (string,status)
Xchar * string;
Xint status;
X{
Xmove(23,0);
Xclrtoeol();
Xmove(23,0);
Xif (status) {
X         addstr(string);
X         }
X    else {
X         addstr(string);
X         beep();
X         }
Xrefresh();
X}
X
X/*******************************************************/
X/* interface to formatter                              */
X/* formats value to loaction pointed to by destination */
X/*******************************************************/
Xformat (value,row,column)
Xint value ;
Xint row;
Xint column;
X{
Xmove(row,column);
Xprintw("%d  ",value);
X}
X
X/*****************************************/
X/* places the string pointed to in a     */
X/* length character field, blank filling */
X/*****************************************/
Xplace_string(string,row,column,length)
Xchar *string;
Xint row;
Xint column;
Xint length;
X{
Xint i;
Xchar *temp;
Xtemp = temp_screen;
Xfor (i=0; i<length; i++)
X    *temp++ = ' ';
X*temp = '\0';
Xmove(row,column);
Xaddstr(temp_screen);
Xmove(row,column);
Xaddstr(string);
X}
X
X/*****************************************/
X/* moves the string pointed to in a      */
X/* length character field, blank filling */
X/*****************************************/
Xmove_string(string,destination,length)
Xchar *string;
Xchar *destination;
Xint length;
X{
Xint i;
Xi = 0;
Xwhile ((*string != '\0') && (i < length)) {       /* copy string */
X    *destination++ = *string++;
X    i++;
X    }
Xfor (i; i<length; i++)
X    *destination++ = ' ';
X}
X
X/**********************************************************************/
X/*                                                                    */
X/*              INPUT UTILITIES                                       */
X/*                                                                    */
X/**********************************************************************/
X
X/*************************/
X/* waits for you to move */
X/*************************/
Xwait_for_move()
X{
Xwhile (TRUE) {
X    random();                      /* help randomize */
X    switch (getch()) {
X         case '5': 
X         case 'd': 
X         case 'k': {             /* toggle */
X              play = !play;
X              display_pick(0);
X              break;
X              }
X         case '6': 
X         case 's': 
X         case 'l': {             /* down */
X              display_pick(1);
X              break;
X              }
X         case '0': 
X         case ',': 
X         case 'a': 
X         case ';': 
X         case ' ': {             /* doit */
X              display_pick(-2);
X              return;
X              }
X         case '4': 
X         case 'f': 
X         case 'j': {             /* up */
X              display_pick(-1);
X              break;
X              }
X         case '?': {
X              display_banner();
X              clear();
X              refresh_screen(FALSE);
X              display_pick(0);
X              break;
X              }
X         case 'Q': {             /* quit */
X              cleanup_io();
X              break;
X              }
X         case '!': {             /* shell escape */
X              shell();
X              }      /* keep going */
X         case '': {
X              clear();
X              refresh_screen(FALSE);
X              display_pick(0);
X              break;
X              }
X         case 'v':
X         case 'V': {
X              message(T_version,TRUE);
X              break;
X              }
X         case 'D': {                            /* <=========== debug */
X              debug = !debug;                   /*                    */
X              break;                            /*                    */
X              }                                 /* <=========== debug */
X         }
X    }
X}
X
X/*****************************/
X/* asks for extension yes/no */
X/*****************************/
Xextension_question()
X{
Xextension = TRUE;
Xwhile (TRUE) {
X    if (extension)
X         message(T_extension_yes,TRUE);
X    else
X         message(T_extension_no,TRUE);
X    random();                      /* help randomize */
X    switch (getch()) {
X         case '5': 
X         case 'd': 
X         case 'k': {             /* toggle */
X              extension = !extension; /* extension */
X              break;
X              }
X         case '0': 
X         case ',': 
X         case 'a': 
X         case ';': 
X         case ' ': {             /* doit */
X              return(extension);
X              break;
X              }
X         case 'Q': {             /* quit */
X              cleanup_io();
X              break;
X              }
X         case '!': {             /* shell escape */
X              shell();
X              }      /* keep going */
X         case '': {
X              clear();
X              refresh_screen(FALSE);
X              break;
X              }
X         }
X    }
X}
X
X/********************************/
X/* asks for another game yes/no */
X/********************************/
Xanother_question()
X{
Xint another;
Xanother = TRUE;
Xwhile (TRUE) {
X    if (another)
X         message(T_another_yes,TRUE);
X    else
X         message(T_another_no,TRUE);
X    random();                      /* help randomize */
X    switch (getch()) {
X         case '5': 
X         case 'd': 
X         case 'k': {             /* toggle */
X              another = !another; /* another */
X              break;
X              }
X         case '0': 
X         case ',': 
X         case 'a': 
X         case ';': 
X         case ' ': {             /* doit */
X              return(another);
X              break;
X              }
X         case 'Q': {             /* quit */
X              cleanup_io();
X              break;
X              }
X         case '!': {             /* shell escape */
X              shell();
X              }      /* keep going */
X         case '': {
X              clear();
X              refresh_screen(TRUE);
X              break;
X              }
X         }
X    }
X}
X
X/*********************************/
X/* asks for another match yes/no */
X/*********************************/
Xanother_match()
X{
Xint another;
Xanother = TRUE;
Xwhile (TRUE) {
X    if (another)
X         message(T_match_yes,TRUE);
X    else
X         message(T_match_no,TRUE);
X    random();                      /* help randomize */
X    switch (getch()) {
X         case '5': 
X         case 'd': 
X         case 'k': {             /* toggle */
X              another = !another; /* another */
X              break;
X              }
X         case '0': 
X         case ',': 
X         case 'a': 
X         case ';': 
X         case ' ': {             /* doit */
X              return(another);
X              break;
X              }
X         case 'Q': {             /* quit */
X              cleanup_io();
X              break;
X              }
X         case '!': {             /* shell escape */
X              shell();
X              }      /* keep going */
X         case '': {
X              clear();
X              refresh_screen(TRUE);
X              break;
X              }
X         }
X    }
X}
X
X/**************************/
X/* perform a shell escape */
X/**************************/
Xshell()
X{
Xextern char * getenv();	/* to stop the warning */
Xint pid;
Xchar *sh;
Xint ret_status;
Xsh = getenv("SHELL");
Xclear();
Xmove(0,0);
Xrefresh();
Xendwin();
Xfflush(stdout);
Xwhile((pid = fork()) < 0)
X     sleep(1);
Xif (pid == 0) {
X    setuid(getuid());
X    setgid(getgid());
X    execl(sh == NULL ? "/bin/sh" : sh, "shell", "-i", 0);
X    perror("No shelly");
X    exit(-1);
X    }
Xelse {
X    signal(SIGINT, SIG_IGN);
X    signal(SIGQUIT, SIG_IGN);
X    while (wait(&ret_status) != pid)
X         continue;
X    signal(SIGINT, cleanup_io);
X    signal(SIGQUIT, cleanup_io);
X    initscr();
X    noecho();
X    cbreak();
X    }
X}
X/*********** end of program **********/
END_OF_io.c
if test 13076 -ne `wc -c <io.c`; then
    echo shar: \"io.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(10389 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/* main.c */
X/* maybe */
X
X/**********************************************************************/
X/*                                                                    */
X/*           MM   MM  IIIIIII  L        L        EEEEEEE              */
X/*           M M M M     I     L        L        E                    */
X/*           M  M  M     I     L        L        EEEE                 */
X/*           M     M     I     L        L        E                    */
X/*           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              */
X/*                                                                    */
X/*      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          */
X/*      B     B  O     O  R     R  N N   N  E        S                */
X/*      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           */
X/*      B     B  O     O  R    R   N   N N  E              S          */
X/*      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           */
X/*                                                                    */
X/*                                                                    */
X/* Creation: Edmond Dujardin                                          */
X/*           (c) 1962 Parker Brothers, Inc.                           */
X/*                                                                    */
X/* Written by: Brett K. Carver                                        */
X/*             Hewlett-Packard, 1983.                                 */
X/*                                                                    */
X/* Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             */
X/*                                                                    */
X/**********************************************************************/
X
X#include <curses.h>
X#include "miles.h"
X
X/**********************************************************************/
X/*                                                                    */
X/*              CONSTANTS AND VARIABLES                               */
X/*                                                                    */
X/**********************************************************************/
X
X/**********************************/
X/* external procedure definitions */
X/**********************************/
X
Xextern initialize_io();
Xextern display_banner();
Xextern cleanup_io();
Xextern deal_card();
Xextern display_hand();
Xextern display_pick();
Xextern display_deck();          /* <=========================== debug */
Xextern wait_for_move();
Xextern valid_move();
Xextern remove_card();
Xextern play_card();
Xextern compute_play_weight();
Xextern compute_discard_weight();
Xextern format();
Xextern initialize_game();
Xextern any_cards_left();
Xextern another_match();
Xextern another_question();
Xextern extension_question();
Xextern tabulate_score();
Xextern init_random();
Xextern random();
Xextern message ();
Xextern write_screen();
X
X/*********************************/
X/* external variable definitions */
X/*********************************/
X
Xextern int deck[20];            /* shufled deck of cards */
Xextern int hand[2][15];         /* current status of players */
Xextern int change[2][15];       /* parallel structure of booleans */
Xextern int cards_played[20];    /* set of cards already played */
Xextern int extension;           /* boolean for extension */
Xextern int whose_turn;          /* you, me, or -1 if game done */
Xextern int play;                /* play=TRUE, discard=FALSE, drawn=-1 */
Xextern int card_number;         /* card to play */
Xextern int debug;               /* flag for debug output */
Xextern char *screen;
X
Xextern char *T_shuffling_cards;
Xextern char *T_make_play;
Xextern char *T_you_won;
Xextern char *T_me_won;
Xextern char *T_endgame;
X
X/**********************************************************************/
X/*                                                                    */
X/*              UTILITIES TO PLAY YOU AND ME TURNS                    */
X/*                                                                    */
X/**********************************************************************/
X
X/*********************/
X/* you play one card */
X/*********************/
Xyou_play_turn()
X{
Xcard_number = 6;
Xif (hand[you][card_number] = deal_card())
X    play = -1;
Xelse
X    play = TRUE;
Xchange[you][card_number] = TRUE;
Xdisplay_hand(you);
Xdisplay_pick(0);
Xif (debug) display_deck();         /* <=========================== debug */
Xwhile (TRUE) {
X    wait_for_move();
X    if (valid_move(you,card_number,play,TRUE)) {
X         remove_card(&cards_played[0],hand[you][card_number]);
X         if (play_card(you,card_number,play))
X              return(you);
X         else
X              return(me);
X         }
X    display_pick(0);
X    }
X}
X
X/********************/
X/* me play one card */
X/********************/
Xme_play_turn()
X{
Xint me_card;
Xint me_play;
Xint me_weight;
Xint weight;
Xint i;
Xhand[me][6] = deal_card();
Xif (debug)			/* <=========================== debug */
X    for (i=0; i<7; i++)		/* <=========================== debug */
X         change[me][i] = TRUE;	/* <=========================== debug */
Xremove_card(&cards_played[0],hand[me][6]);
Xif (debug) display_hand(me);    /* <=========================== debug */
Xif (debug) display_deck();      /* <=========================== debug */
Xme_card = 0;
Xme_play = TRUE;
Xme_weight = -1;
Xfor (i=0; i<7; i++) {
X    weight = 0;                 /* <=========================== debug */
X    if (valid_move(me,i,TRUE,TRUE))
X         if ((weight = compute_play_weight(i)) > me_weight) {
X              me_weight = weight;
X              me_card = i;
X              me_play = TRUE;
X              }
X    if (debug)                  /* <=========================== debug */
X         format(weight,i + hand_loc + 20);
X    weight = 0;                 /* <=========================== debug */
X    if (valid_move(me,i,FALSE,TRUE))
X         if ((weight = compute_discard_weight(i)) > me_weight) {
X              me_weight = weight;
X              me_card = i;
X              me_play = FALSE;
X              }
X    if (debug)                  /* <=========================== debug */
X         format(weight,i + hand_loc + 30);
X    }
Xif (debug) write_screen();      /* <=========================== debug */
Xif (debug) sleep(2);            /* <=========================== debug */
Xif (play_card(me,me_card,me_play))
X    return(me);
Xelse
X    return(you);
X}
X
X/****************************/
X/* check for useable cards */
X/****************************/
Xint useable_card(who,play)
Xint who;
Xint play;
X{
Xint i;
Xfor (i=0; i<7; i++)
X    if (valid_move(who,i,play,FALSE))
X         return(TRUE);
Xreturn(FALSE);
X}
X
X/**********************************************************************/
X/*                                                                    */
X/*              MAIN PROGRAM                                          */
X/*                                                                    */
X/**********************************************************************/
X
X/****************/
X/* main program */
X/****************/
Xmain ()
X{
Xinitialize_io();
Xdisplay_banner();
Xmessage(T_shuffling_cards,TRUE);
Xinit_random();
Xwhile (TRUE) {
X    hand[you][score] = hand[me][score] = 0;         /* set scores to 0 */
X    while (hand[you][score] < 10000 && hand[me][score] < 10000) {
X         initialize_game();
X         while (whose_turn != -1) {
X              switch (whose_turn) {
X                   case you : {
X                       if (deck[0] == 0)              /* no cards left to draw*/
X                             if ( ! useable_card(you,FALSE)) {  /* or to play */
X                                  whose_turn = me;
X                                  break;
X                                  }
X                        message(T_make_play,TRUE);
X                        whose_turn = you_play_turn();
X                        display_hand(you);
X                        display_hand(me);
X                        if (extension) {
X                             if (hand[you][miles] == 1000)
X                                  whose_turn = -1;
X                             }
X                        else
X                             if (hand[you][miles] == 700)
X                                  if (!(extension = extension_question()))
X                                       whose_turn = -1;
X                        break;
X                        }
X                   case me : {
X                        if (deck[0] == 0)             /* no cards left to draw*/
X                             if ( ! useable_card(me,FALSE)) {   /* or to play */
X                                  whose_turn = you;
X                                  break;
X                                  }
X                        whose_turn = me_play_turn();
X                        display_hand(you);
X                        display_hand(me);
X                        if (extension) {
X                             if (hand[me][miles] == 1000)
X                                  whose_turn = -1;
X                             }
X                        else
X                             if (hand[me][miles] == 700) {
X                                  if (hand[you][miles] == 0 ||
X                                      (deck[0] - 25 - (random() % 10)) < 0)
X                                       extension = FALSE;
X                                  else
X                                       extension = 2;
X                                  if (!extension)
X                                       whose_turn = -1;
X                                  }
X                        break;
X                        }
X                   }
X              if (whose_turn != -1 && deck[0] == 0)  /* no cards left to draw */
X                   if ( ! useable_card(you,TRUE) && ! useable_card(me,TRUE)) {
X                        message(T_endgame,FALSE);
X                        refresh();
X                        getch();
X                        whose_turn = -1;
X                        }
X              }
X         tabulate_score(TRUE);
X         if (hand[you][score] < 10000 && hand[me][score] < 10000)
X              if (!another_question())
X                   break;
X         }
X    if (hand[you][score] > hand[me][score])
X        message(T_you_won,FALSE);
X    else
X        message(T_me_won,FALSE);
X    sleep(2);
X    if (!another_match())
X         break;
X    }
Xcleanup_io();
Xexit(0);
X}
X
X/*********** end of program **********/
END_OF_main.c
if test 10389 -ne `wc -c <main.c`; then
    echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f miles.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"miles.h\"
else
echo shar: Extracting \"miles.h\" \(2532 characters\)
sed "s/^X//" >miles.h <<'END_OF_miles.h'
X/* miles.h */
X/* transportable */
X
X/**********************************************************************/
X/*                                                                    */
X/*              INCLUDE FILE OF SYSTEM DEFINES ETC                    */
X/*                                                                    */
X/**********************************************************************/
X
X#ifndef TRUE
X#define TRUE 1
X#define FALSE 0
X#endif
X
X#define blank_line     0
X#define extra_tank     1        /* safeties */
X#define puncture_proof 2
X#define driving_ace    3
X#define right_of_way   4
X#define gasoline       5        /* remedies */
X#define spare_tire     6
X#define repairs        7
X#define end_of_limit   8
X#define roll           9
X#define out_of_gas     10       /* hazards */
X#define flat_tire      11
X#define accident       12
X#define speed_limit    13
X#define stop           14
X#define miles_200      15       /* distance */
X#define miles_100      16
X#define miles_75       17
X#define miles_50       18
X#define miles_25       19
X#define YOUR_STATUS    20       /* screen text */
X#define MY_STATUS      21
X#define Miles          22
X#define Hand           23
X#define Game           24
X#define Last_Discard   25
X#define Cards_Left     26
X#define Drawn          27
X#define Play           28
X#define Discard        29
X#define safe_trip      30       /* game text */
X#define one_200        31
X#define two_200        32
X#define coup_fourre    33
X#define Scoring        34       /* scoring */
X#define S_miles        35
X#define S_safety       36
X#define S_4_safeties   37
X#define S_coup_fourre  38
X#define S_trip_complete 39
X#define S_delayed_action 40
X#define S_safe_trip    41
X#define S_extension    42
X#define S_shut_out     43
X
X#define you 0
X#define me  1
X
X#define miles   8
X#define cnt_200 9
X#define safety  10
X#define limit   11
X#define battle  12
X#define coups   13              /* 10H -> coup possible */
X#define score   14
X
X#define blank   1
X
X#define start_loc      (blank * 1 +  0),( 0)
X#define miles_loc      (blank * 1 +  1),(10)
X#define cnt_200_loc    (blank * 1 +  1),(20)
X#define safety_loc     (blank * 1 +  2),(10)
X#define limit_loc      (blank * 1 +  6),( 0)
X#define battle_loc     (blank * 1 +  6),(20)
X#define result_loc     (blank * 2 +  7),(20)
X#define hand_loc       (blank * 2 +  8),(10)
X#define discard_loc    (blank * 2 + 16),(20)
X#define cards_left_loc (blank * 2 + 16),(60)
X#define score_loc      (blank * 2 + 17),( 0)
X#define who_loc        (who * 40)
X
X/*********** end of program **********/
END_OF_miles.h
if test 2532 -ne `wc -c <miles.h`; then
    echo shar: \"miles.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f random.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"random.c\"
else
echo shar: Extracting \"random.c\" \(4528 characters\)
sed "s/^X//" >random.c <<'END_OF_random.c'
X/* random.c */
X/* machine dependent */
X
X/**********************************************************************/
X/*                                                                    */
X/*           MM   MM  IIIIIII  L        L        EEEEEEE              */
X/*           M M M M     I     L        L        E                    */
X/*           M  M  M     I     L        L        EEEE                 */
X/*           M     M     I     L        L        E                    */
X/*           M     M  IIIIIII  LLLLLLL  LLLLLLL  EEEEEEE              */
X/*                                                                    */
X/*      BBBBBB    OOOOO   RRRRRR   NN    N  EEEEEEE   SSSSSS          */
X/*      B     B  O     O  R     R  N N   N  E        S                */
X/*      BBBBBB   O     O  RRRRRR   N  N  N  EEEEE     SSSSS           */
X/*      B     B  O     O  R    R   N   N N  E              S          */
X/*      BBBBBB    OOOOO   R     R  N    NN  EEEEEEE  SSSSSS           */
X/*                                                                    */
X/*                                                                    */
X/* Creation: Edmond Dujardin                                          */
X/*           (c) 1962 Parker Brothers, Inc.                           */
X/*                                                                    */
X/* Written by: Brett K. Carver                                        */
X/*             Hewlett-Packard, 1983.                                 */
X/*                                                                    */
X/* Copyright: (c) Brett K. Carver, Hewlett-Packard, 1986.             */
X/*                                                                    */
X/**********************************************************************/
X
X#include "miles.h"
X#include <time.h>
X
X#undef MY_RAND
X#undef RND_ONE
X
X/**********************************************************************/
X/*                                                                    */
X/*              CONSTANTS AND VARIABLES                               */
X/*                                                                    */
X/**********************************************************************/
X
X/**********************************/
X/* external procedure definitions */
X/**********************************/
X
Xextern	long	time();
X
X/**********************************/
X/* external variable definitions */
X/**********************************/
X
Xextern	struct	tm	*localtime();
X
X#ifdef MY_RAND
X
X/**********************************************************************/
X/*                                                                    */
X/*              RANDOM NUMBER GENERATION UTILITIES                    */
X/*                                                                    */
X/**********************************************************************/
X
X#ifdef RND_ONE
X
Xdouble rnd_x = 283463.5;
X
X/**************************************/
X/* pseudo random number generator one */
X/**************************************/
Xrnd()
X{
Xrnd_x = (double)((3612 * (long)rnd_x + 5701) % 566927) + 0.5;
Xreturn((long)rnd_x);
X}
X
X#else
X
Xint rnd_x;
X
X/**************************************/
X/* pseudo random number generator two */
X/**************************************/
Xint
Xrnd()
X{
Xrnd_x = (rnd_x * 11109) + 13849;
Xreturn((rnd_x & 0xfff) >> 1);
X}
X
X#endif
X
X#endif
X
X/****************************************************/
X/* generates a seed for the random number generator */
X/****************************************************/
Xint
Xget_seed ()
X{
Xint	seed;
Xstruct	tm	*timestruct;
Xlong	clock;
Xclock = time(0);
Xtimestruct = localtime(&clock);
Xseed = timestruct->tm_sec  +
X       timestruct->tm_min  +
X       timestruct->tm_hour +
X       timestruct->tm_mday +
X       timestruct->tm_mon  +
X       timestruct->tm_year +
X       timestruct->tm_yday;
Xreturn((int) ((seed + clock) % 32767));
X}
X
X/***********************************************/
X/* generates a random number between 0 and 100 */
X/***********************************************/
Xint
Xrandom()
X{
X#ifdef MY_RAND
Xreturn(rnd() % 101);
X#else
Xreturn(rand() % 101);
X#endif
X}
X
X/*******************************************/
X/* initializes the random number generator */
X/*******************************************/
Xinit_random()
X{
Xint seed;
Xregister int i;
Xseed = get_seed();
X#ifdef MY_RAND
X#ifdef RND_ONE
X    for (i=0; i<seed; i++)
X         rnd();
X#else
X    rnd_x = seed;
X#endif
X#else
X    srand((unsigned)seed);
X#endif
X}
X
X/*********** end of program **********/
END_OF_random.c
if test 4528 -ne `wc -c <random.c`; then
    echo shar: \"random.c\" unpacked with wrong size!
fi
# end of overwriting check
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