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

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

Submitted by: Brett K. Carver <hpsrlc!brett@hplabs.HP.COM>
Comp.sources.games: Volume 3, Issue 66
Archive-name: miles/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:  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"