bomb - repost for vms

Eric Olson ejo at ims.alaska.edu
Mon May 27 07:52:38 AEST 1991


Whoops!

There was an error in the com file to build bomb on vms systems.  If
you use a good compile program, you wouldn't need to worry about it,
but I'll post a correction anyway.  Because a) it's a fairly small
share file and b) the last posting was of a unix share file, I'm just
going to repost the whole thing in a vms_shar share file.
***
$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On 26-MAY-1991 12:49:51.89   By user EJO 
$!
$! 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. BOMB.C;1
$!       2. BUILD_VMS.COM;2
$!       3. MAKEFILE.;1
$!       4. README.BOMB;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/* bomb.c, by Eric Olson. */
X/*    version 1.0 */
X/* This program is copyright 1991 by Eric Olson.  You are welcome to
X   distribute it, but this notice should remain intact and you should
X   include all the files that were distributed with it.  This program is
X   not to be sold, although a fee may be charged to cover distribution
X   expenses (if there are any).  If you wish to modify the code and
X   distribute it, please feel free to do so, but label the code as
X   modified here and change the version accordingly. */
X
X#include <stdio.h>
X#include <curses.h>
X
X#ifdef VMS
Xunsigned char _getch() /* kent d ramier 20 feb 88 */ /* eo ruined spacing */
X `7B struct `7B unsigned short length; unsigned char dtype; unsigned char
X class; char *pointer; `7D device = `7B 9, 14, 1, "SYS$INPUT"`7D; static
X unsigned short a_channel = 0; unsigned char the_key; if (!(a_channel))
X SYS$ASSIGN(&device,&a_channel,0,0); SYS$QIOW
X (0,a_channel,625,0,0,0,&the_key,1,1,0,0,0); return(the_key); `7D
X# define GETCH (_getch())
X#else
X  /* if you're not on VAX/VMS, you may need to refit this. */
X  /* it does occasionally leave numbers on my screen. */
X# define GETCH (getch())
X#endif VMS
X
X#define MAX 16 /* boardsize */
X
X/* this is a terrible random generator.  Make a better one. */
X#include <math.h>
X#include <time.h>
X#define RANDOM ((int)((float)rand()/((float)((unsigned)(-1)))*2.0*(float)(MA
VX)))
X#define RANDOM_SEED srand(time((time_t *)0))
X
Xshort think`5BMAX`5D`5BMAX`5D,grid`5BMAX`5D`5BMAX`5D,boom;
Xint xx=0,yy=0;
X
X#define NOTYET 9
X#define BOMB 10
X#define OKAY 11
Xstatic char icon`5B`5D=" 12345678.*o";
X
Xdrawscr()
X`7B
Xint i,j;
X
Xfor (i=0;i<MAX;i++)
X  for (j=0;j<MAX;j++)
X    `7B
X      move(j,i*2);
X/*       printw("(%c)",icon`5Bthink`5Bi`5D`5Bj`5D`5D); */
X      printw(" %c",icon`5Bthink`5Bi`5D`5Bj`5D`5D);
X    `7D
X/* mvaddch(yy,xx*2+1,'#');`20
Xmvaddch(yy,xx*2,'`5B'); mvaddch(yy,xx*2+2,'`5D');
Xmvaddch(yy,xx*2,'>'); */
X`7D
X
Xshort invalid(i,j)
Xint i,j;
X`7B
X  if ((i==j) && ((i==0) `7C`7C (i==MAX-1))) return (1);
X  if ((i<2) && (j<2)) return (1);
X  if ((i==MAX) `7C`7C (j==MAX)) return (1);
X  if (grid`5Bi`5D`5Bj`5D) return (1);
X  return (0);
X`7D
X
Xanalyze(x,y)
Xint x,y;
X`7B
Xint i,j,t=0;
X
Xfor (i= -1;i<2;i++)
X  for (j= -1;j<2;j++)
X    if ((i+x>=0) && (j+y>=0) && (i+x<MAX) && (j+y<MAX))
X      if (grid`5Bi+x`5D`5Bj+y`5D) t++;
Xthink`5Bx`5D`5By`5D=t;
Xif (!t)
X  for (i= -1;i<2;i++)
X    for (j= -1;j<2;j++)
X      if ((i+x>=0) && (j+y>=0) && (i+x<MAX) && (j+y<MAX))
X        if (think`5Bi+x`5D`5Bj+y`5D==NOTYET) analyze(i+x,j+y);
X`7D
X
Xtoggle(x,y)
Xint x,y;
X`7B
Xswitch (think`5Bx`5D`5By`5D)
X  `7B
X    case NOTYET: think`5Bx`5D`5By`5D=BOMB; break;
X    case BOMB: think`5Bx`5D`5By`5D=OKAY; break;
X    case OKAY: think`5Bx`5D`5By`5D=NOTYET; break;
X  `7D
X`7D
X
Xmoveto(x,y)
X`7B
Xint i,j,q=0;
X
Xfor (i= -1;i<2;i++)
X  for (j= -1;j<2;j++)
X    if ((i+x>=0) && (i+x<MAX) && (j+y<MAX) && (j+y>=0))
X      if (think`5Bi+x`5D`5Bj+y`5D<NOTYET) q=1;
Xif (!q) return(0);
X
Xxx=x; yy=y; analyze(x,y);
X
Xif (grid`5Bx`5D`5By`5D) boom=2;
Xif ((y==MAX-1) && (x==MAX-1)) boom=1;
X`7D
X
Xmain(argc,argv)
Xint argc; char **argv;
X`7B
Xint i,j,k,nb=30;
Xchar c;
X
Xif (argc>1)
X  `7B
X    sscanf(argv`5B1`5D,"%d",&nb);
X    if ((nb<1) `7C`7C (nb>(MAX*(MAX-2))))
X      `7B
X        printf ("Invalid number of bombs."); exit(0);
X      `7D
X  `7D
X
Xinitscr();
XRANDOM_SEED;
X
Xfor (i=0;i<MAX;i++)
X  for (j=0;j<MAX;j++)
X    think`5Bi`5D`5Bj`5D=NOTYET,grid`5Bi`5D`5Bj`5D=0;
Xfor (k=0;k<nb;k++)
X  `7B
X    for (i=j=0;invalid(i,j);)
X      i=RANDOM,j=RANDOM;
X    grid`5Bi`5D`5Bj`5D=1;
X  `7D
X
Xanalyze(0,0);
Xprintf("%c>",27);
X
Xfor (i=j=boom=0;!boom;)
X  `7B
X    drawscr();
X    move(j,i*2+1); refresh();
X    c=GETCH;
X    switch (c)
X      `7B
X        case '1': i--;
X        case '2': j++; break;
X        case '7': j--;
X        case '4': i--; break;
X        case '9': i++;
X        case '8': j--; break;
X        case '3': j++;
X        case '6': i++; break;
X        case ' ': toggle(i,j); break;
X        case 12: clear(); refresh(); break;
X        /* case '\n': */ case 13: case 10: moveto(i,j);
X        default: break;
X      `7D
X    if (i<0) i=0; if (i>=MAX) i=MAX-1; if (j<0) j=0; if (j>=MAX) j=MAX-1;
X  `7D
X
Xendwin();
Xif (boom==1) printf ("Good job!\n");
Xelse printf ("***BOOM***\n");
Xfor (j=0;j<MAX;j++,printf("\n"))
X  for (i=0;i<MAX;i++)
X    `7B
X      if (think`5Bi`5D`5Bj`5D<NOTYET)
X        if (grid`5Bi`5D`5Bj`5D) printf ("*  ");
X        else printf ("o  ");
X      else
X        if (think`5Bi`5D`5Bj`5D==NOTYET)
X          if (grid`5Bi`5D`5Bj`5D)
X            printf ("*. ");
X            else printf ("o. ");
X        else
X          if (think`5Bi`5D`5Bj`5D==BOMB)
X            if (grid`5Bi`5D`5Bj`5D)
X              printf ("*! ");
X            else printf ("o? ");
X          else
X            if (grid`5Bi`5D`5Bj`5D)
X              printf ("*? ");
X            else printf ("o! ");`20
X    `7D
Xprintf ("\n*=bomb, o=okay     .=no guess, !=right, ?=wrong\n\n");
X`7D
$ CALL UNPACK BOMB.C;1 576792176
$ create 'f'
X$ cc bomb
X$ link bomb+sys$input/opt
Xsys$share:vaxcrtl/share
X$ delete bomb.obj;
X$ pu bomb.exe
$ CALL UNPACK BUILD_VMS.COM;2 1262573862
$ create 'f'
X# makefile for bomb
X#
XCC= cc
X
X# your system may not require termlib to be loaded
XLIBRARIES= -lm -lcurses -ltermlib
X
X# use -g for debugging, if necessary
XFLAGS= -O
X
Xdefault: bomb
X
Xbomb: bomb.c
X`09$(CC) $(FLAGS) -o bomb bomb.c $(LIBRARIES)
X
$ CALL UNPACK MAKEFILE.;1 806617433
$ create 'f'
XBomb is a simple game of deduction.  There is a 16x16 grid containing
Xsome number of bombs (the default is 30) which you must move through.
XEach sector is denoted by a number from 1 to 8 representing the number
Xof bombs immediately adjacent to it, a space (if there are no bombs
Xadjacent to it), or a period (if you haven't been there yet).  You may
Xplace a guess as to what a given sector is by positioning the cursor
Xon it (with the number keys) and pressing the space bar; this will
Xtoggle the sector's classification between unknown (.), bomb (*), and
Xokay (o).  You start in the upper left hand corner and the object is
Xto work your way into the lower right hand corner.  If you believe a
Xsector to be safe, you can move into it by pressing return.  Control-l
Xwill redraw the screen.  If you move into a sector which does not
Xborder on any bombs, the computer will automatically move into each
Xsector around it.  You may only move into sectors adjacent to sectors
Xyou have already visited.  There are never any bombs bordering on your
Xstarting square.
X
XBomb compiles and runs successfully for the following operating systems:
X
XSunOS 4.1, Ultrix 4.1, and VAX/VMS.
X
XIf you compile bomb successfully on another machine, please add it to
Xthe list.
$ CALL UNPACK README.BOMB;1 1226440836
$ v=f$verify(v)
$ EXIT



More information about the Alt.sources mailing list