[comp.sources.games] v09i048: tttt2 - tic-tac-toc-toe with wraparound edges

billr@saab.CNA.TEK.COM (Bill Randle) (05/08/90)

Submitted-by: Eric Lechner <lechner@ucscb.ucsc.edu>
Posting-number: Volume 9, Issue 48
Archive-name: tttt2/Patch1
Patch-To: tttt2: Volume 9, Issue 36

[From the author:]
[[This patch fixes a small bug that would let the computer
player occasionally move on squares that already had
pieces, which it shouldn't have done.

It also now uses "rand()" instead of "random()" so it'll
compile straight off on systemV machines, and has a define
if your curses package uses "crmode()" instead of "cbreak()".]]

	[I made a slight change to ifdef the rand/random code
	 to use random/lrand48/rand, depending on the define.  -br]

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  patches01
# Wrapped by billr@saab on Mon May  7 08:53:55 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'patches01' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patches01'\"
else
echo shar: Extracting \"'patches01'\" \(4361 characters\)
sed "s/^X//" >'patches01' <<'END_OF_FILE'
X*** tttt.c.orig	Wed Apr 11 17:33:26 1990
X--- tttt.c	Mon May  7 08:43:34 1990
X***************
X*** 41,46 ****
X--- 41,55 ----
X  #define FALSE	0
X  #endif
X  
X+ #ifdef BSD
X+ # define rand	random
X+ # define srand	srandom
X+ #else
X+ /* Current versions of System V */
X+ # define rand	lrand48		/* comment this out if you only have rand() */
X+ # define srand	srand48		/* comment this out if you only have srand() */
X+ #endif
X+ 
X  char board [4][4];		/* this is the playing board */
X  int pieces;
X  int randomness;			/* whether the computer uses randomness */
X***************
X*** 143,153 ****
X  
X  	initscr();
X  	savetty();
X  	cbreak();
X  	noecho();
X  
X  	signal(SIGINT,quit);
X! 	srandom(getpid() * (1 + getuid()));
X  
X  	clear();
X  
X--- 152,166 ----
X  
X  	initscr();
X  	savetty();
X+ #ifdef CRMODE
X+ 	crmode();
X+ #else
X  	cbreak();
X+ #endif
X  	noecho();
X  
X  	signal(SIGINT,quit);
X! 	srand(getpid());
X  
X  	clear();
X  
X***************
X*** 391,404 ****
X  int computer_move(type)
X  int type;
X  {
X! 	int bestrow = 0, bestcol = 0, i, j;
X! 	int bestrank = 0, numbest = 0, rank, numrank;
X  		/* rank == the rank score */
X  		/* num == the number of times the score happened */
X  
X  	for (i=0; i<4; i++) {
X  		for (j=0; j<4; j++) {
X  			getrank(type,i,j,&rank,&numrank);
X  			if (rank > bestrank) {
X  				bestrow = i;
X  				bestcol = j;
X--- 404,420 ----
X  int computer_move(type)
X  int type;
X  {
X! 	int bestrow, bestcol, i, j;
X! 	int bestrank, numbest, rank, numrank;
X  		/* rank == the rank score */
X  		/* num == the number of times the score happened */
X  
X+ 	bestrow = bestcol = bestrank = numbest = 0;
X+ 
X  	for (i=0; i<4; i++) {
X  		for (j=0; j<4; j++) {
X  			getrank(type,i,j,&rank,&numrank);
X+ 			if (rank == 0) continue;
X  			if (rank > bestrank) {
X  				bestrow = i;
X  				bestcol = j;
X***************
X*** 411,417 ****
X  					bestrank = rank;
X  					numbest = numrank;
X  				} else if (numrank == numbest) {
X! 					if ((random() % 2) && randomness) {
X  						bestrow = i;
X  						bestcol = j;
X  						bestrank = rank;
X--- 427,433 ----
X  					bestrank = rank;
X  					numbest = numrank;
X  				} else if (numrank == numbest) {
X! 					if ((rand() % 2) && randomness) {
X  						bestrow = i;
X  						bestcol = j;
X  						bestrank = rank;
X***************
X*** 435,443 ****
X  	this ranks a move location in order of "preference".
X  
X  	the strategy is to not let the opponent get lots in a row.
X  	ever.
X  
X- 
X  	rows, columns, and diagonals get treated independently, and
X  	the "best" rank of them all is considered.
X  */
X--- 451,459 ----
X  	this ranks a move location in order of "preference".
X  
X  	the strategy is to not let the opponent get lots in a row.
X+ 
X  	ever.
X  
X  	rows, columns, and diagonals get treated independently, and
X  	the "best" rank of them all is considered.
X  */
X***************
X*** 450,456 ****
X  	*numrank = 0;
X  
X  	/* if already taken, this isn't a good spot */
X! 	if (board[row][col]) return;
X  
X  	/* check across */
X  	countx = counto = 0;
X--- 466,472 ----
X  	*numrank = 0;
X  
X  	/* if already taken, this isn't a good spot */
X! 	if (board[row][col] != EMPTY) return;
X  
X  	/* check across */
X  	countx = counto = 0;
X***************
X*** 490,496 ****
X  
X  	/* add one, so that even no blocks still shows as a valid move	*/
X  	/* and return the rank for this move				*/
X! 	*rank++;
X  }
X  
X  /*
X--- 506,512 ----
X  
X  	/* add one, so that even no blocks still shows as a valid move	*/
X  	/* and return the rank for this move				*/
X! 	++(*rank);
X  }
X  
X  /*
X*** Makefile.orig	Wed Apr 11 17:33:24 1990
X--- Makefile	Mon May  7 08:52:48 1990
X***************
X*** 2,7 ****
X--- 2,13 ----
X  #
X  # edit as necessary, then make
X  
X+ # CRMODE: if your version of curses uses "crmode()"
X+ #         instead of "cbreak()", define CRMODE here.
X+ # BSD: if your OS supports random() and srandom()
X+ #FLAGS = -DCRMODE
X+ FLAGS =
X+ 
X  # where the executable will go
X  BINDIR = /usr/games
X  
X***************
X*** 15,21 ****
X  LIBS = -lcurses -ltermcap
X  
X  tttt: tttt.c
X! 	cc $(CFLAGS) -o tttt tttt.c $(LIBS)
X  
X  install: tttt tttt.man
X  	cp tttt $(BINDIR)/tttt
X--- 21,27 ----
X  LIBS = -lcurses -ltermcap
X  
X  tttt: tttt.c
X! 	cc $(CFLAGS) $(FLAGS) -o tttt tttt.c $(LIBS)
X  
X  install: tttt tttt.man
X  	cp tttt $(BINDIR)/tttt
X*** /dev/null	Mon May  7 08:50:00 1990
X--- patchlevel.h	Mon May  7 08:53:24 1990
X***************
X*** 0 ****
X--- 1 ----
X+ #define PATCHLEVEL	1
END_OF_FILE
if test 4361 -ne `wc -c <'patches01'`; then
    echo shar: \"'patches01'\" unpacked with wrong size!
fi
# end of 'patches01'
fi
echo shar: End of shell archive.
exit 0