$! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 18-JUN-1993 00:00:58.33 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 2 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. FILES.;1 $! 2. GAME.C;1 $! 3. MAIN.C;1 $! 4. MAKEFILE.;1 $! 5. README.;1 $! 6. SHUFFLE.H;1 $! 7. SWITCH.C;1 $! 8. VISUAL.C;1 $! 9. XRAND.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' XYou should have: X XMakefile:`09this is the makefile, it needs some modification of directory X`09`09names X Xshuffle.6:`09this is the unix style manual page formatted in -man macros X`09`09you can modify the filenames in it. X Xshuffle.h`09this is the include file for the include files I use. X`09`09Here are also some modifications necessary. X X XThe rest of the files are the source files, this is a manifest of them: X Xgame.c Xmain.c Xswitch.c Xvisual.c Xxrand.c $ CALL UNPACK FILES.;1 222308670 $ create 'f' X/* X** Written by Stephan Dasia. X** X** permission is granted to freely distribute this code provided that you: X** X** 1) don't charge for it X** 2) leave my name and header on it X** 3) clearly document your changes and place your name on them X** 4) and please send the changes to me X** X*/ X/* Shuffle: game()`09This is main game loop`09`09`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X/* end_game()`09This procedure is called when a level`09`09*/ X/*`09`09`09is ended. It quits if you did it in to`09`09*/ X/*`09`09`09many turns.`09`09`09`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X X#include "shuffle.h" X Xgame(row,level) Xint *row`5B`5D,level; X`7B X int nbr ,counter; X char c; X X do X `7B X counter=0; X screen(); X switch_row(row,level); X draw_row(row,level,counter); X if(counter==0) X `7B X move(18,20); X printw("Which switch ? "); X mvcur(0,0,18,35); X `7D X refresh(); X do X `7B X do X `7B X c=getch(); X c&=0x7f; X`09nbr=0; X if(c>='1' && c<='4') X `7B X counter++; X nbr=1; X mvcur(0,0,18,35); X printw("%c",c); X `7D X if(c=='\022') X `7B X`09 clear(); X screen(); X draw_row(row,level,counter); X refresh(); X `7D X if(c=='?' `7C`7C c=='h' `7C`7C c=='H') X `7B X clear(); X help(); X refresh(); X while((c=getch()) != ' '); X`09 clear(); X screen(); X draw_row(row,level,counter); X refresh(); X `7D X `7D X while( nbr!=1 && c!='?' && c!='h' && c!='H' && c!='q' && c!='Q'); X do_switch(row,c-'0'); X draw_row(row,level,counter); X refresh(); X `7D X while(test_row(row) ==0 && c!='q' && c!='Q'); X if(c!='q' && c!='Q') X end_game(counter,level); X level++; X `7D X while(c!='q' && c!='Q' && counter to continue"); X refresh(); X move(20,67); X clrtoeol(); X while((x=getch()) !=' '); X `7D X else X `7B X printw("You did it in %d switches and",cntr); X printw(" it could be done in %d switches.\n\n",lvl*FAC1); `20 X refresh(); X exit(); X `7D X`7D $ CALL UNPACK GAME.C;1 1766977699 $ create 'f' X/* X** Written by Stephan Dasia. X** X** permission is granted to freely distribute this code provided that you: X** X** 1) don't charge for it X** 2) leave my name and header on it X** 3) clearly document your changes and place your name on them X** 4) and please send the changes to me X** X*/ X/* Shuffle: main()`09Gets the options and executes them`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X/*`09 test_row()`09Test the order of the numbers`09`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X/*`09 draw_row()`09Draw the numbers on the screen`09`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X X#include "shuffle.h" X X Xmain(argc, argv, optstring) Xint argc; Xchar **argv,*optstring; X`7B X int row`5B9`5D, t, level; X char c; Xextern char *optarg; Xextern int optind,opterr; X X initscr(); X crmode(); X nonl(); noecho(); standend(); X X for(t=1;t<10;t++) row`5Bt`5D=t; X level=1; X if(argv`5B1`5D && !strcmp(argv`5B1`5D, "-")) X `7B X fprintf(stderr, "Usage: %s `5B-`5D `5B-L level`5D\n", argv`5B0`5D); X fprintf(stderr, "\t- - give this summary of usage\n"); X fprintf(stderr, "\tL `5Blevel`5D - start at `5Blevel`5D of difficulty\n" V); X exit(0); X `7D X X`09/* process the arguments to the program */ X/* X * while((c = getopt(argc, argv, "L:")) != EOF) X * `7B X * switch(c) X * `7B X * case 'L': X * `09 level = (int)atoi(optarg); X *`09 if(level>MAXLEVEL) X *`09 level = MAXLEVEL; X *`09 break; X * default: X * fprintf(stderr, "Unknown flag or improper usage:\n"); X * fprintf(stderr, "\tuse '%s -' for usage\n", argv`5B0`5D); X * exit(1); X * `7D X * `7D X */ X X game(row,level); X endwin(); X`7D X X Xtest_level(lvl) Xint lvl; X`7B X int temp; X temp = lvl*FAC1*FAC2+0.5; X temp = temp % (MAXPLAY_L+1) ; X return temp; X`7D X X Xtest_row(rwt) /* test the correct order of the number Vs */ Xint rwt`5B`5D; X`7B X int bl=0,q,cnt=0; X X for(q=1;q<10;q++) X if(rwt`5Bq`5D==q) cnt++; X if(cnt==9) bl=1; X return(bl); X`7D X X Xdraw_row(rw,lvl,cntr) /* Draw the numbers on the screen */ Xint *rw`5B`5D,lvl,cntr; X`7B X move(11,3); X printw("`7C %d `7C `7C %d `7C `7C %d `7C ",rw`5B1`5D,rw`5B2`5D,rw`5B V3`5D); X printw("`7C %d `7C `7C %d `7C `7C %d `7C ",rw`5B4`5D,rw`5B5`5D,rw`5B V6`5D); X printw("`7C %d `7C `7C %d `7C `7C %d `7C \n",rw`5B7`5D,rw`5B8`5D,rw`5B V9`5D); X move(18,10); X printw("%d",lvl); X move(18,42); X if(cntr!=0) X printw("moves : %d",cntr); X else X printw("moves : "); X move(18,20); X printw("Last switch ? "); X mvcur(0,0,18,35); X`7D $ CALL UNPACK MAIN.C;1 124198133 $ create 'f' X# X# Makefile for shuffle V1.0 X# X# 21/11/89 X# X# Stephan Dasia stephand@maestro.htsa.aha.nl X# stephand@htsa.UUCP X# ...!hp4nl!htsa!stephand X X X# Use these lines for BSD. X#Add library 'lseq' for sequent system. XLIBS= -lcurses -ltermcap -lm XCFLAGS = -O X X# uncomment these lines for SYSV X#LIBS= -lcurses -lm X#CFLAGS = -O -DSYSV X X# If you can compile on a sequent system use : X#PARALLEL= & X#else XPARALLEL= X XCC = cc X X# where the binary will go XDESTDIR = /usr/local/games XMANDIR`09= /usr/man/man6 X XINC = `09shuffle.h X XSRC =`09game.c\ X`09main.c\ X`09switch.c\ X`09visual.c\ X`09xrand.c X XOBJ = `09game.o\ X`09main.o\ X`09switch.o\ X`09visual.o\ X`09xrand.o X Xshuffle: $(PARALLEL) $(OBJ) $(INC) X`09 cc -o shuffle $(OBJ) $(LIBS) X Xdebug: $(PARALLEL) $(OBJ) $(INC) X`09cc -g -o shuffle $(OBJ) $(LIBS) X Xinstall: shuffle X`09install -s -m 711 shuffle $(DESTDIR) X`09install -o -m 400 shuffle.6 $(MANDIR) X#`09install -s -o games -m 711 shuffle $(DESTDIR) X#`09install -o manual -400 shuffle.6 $(MANDIR) X Xclean: X`09/bin/rm -rf shuffle *.o core X Xshar: X`09@/bin/rm -rf ../shuffle.shar X`09shar -vc README FILES Makefile *.c *.h shuffle.man > ../shuffle.shar X Xall: clean shuffle install X Xdepend: X`09mkdep $(CFLAGS) $(SRC) X X# DO NOT DELETE THIS LINE -- mkdep uses it. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. X Xgame.o: game.c shuffle.h /usr/include/stdio.h /usr/include/math.h Xgame.o: /usr/include/curses.h /usr/include/stdio.h /usr/include/sgtty.h Xgame.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h Xgame.o: /usr/include/sys/ttydev.h /usr/include/sgtty.h Xmain.o: main.c shuffle.h /usr/include/stdio.h /usr/include/math.h Xmain.o: /usr/include/curses.h /usr/include/stdio.h /usr/include/sgtty.h Xmain.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h Xmain.o: /usr/include/sys/ttydev.h /usr/include/sgtty.h Xswitch.o: switch.c shuffle.h /usr/include/stdio.h /usr/include/math.h Xswitch.o: /usr/include/curses.h /usr/include/stdio.h /usr/include/sgtty.h Xswitch.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h Xswitch.o: /usr/include/sys/ttydev.h /usr/include/sgtty.h Xvisual.o: visual.c shuffle.h /usr/include/stdio.h /usr/include/math.h Xvisual.o: /usr/include/curses.h /usr/include/stdio.h /usr/include/sgtty.h Xvisual.o: /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h Xvisual.o: /usr/include/sys/ttydev.h /usr/include/sgtty.h Xxrand.o: xrand.c X X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY $ CALL UNPACK MAKEFILE.;1 1510306828 $ create 'f' XShuffle: X X`09I wrote this as a way to learn curses. X X`09I have successfully compiled and run shuffle on a Sequent X`09running under 4.2BSD and a HP9000 running under HP-UX X X`09When I first wrote this I had a little knowledge of how to X`09make the code portable, so if you patch the code to run on X`09another system I would REALLY appreciate your input and code. X X`09Stephan Dasia X`09stephand@maestro.htsa.aha.nl X`09stephand@htsa.UUCP X`09...!hp4nl!htsa!stephand X XTo compile on VMS: X X CC each file independently, then X LINK GAME,MAIN,SWITCH,VISUAL,XRAND,SYS$LIBRARY:VAXCCURSE/LIBRARY, X SYS$LIBRARY:VAXCRTL X RENAME GAME.EXE to SHUFFLE.EXE X X -Nick Triantos X MASNICK @ UBVMS.CC.BUFFALO.EDU X MASNICK @ UBVMS.BITNET $ CALL UNPACK README.;1 1551830441 $ create 'f' X/* X** Written by Stephan Dasia. X** X** permission is granted to freely distribute this code provided that you: X** X** 1) don't charge for it X** 2) leave my name and header on it X** 3) clearly document your changes and place your name on them X** 4) and please send the changes to me X** X*/ X/* Shuffle: shuffle.h`09`09`09`09`09`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X/* this is the header file, it does all the necessary includes.`09`09*/ X X X#include X#include X#include X X/* Here start the definitions of the random generator. I've used an`09*/ X/* other random generator which is declared in xrand.c.`09`09`09*/ `20 X X#define RANDOM1`09`09rnd_i X#define RANDOM2`09`09rnd_init X X/* Here are the definitions of MAXLEVEL, be sure that the last number`09*/ X/* of MAXLEVEL is a 0.`09`09`09`09`09`09`09*/ X X#define FAC1`09`095 X#define FAC2`09`091.1 X#define MAXLEVEL `091000 X#define MAXCOMP_L`095000`09/* MAXLEVEL*FAC1`09`09`09*/ X#define MAXPLAY_L`095500`09/* MAXCOMP_L*FAC2`09`09`09*/ $ CALL UNPACK SHUFFLE.H;1 356595283 $ create 'f' X/* X** Written by Stephan Dasia. X** X** permission is granted to freely distribute this code provided that you: X** X** 1) don't charge for it X** 2) leave my name and header on it X** 3) clearly document your changes and place your name on them X** 4) and please send the changes to me X** X*/ X/* Shuffle: switch_row`09`09switch the numbers for the computer`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X/*`09 do_switch()`09`09switch the numbers for the player`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X/*`09 switch_number()`09switch the numbers`09`09`09*/ X/*`09`09`09`09`09`09`09`09`09*/ X X#include "shuffle.h" X X Xswitch_row(rw,lvl)`09/* switch the numbers for the computer */ Xint *rw`5B`5D , lvl; X`7B X int r`5BMAXPLAY_L`5D,cnt,df,x; X X RANDOM2(time(0)); X do X `7B X x=2; X r`5Bx-2`5D=RANDOM1()%4+1; X do X `7B X r`5Bx-1`5D=RANDOM1()%4+1; X `7D X while(r`5Bx-2`5D==r`5Bx-1`5D); +-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-