Battleship Update

Bruce Holloway holloway at drivax.UUCP
Sat Mar 8 08:55:46 AEST 1986


Following is a difference file from the old Battleship game (the one
with curses) to a newer one with some bug fixes and several additions.

The three #defines near the top of the resulting file change the way
the game plays:

	NOBLITZ		If defined: Players always alternate
			If undefined: Turns continue as long as player hits

	NOASK		If defined: Computer sees whether it hits or misses
			If undefined: Computer asks if it hits or misses

	SEEMISS		If defined: Computer misses show up on players screen
			If undefined: Computer keeps track of its own misses

Also, I changed the strategy slightly so that it's less deterministic. And
the program checks LOGNAME for the player's name, or uses Stranger if LOGNAME
is undefined.

The difference file follows. If you call it battle.dif, and the original
source battle.c, then the shell command

	(cat battle.dif; echo '1,$p') | ed - battle.c >battle.new

will create the new version, battle.new.

------------------------------------------------------------------------------
439c
    i = 18 + strlen(name);
.
409c
    else{
#ifdef SEEMISS
	mvaddch(7+(c/10),3+3*(c%10),' ');
#endif
	if(cdir == -2) cdir = -1;
	}
.
400a
#endif
.
389a
#ifdef NOASK
    res = (board[OTHER][c]) ? 'H' : 'M';
    move(21,0); clrtoeol();
    printw("I shoot at %c%d. I %s!",c/10+'A',c%10,(res=='H')?"hit":"miss");
#else
.
343c
		} while(((x+huntoffs) % srchstep) != (y % srchstep));
.
296c
	    move(23,0); clrtoeol(); beep();
	    printw(m,cpuship[c-1].name); refresh();
.
120a
    huntoffs = rnd(srchstep);
.
69a
    if(tmpname = getenv("LOGNAME"))
	strcpy(name,tmpname);
    else
	strcpy(name,dftname);
    name[0] = toupper(name[0]);

.
66a
    srand(time(0L));			/* Kick the random number generator */

.
65a
    extern char *getenv();
    char *tmpname;
.
55a
#endif
.
54a
#ifdef NOBLITZ
	    if(turn) cputurn(); else plyturn();
#else
.
48a
int huntoffs;				/* Offset on search strategy */
.
15c
char name[40];
char dftname[] = "Stranger";
.
6a
#define	NOBLITZ	0		/* Defined if HITs don't mean you get to 
				   continue wiping out your opponent. */
#define	NOASK	0		/* Defined if the computer figures out whether
				   it hits without bothering yout about it. */
#define	SEEMISS	0		/* Defined if the player sees the computer's
				   misses. */

.
-- 

+----------------------------------------------------------------------------+
|Whatever I write are not the opinions or policies of Digital Research, Inc.,|
|and probably won't be in the foreseeable future.                            |
+----------------------------------------------------------------------------+

Bruce Holloway

....!ucbvax!hplabs!amdahl!drivax!holloway
(I'm not THAT Bruce Holloway, I'm the other one.)



More information about the Comp.sources.bugs mailing list