$! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 21-MAY-1992 01:12:07.75 By user MASMUMMY $! $! This VMS_SHARE Written by: $! Andy Harper, Kings College London UK $! $! Acknowledgements to: $! James Gray - Original VMS_SHARE $! Michael Bednarek - Original Concept and implementation $! $!+ THIS PACKAGE DISTRIBUTED IN 4 PARTS, TO KEEP EACH PART $! BELOW 30 BLOCKS $! $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER $! AND EXECUTE AS A COMMAND PROCEDURE ( @name ) $! $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING: $! 1. CCSETUP.COM;1 $! 2. CRIBBAGE.C;1 $! 3. CRIBBAGE.MAN;1 $! 4. GETOPT.C;1 $! $set="set" $set symbol/scope=(nolocal,noglobal) $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID")) $e="write sys$error ""%UNPACK"", " $w="write sys$output ""%UNPACK"", " $ if f$trnlnm("SHARE_LOG") then $ w = "!" $ ve=f$getsyi("version") $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START $ e "-E-OLDVER, Must run at least VMS 4.4" $ v=f$verify(v) $ exit 44 $UNPACK: SUBROUTINE ! P1=filename, P2=checksum $ if f$search(P1) .eqs. "" then $ goto file_absent $ e "-W-EXISTS, File ''P1' exists. Skipped." $ delete 'f'* $ exit $file_absent: $ if f$parse(P1) .nes. "" then $ goto dirok $ dn=f$parse(P1,,,"DIRECTORY") $ w "-I-CREDIR, Creating directory ''dn'." $ create/dir 'dn' $ if $status then $ goto dirok $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped." $ delete 'f'* $ exit $dirok: $ w "-I-PROCESS, Processing file ''P1'." $ if .not. f$verify() then $ define/user sys$output nl: $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1' PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET( SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:= CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b)); LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION( BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1); IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE; MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1; ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")= 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF"; POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r); ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1; COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE, "output_file"));ENDPROCEDURE;Unpacker;QUIT; $ delete/nolog 'f'* $ CHECKSUM 'P1' $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT $ e "-E-CHKSMFAIL, Checksum of ''P1' failed." $ ENDSUBROUTINE $START: $ create 'f' X$ define lnk$library sys$library:vaxccurse X$ define lnk$library_1 sys$library:vaxcrtl $ CALL UNPACK CCSETUP.COM;1 408505211 $ create 'f' X/*`09`09cribbage.c`09`09*/ X X/* Play the computer in the game of cribbage! */ X X/* (C) 1985 - Dave Taylor: ihnp4!hpfcla!d_taylor - or - hplabs!hpcnof!dat V */ X X/* Cribbage display board added by: X * Chris Yoder ->`09(ihnp4`7Callegra)!scgvaxd!engvax!chris or X *`09`09`09engvax!chris@csvax.caltech.edu X * Hughes Aircraft Company X * Space and Communications Group X * Computing Technology Center X * Feb. 1986 X */ X X#include X#include curses /* For display routines. */ X X#define swap(a,b)`09`7B int c; c = b; b = a; a = c; `7D X#define suite(n)`09(int) (n-1) / 13 X#define plural(n)`09n == 1? "" : "s" X#define merge(hand,c)`09hand.card`5B4`5D = c; order(&hand, 5) X#define pick_card()`09deck`5Btop_of_deck++`5D X X#define add_points(who,n)`09`7B points`5Bwho`5D += n; peg(who,n); \ X`09`09`09`09 if (points`5Bwho`5D >= limit) winner(who); `7D X X#define save(base, a,b,c,d) `09`7B base.card`5B0`5D = my_hand.card`5Ba`5D; \ X`09 base.status`5B0`5D = AVAILABLE; \ X base.card`5B1`5D = my_hand.card`5Bb`5D; \ X`09 base.status`5B1`5D = AVAILABLE; \ X`09`09`09 base.card`5B2`5D = my_hand.card`5Bc`5D; \ X`09 base.status`5B2`5D = AVAILABLE; \ X base.card`5B3`5D = my_hand.card`5Bd`5D; \ X`09 base.status`5B3`5D = AVAILABLE; `7D X X#define show_played_cards`090 X X#define DECKSIZE `0952 X#define CRIB`09`092 X#define YOU`09`091 X#define ME`09`090 X X#define LONG_FORM`090`09/* for card format output */ X#define SHORT_FORM`091 X#define QUIET`09`090`09/* compute point sum */ X#define EXPLAIN`09`091 X X#define PLAYED `091`09/* card played yet? */ X#define AVAILABLE `090 X#define DISCARDED (-1) X X#define ACE`09`091 X#define JACK`09`0911 X#define QUEEN`09`0912 X#define KING`09`0913 X Xstruct card_hand `7B X`09 int card`5B6`5D; X`09 int status`5B6`5D; X `7D; X Xstruct card_hand my_hand, your_hand, crib_hand; X Xint deck`5BDECKSIZE`5D, top_of_deck, limit; Xint points`5B`5D = `7B0, 0`7D; Xint whose_crib, show_counting = 0, starter; X Xint`09my_for_peg = 0, your_for_peg = 0; /* These for display purposes. */ Xint`09my_bck_peg = -1, your_bck_peg = -1; /* -cy */ X XWINDOW`09*board_win, *i_o_win; /* Main windows. */ X X#define YOUR_CARD_EDGE 0 X#define YOUR_CARD_TOP 8 X#define MY_CARD_EDGE 18 X#define MY_CARD_TOP 8 X#define CRIB_CARD_EDGE whose_crib == ME? MY_CARD_EDGE : YOUR_CARD_EDGE X#define CRIB_CARD_TOP 18 X#define BOARD_TOP 0 X#define BOARD_EDGE 0 X#define I_O_TOP 0 X#define I_O_EDGE 40 X X#define VISIBLE`09`091 X#define INVISIBLE`090 X XWINDOW`09*your_card_win`5B7`5D, *my_card_win`5B7`5D, *crib_card_win;`20 X/* Card display windows. */ X X/* End of display purposes. */ X Xchar *say(), *say_card(); X Xmain(argc, argv) Xint argc; Xchar *argv`5B`5D; X`7B X`09extern char *optarg; X`09extern int opterr; X`09register int i=0, j; X`09int c; X X`09limit = 121;`09/* default counting limit for game (in orig = 150) */ X`09opterr = 0;`09/* suppress the 'getopt' error messages */ X X`09while ((c = getopt(argc, argv, "l:v")) != EOF) X`09 switch (c) `7B X`09 case 'l' : sscanf(optarg, "%d", &limit); X`09`09 if (limit < 11)`20 X`09`09`09 exit(printf("** Limit must be greater than 10! **\n")); X`09`09 if (limit > 121) X`09`09`09 exit(printf("** Limit must not be greater than 121! **\n")); X`09`09 break; X`09 case 'v' : show_counting++;`09`09 X`09`09 break; X`09 default : exit(printf("Usage: %s `5B-v`5D `5B-l limit`5D\n", argv`5B V0`5D)); X`09 `7D X X`09setup_screen(); X X`09wprintw(i_o_win,"\n Cribbage 1.2\n\n"); X X`09wprintw(i_o_win,"We are playing up to %s points.\nGood luck!\n\n", X`09`09say(limit)); X X`09srand(time(0)); X`09whose_crib = rand() % 2; X X`09do `7B X`09 shuffle(); X`09 wprintw(i_o_win,"\nIt's %s crib...\n\n", whose_crib==ME? "my" : "your") V; X`09 wrefresh(i_o_win); X`09 deal_cards(); X`09 display_hand(your_hand, 6, VISIBLE, YOU); X`09 pick_crib(); X`09 player_add_to_crib(); X`09 X`09 /** pick the starter card! **/ X X`09 starter = pick_card(); X`09 make_card (&crib_card_win,say_card(starter,SHORT_FORM), X`09`09 CRIB_CARD_TOP,CRIB_CARD_EDGE); X`09 wprintw(i_o_win,"\nThe starter is the %s",say_card(starter,LONG_FORM)); X`09 if (rank(starter) == JACK) `7B X`09 wprintw(i_o_win,"\nfor two ('his heels').\n"); X`09 add_points(whose_crib, 2); X`09 `7D X`09 wprintw(i_o_win,".\n"); X`09 wrefresh(i_o_win); X X`09 play(! whose_crib); X`09 wprintw(i_o_win,"\nOkay, let's count up! (Recall the \nstarter is the V %s)\n\n", X`09 say_card(starter, LONG_FORM)); X`09 wrefresh(i_o_win); X`09 total_points(whose_crib); X`09 wprintw(i_o_win,"\nYou have %d points and I have %d points\n", X points`5BYOU`5D, points`5BME`5D); X`09 wrefresh(i_o_win); X`09 whose_crib = ! whose_crib; X`09 delwin (crib_card_win); X`09`7D while (1); X cleanup(); X`7D X Xshuffle() X`7B X`09/* shuffle the 52 random integers into deck.. */ X`09register int i, j; X X`09for (i=0;i1;i--) `7B X`09 j = rand() % i; X`09 swap(deck`5Bi`5D, deck`5Bj`5D); X`09`7D X`09/** and do it again for good luck! **/ X`09for (i=DECKSIZE-1;i>1;i--) `7B X`09 j = rand() % i; X`09 swap(deck`5Bi`5D, deck`5Bj`5D); X`09`7D X`09top_of_deck = 0; X`7D X Xdeal_cards() X`7B X`09/* deal cards out: six per player */ X`09register int i; X`09int offset; X X`09for (i=0;i<6;i++) `7B X`09 your_hand.card`5Bi`5D = pick_card(); X`09 your_hand.status`5Bi`5D = AVAILABLE; X`09 my_hand.card`5Bi`5D = pick_card(); X`09 my_hand.status`5Bi`5D = AVAILABLE; X`09 crib_hand.status`5Bi`5D = AVAILABLE;`09/* all crib cards available! */ X`09`7D X`09order(&my_hand, 6);`09/* sort lowest to highest rank */ X`09order(&your_hand, 6);`09/* for both hands... */ X`09show_hand(your_hand, 6, "You are dealt: ","\n",PLAYED); X`7D X Xpick_crib() X`7B X`09/* pick for crib...get best hand(s) and then put remainder X`09 in crib. If other players crib, pick hand with same value X`09 that gives them the LEAST points in the two cards (ie try X`09 not to be same suite, pairs, fifteens, fives, etc etc) */ X X`09struct card_hand hand`5B15`5D; X`09int worst, hand_to_use, val; X`09int i,j,k,l, best=0, possible=0, discard`5B2`5D; X X`09for (i=0; i<3; i++) X`09 for (j=i+1; j<4; j++) X`09 for (k=j+1; k<5; k++) X`09 for (l=k+1; l<6; l++) `7B X`09 val = hand_value(my_hand, i, j, k, l, 0, QUIET); X`09 if (val > best) `7B X possible=0; X`09 save(hand`5Bpossible`5D,i,j,k,l); X`09 possible++; X`09 best = val; X`09 `7D X`09 else if (val == best) `7B X`09`09 save(hand`5Bpossible`5D,i,j,k,l); X`09 possible++; X`09`09`7D X`09 `7D X X`09best = -1;`20 X`09worst = 99; X X`09if (possible > 1) `7B /* more than one hand with the same value! */ X`09 if (whose_crib == ME) `7B /* our crib! Pick hand with BEST crib cards!* V/ X`09 for (i=0;i best) `7B X`09 best = j; X`09`09hand_to_use = i;`09/* save this index! */ X`09 `7D X`09 `7D X`09 `7D X`09 else `7B /* other players crib. Pick hand with WORST crib cards! */ X`09 for (i=0;ii2) swap(i1,i2); /* Make sure that i1 is < i2. */ X X`09crib_hand.card`5B2`5D = your_hand.card`5Bi1`5D; X`09crib_hand.status`5B2`5D = AVAILABLE; X`09crib_hand.card`5B3`5D = your_hand.card`5Bi2`5D; X`09crib_hand.status`5B3`5D = AVAILABLE; X X`09your_hand.status`5Bi1`5D = DISCARDED; X`09your_hand.status`5Bi2`5D = DISCARDED; X`09compress(&your_hand); X`09order(&crib_hand, 4); X X`09remove_card(your_card_win,i1,YOU); X`09remove_card(your_card_win,i2-1,YOU); X`7D X Xplay(turn) Xint turn; X`7B X`09/** play the two hands... 'first' is who should discard first.. **/ X X`09int sum, card, cards_played`5B10`5D, total_cards_played = 0; X`09int valid_card, index, a_move, i; X X`09wprintw(i_o_win,"\nNo cards out..\n"); X`09wrefresh(i_o_win); X`09display_hand(my_hand, 4, INVISIBLE, ME); X`09index = 0; X`09sum = 0; X X`09while (total_cards_played < 8) `7B X`09 a_move = 0; X`09 if (turn == ME) X`09 `7B X`09 if (stuck(my_hand, sum))`20 X`09 wprintw(i_o_win,"I can't go!\n"); X`09 else `7B X`09 card = pick_discard(cards_played, index, sum); X`09 wprintw(i_o_win,"I play the %s\n",say_card(card,LONG_FORM)); X`09 a_move++; X`09 `7D X`09 wrefresh(i_o_win); X`09 `7D X`09 else if (stuck(your_hand, sum))`20 X`09 `7B X`09 wprintw(i_o_win,"you can't go!\n"); X`09 wrefresh(i_o_win); X`09 `7D X`09 else `7B X`09 show_hand(your_hand, 4, "Your hand is ","... \n",AVAILABLE); X`09 valid_card = 0; X do `7B X`09 read_a_card("You play the : ",1, &card, &valid_card); X`09 if (value_of(card) + sum > 31) `7B X`09 wprintw(i_o_win,"That'll take us over 31!\n"); X`09 valid_card = 1; X`09 `7D X`09 else if ((valid_card = mark_as_played(&your_hand, card, YOU)) != 0) X`09 wprintw(i_o_win,"You don't have that card to play!\n"); X`09 wrefresh(i_o_win); X`09 `7D while (valid_card == 1); X`09 a_move++; X`09 `7D X X`09 if (a_move) `7B X`09 total_cards_played++; X`09 add_to_played(turn, card, cards_played, &index, &sum, X total_cards_played); X`09 `7D X X`09 turn = ! turn; X`09`7D X`7D X Xtotal_points(who) Xint who; X`7B X`09/** sum up points for each hand... **/ X X`09int points_in_hand; X X`09if (who == ME) `7B /* computer crib, so player counts first! */ X`09 display_hand(your_hand, 4, VISIBLE, YOU); +-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-