$! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 24-SEP-1992 08:37:09.86 By user MASLIB $! $! This VMS_SHARE Written by: $! Andy Harper, Kings College London UK $! $! Acknowledgements to: $! James Gray - Original VMS_SHARE $! Michael Bednarek - Original Concept and implementation $! $! 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. MASTER.C;1 $! 2. MASTER.H;1 $! 3. RANDOM.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#include stdio X#include stdlib X#include smgdef X#include descrip X#include "master.h" X#include "random.c" X Xon_ctrl()`09`09`09`09`09/* enable control-C */ X`7B Xint mask = 0x02000000; Xlib$enable_ctrl(&mask); X`7D X`09 Xno_ctrl()`09`09`09`09`09/* disable control-C */ X`7B Xint mask = 0x02000000; Xlib$disable_ctrl(&mask); X`7D X Xcreate_windows() `09`09`09`09/* Handle the windows stuff */ X`7B Xsmg$create_pasteboard(&pb); Xsmg$create_virtual_keyboard(&kboard); Xsmg$set_cursor_mode(&pb,&SMG$M_SCROLL_JUMP); Xsmg$create_virtual_display(&21,&13,&dsp_main,&SMG$M_BORDER); Xsmg$create_virtual_display(&21,&11,&dsp_score,&SMG$M_BORDER); Xsmg$create_virtual_display(&21,&9,&dsp_pegs,&SMG$M_BORDER); Xsmg$create_virtual_display(&21,&43,&dsp_help); Xsmg$create_virtual_display(&1,&78,&dsp_text); Xsmg$set_keypad_mode(&kboard,&SMG$M_KEYPAD_APPLICATION); X`7D X X Xput_windows()`09`09`09`09`09/* put windows on the screen */ X`7B Xint i; X/* Note: since the help display is not bordered, you have to paste it before V`20 X pasting the score display in order to get the border for the score V */ Xsmg$begin_pasteboard_update(&pb); Xsmg$paste_virtual_display(&dsp_pegs,&pb,&2,&2); Xfor( i=2; i< 22; i+=2)`20 X smg$draw_line(&dsp_pegs,&i,&1,&i,&9); Xsmg$paste_virtual_display(&dsp_main,&pb,&2,&12); Xfor( i=2; i< 22; i+=2)`20 X smg$draw_line(&dsp_main,&i,&1,&i,&13); Xsmg$paste_virtual_display(&dsp_help,&pb,&2,&37); Xsmg$paste_virtual_display(&dsp_score,&pb,&2,&26); Xsmg$paste_virtual_display(&dsp_text,&pb,&24,&1); Xsmg$draw_line(&dsp_score,&2,&1,&2,&11); Xsmg$end_pasteboard_update(&pb); X`7D X X Xdelete_windows()`09`09`09`09/* clear screen */ X`7B Xsmg$delete_virtual_keyboard(&kboard); Xsmg$delete_pasteboard(&pb); X`7D X X Xprt_help() X`7B Xint i, row; X Xi = row = 0; Xwhile( helptext`5Bi`5D != NULL) prt( dsp_help, helptext`5Bi++`5D, ++row, 2, V 0); X`7D X X Xprt( display, message, y, x, flags)`09`09/* put something in a display */ Xint display, y, x, flags; Xchar *message; X`7B Xint text = 0; X$DESCRIPTOR( mess_d, message); X Xif ( display == dsp_text) text = SMG$M_ERASE_TO_EOL; Xmess_d.dsc$w_length = strlen(message); Xsmg$put_chars(&display,&mess_d,&y,&x,&text,&flags); X`7D X Xprt_char( display, ch, row, col, flags) Xchar ch; Xint row, col, flags, display; X`7B Xchar ch_c`5B1`5D; X$DESCRIPTOR( p_char, ch_c); Xch_c`5B0`5D = ch; Xrow++; Xcol++; X Xp_char.dsc$w_length = 1; Xsmg$put_chars(&display,&p_char,&row,&col,0,&flags); X`7D X Xexit_game() X`7B Xon_ctrl(); Xdelete_windows(); Xexit( 0); X`7D X Xprt_color( col) Xint col; X`7B Xprt_char( dsp_main, names`5Bcol`5D`5B0`5D, cur_row, cur_col, SMG$M_BOLD); Xprt_char( dsp_main, names`5Bcol`5D`5B1`5D, cur_row, cur_col+1, SMG$M_BOLD); X`7D X X Xinit_game() X`7B Xint j, i, color, found; Xchar str`5B80`5D; X Xno_ctrl(); Xcreate_windows(); Xput_windows(); Xprt_help(); Xrandomize(); Xprt( dsp_pegs, " Clues ", 1, 1, SMG$M_BOLD); Xprt( dsp_score, " W L %", 1, 1, SMG$M_BOLD); Xscore_row = 3; Xcur_row = 2; Xcur_col = 1; Xfor( i=0; i< game; i++) used`5Bi`5D = 0;`20 Xfor( i=0; i< 4; i++) `7B X guess`5Bi`5D = ' '; X code`5Bi`5D = ' '; X`7D Xfor( i=0; i< 4; i++) `7B X do `7B X color = random( game); X code`5Bi`5D = colors`5Bcolor`5D; X if ( used`5Bcolor`5D) found = TRUE; X else found = FALSE; X `7D while( found); X used`5Bcolor`5D++;`09/* Keep track of how many times that color is used */ X `7D /* End FOR */ Xprt( dsp_main, " XX XX XX XX ", 1, 1, SMG$M_BOLD); Xif ( wins == 0) pcnt = 0; Xelse pcnt = wins/(wins + losses) * 100; Xsprintf( str, "%2.0f %2.0f %3.0f ", wins, losses, pcnt); Xprt( dsp_score, str, score_row, 1, 0); Xcursor(); X`7D X X Xprint_code() X`7B Xint i, j, array`5B4`5D; Xchar str`5B80`5D; X Xfor ( j=0; j< 4; j++) X for ( i=0; i< game; i++) X if ( code`5Bj`5D == colors`5Bi`5D) `7B X array`5Bj`5D = i; X break; X `7D X Xsprintf(str," %s %s %s %s \0", names`5Barray`5B0`5D`5D, names`5Barray`5B1`5D V`5D,`20 X`09`09`09`09`09names`5Barray`5B2`5D`5D, names`5Barray`5B3`5D`5D); Xprt( dsp_main, str, 1, 1, SMG$M_BOLD); X`7D X Xtry_again() X`7B Xchar dummy; X Xprint_code(); Xwhile( 1) `7B X smg$read_keystroke( &kboard, &dummy); X if ( toupper( dummy) == 'Y') `7B X delete_windows(); X init_game();`20 X break; X `7D X else if ( toupper( dummy) == 'N') `7B X delete_windows(); X exit_game(); X break; X `7D X else prt( dsp_text, "Please enter Y or N. ", 1, 1, 0); X`7D /* End while */ X`7D X X Xcursor() X`7B Xint asdf, shit; X Xasdf = cur_row+1; Xshit = cur_col+1; Xsmg$set_cursor_abs( &dsp_main, &asdf, &shit); X`7D X X Xmain( argc, argv) Xint argc; Xchar *argv`5B`5D; X`7B Xint i, j, key, count; Xchar str`5B80`5D; X X/* Begin setup */ Xprintf("As a parameter, use \"m\" for master or \"d\" for difficult games.\n V"); Xlib$wait(&3.0); Xwins = losses = 0; Xgame = REGULAR; X Xif ( argc > 1) `7B X switch( toupper( argv`5B1`5D`5B0`5D)) `7B X `09 case 'M': game = MASTER; break; X`09 case 'D': game = DIFFICULT; break; X default: printf( "There is no option with that letter.\n"); X`09`09 printf( "Valid options are: \"M\" or \"D\".\n"); X`09`09 exit(0); X `7D /* End switch */ X`7D X X/* Do everything to start a game next */ Xinit_game(); X X/* Main loop */ Xwhile( 1) `7B X smg$read_keystroke(&kboard,&key); X key = toupper( key); X switch( key) `7B X case 18: case 12: smg$repaint_screen( &pb); break; X case 26:`20 X `09exit_game(); break; X case 20: /* move left */ X`09if ( (cur_col - 3) < 1) cur_col = 1;`20 X`09else cur_col -= 3; X`09cursor(); X`09break; X case 21: /* move right */ X`09if ( (cur_col + 3) > 10) cur_col = 10; X`09else cur_col += 3; X`09cursor(); X`09break; X case 13: /* select sequence */ X`09count = 0; X`09for ( i=0; i< 4; i++) X`09 if ( guess`5Bi`5D == ' ') `7B X`09 prt( dsp_text, "You must have all four colors selected first.", 1, X`09`09`09`09`09`09`09`09`091, 0); X`09 j = FALSE; X`09 break; X`09 `7D X`09 else j = TRUE; X`09if ( !j) break; X`09for ( j=0; j< 4; j++) `7B X`09 for ( i=0; i< 4; i++)`20 X`09 if ( (guess`5Bi`5D == guess`5Bj`5D) && ( i != j)) `7B X`09 prt( dsp_text,`20 X`09 "Multiple occurrence of single color found. Choose again.", 1, 1, 0); X`09 count = 99; X`09 break; X`09 `7D X`09 if ( count == 99) break; X`09`7D X`09if ( count == 99) break; X`09/* compare computer code and guess here */ X`09for ( j=0; j< 4; j++) X`09 for ( i=0; i< 4; i++) X`09`09if ( guess`5Bi`5D == code`5Bj`5D) `7B X`09`09 if ( i == j) pegs`5Bj`5D = 'X'; X`09`09 else pegs`5Bj`5D = 'o'; X`09`09 break; X`09`09`7D X`09`09else pegs`5Bj`5D = ' '; X`09pegs`5B4`5D = 0; X /* print out pegs for clues */ X`09count = 0; X`09for ( i=0; i< 4; i++) X`09 if ( pegs`5Bi`5D == 'X') X`09 prt_char( dsp_pegs, pegs`5Bi`5D, cur_row, (count++)*2+1, SMG$M_REVERS VE); X`09for ( j=0; j< 4; j++) X`09 if ( pegs`5Bj`5D == 'o') X`09 prt_char( dsp_pegs, pegs`5Bj`5D, cur_row, (count++)*2+1, SMG$M_REVERS VE); X X`09for( i=0; i< 4; i++) guess`5Bi`5D = ' '; X `09cur_row += 2; X`09/* if winner, score here and start new game */`09 X`09if ( strcmp( pegs, "XXXX") == 0) `7B X`09 wins++; X`09 prt( dsp_text, "You won. Would you like to try again? `5By/n`5D ", 1, V 1, X`09`09`09`09`09`09`09`09`09 0); X`09 try_again(); X`09 cur_row = 2; X`09`7D `20 X `09if ( cur_row > 20) `7B X`09 /* end game due to too many guesses */ X`09 losses++; X`09 prt( dsp_text, "You lose. Would you like to try again? `5By/n`5D ", 1, V`20 X`09`09`09`09`09`09`09`09 `09 1, 0); X`09 try_again(); X`09 cur_row = 2; X`09`7D X X`09smg$erase_line( &dsp_text); X`09cur_col = 1; X`09cursor(); X `09break; X default:`20 X for( i=0; i< game; i++) X if ( key == colors`5Bi`5D) `7B X `09 prt_color( i); X`09 if ( cur_col< 4) guess`5B0`5D = key; X`09 else if ( cur_col< 7) guess`5B1`5D = key; X`09 else if ( cur_col< 10) guess`5B2`5D = key; X `09 else guess`5B3`5D = key; X `09 if ( (cur_col + 3) > 10) cur_col = 10; X`09 else cur_col += 3; X`09 cursor(); X break; X `7D X `7D /* End switch */ X`7D /* End while */ X`7D $ CALL UNPACK MASTER.C;1 997623875 $ create 'f' X#define REGULAR`09`096`09`09/* Game type */ X#define DIFFICULT`098`09`09/* Game type */ X#define MASTER`09`0910`09`09/* Game type */ X#define MAXCOLORS `0910`09`09/* Max number of colors */ X X#define TRUE `09`091 X#define FALSE `09`090 X Xint dsp_main, dsp_pegs, dsp_help, dsp_score, dsp_text; Xint kboard, pb; X Xint random_incl, random_seed;`09`09/* for random functions */ X Xint game;`09`09`09`09/* Difficult or Master or Regular */ Xdouble wins, losses, pcnt;`09`09/* Number of wins, losses, and win % */ Xint cur_row, cur_col;`09`09`09/* Cursor position */ Xint score_row; X X/* 10 colors are: red, yellow, green, blue, black, white, orange, tan, brown V,`20 X`09 purple */ Xchar colors`5BMAXCOLORS+1`5D = `7B"RYGUKWOTBP"`7D; Xchar *names`5BMAXCOLORS`5D = `7B X "Rd", "Yl", "Gn", "Bu", "Bk", "Wt", "Or", "Tn", "Br", "Pp" X`7D; Xint used`5BMAXCOLORS`5D; X Xchar pegs`5B4`5D;`09`09/* black and white clue pegs given by computer */ Xchar guess`5B4`5D;`09`09/* player's guess of 4 colors */ Xchar code`5B4`5D;`09`09/* computer code of 4 colors */ X Xchar *helptext`5B`5D = `7B X" MasterMind", X" ", X" Standard Game:", X" R - select RED Y - select YELLOW", X" U - select BLUE K - select BLACK", X" W - select WHITE G - select GREEN", X" ", X" Difficult Game: (2 added colors)", X" O - select ORANGE T - select TAN", X" ", X" Master Game: (4 added colors)", X" B - select BROWN P - select PURPLE", X" ", X" Control-R & Control-L redraw", X" Control-Z exits game", X" selects 4-color sequence", X" and compares to computer code", X" ", X" Clue pegs:", X" X = correct color, correct position", X" o = correct color, incorrect position", XNULL /* End help listing */ X`7D; $ CALL UNPACK MASTER.H;1 2120495476 $ create 'f' Xint randomize() X`7B X int seed; X char dt`5B30`5D; X X $DESCRIPTOR(d_s,dt); X lib$date_time(&d_s); X random_seed=(dt`5B16`5D+dt`5B19`5D*7+dt`5B21`5D*88+dt`5B22`5D*624); X random_incl= (mth$random(&random_seed) % 50); X`7D X Xint random(max_num) X`7B X int seed; X seed=(random_seed + ++random_incl*624); X if (max_num)`20 X return(abs(mth$random(&seed) % max_num)); X else X return(max_num/2); /* Division by zero */ X`7D $ CALL UNPACK RANDOM.C;1 235865404 $ v=f$verify(v) $ EXIT