[net.sources.games] noughts and crosses

roland@ttds.UUCP (Roland Karlsson) (11/01/85)

This program plays the game of noughts and crosses. It uses termcap. Enjoy!

==============================================================================
		Have a nice day wishes:
		Roland Karlsson  (roland@ttds)
		Dpt. of Telecomm. & Computer Systems
		Royal Institute of Technology
		S-100 44 Stockholm
		SWEDEN
==============================================================================

cut - cut ---- cut ------------ cut ---------------------- cut --------------
: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
echo 'Extracting README'
sed 's/^X//' > README << '+ END-OF-FILE README'
XREADME          This file.
X
Xmakefile
X
Xdef.h           header.
X
Xadm.c
X	cheat()         Interupt routine to run when someone trys to
X			exit program.
X	main()          The main program which make initialisations and
X			administrates who is on the move.
X
Xinmove.c
X	normal()        stops the program play self.
X	inmove()        The main event loop.
X	inposition()    Converts text string to position.
X	emptyline()     empty a line at input.
X
Xterminal.c
X	getcap()        Initialises termcap.
X	pos()           Positions on the screen.
X	up()            Move up one line.
X	clear()         Clear screen from cursor.
X	home()          Cursor home.
X
Xutboard.c
X	utboard()       Draws the board.
X
Xautomat.c
X	automat[][]     A computer generated table which defines a finite
X			automat for calculating points in a string of
X			<space> o and x.
X
Xautom.c
X	autom()         A subroutine which from the table automat[][]
X			calculates points.
X
Xchose.c
X	chose()         This one is the most central subroutine. It choses
X			a move to do. You may call this the algorithm for
X			chosing moves. Now it only choses the move that
X			gets the highest threat and point score. To be
X			better it should also test moves and see whats
X			changing on the board!
X
Xcatch.c
X	catch()         Fetches patterns from the board and puts them in
X			temporaray strings.
X
Xupd.c
X	update()        This one is the second most central subroutine.
X			It administrates the updating of points and
X			threats. The code can be difficult to read because
X			it is optimised for doing as little as possible.
X			If a more complicated algorithm is used in chose()
X			this have to be a fast one!
X
Xupdtht.c
X	updtht()        A help routine for update. It updates the points
X			on the threat board.
X
XThere are three more files. Those files you don't need if you don't want
Xto change the computing of points. The comments are in Swedish but i don't
Xthink that will be of any inconvinience.
X
Xmake_header     The beginning of an automat.c file.
X
Xmaketabell      Defines the computing of points. First there is a table
X		that defines threatpoint and point for some letters. Then
X		those letters are used in patterns to define where those
X		points are found.
X
Xmakeautomat.c   Compile this with cc and run makeautomat < maketabell to
X		make a new automat.c file.
X
XPS. If you make any improvments or/and have any suggestions please send the
Ximprovments/suggestions to me.
X
X	Roland Karlsson                      roland@ttds
X	Dept. of Telecomm. and Computer Systems
X	Royal Institute of Technology
X	S-100 44 Stockholm
X	Sweden
+ END-OF-FILE README
chmod 'u=rw,g=r,o=r' 'README'
echo '	-rw-r--r--  1 roland       2553 Oct 23 08:26 README        (as sent)'
echo -n '	'
/bin/ls -l README
echo 'Extracting adm.c'
sed 's/^X//' > adm.c << '+ END-OF-FILE adm.c'
X# include "def.h"
X# include <stdio.h>
X# include <signal.h>
X
X/* If you push BREAK you are a cheater */
Xcheat(){
X	signal(SIGINT, cheat);
X	pos(1, YZIZE + 2);
X	if(!slf)
X		printf("Cheater. I win on V.O.\n");
X	exit();
X}
X
X/* The main program which administrate who's on the move etc */
X
Xmain(){
X	int x, y;
X	char svar[16];
X	char *term, *getenv();
X
X	term = getenv("TERM");
X	if(getcap(term) == -1){
X		printf("Wrong or no TERM: %s\n", term);
X		exit();
X	}
X	if((height < 24) || (width < 80)){
X		printf("To smal screen (%d x %d). Min is (80 x 24)\n",
X			width, height);
X		exit();
X	}
X
X	for(x = 0; x < XZIZE; x++)
X		for(y = 0; y < YZIZE; y++)
X			board[x][y] = ' ';
X	srand( getpid() );
X	utboard(0);
X	signal(SIGINT, cheat);
X	pos(1, YZIZE + 1);
X	printf("Your move f.ex: k12. Computer start: start");
X
X	while(TRUE){
X		if(!slf)
X			inmove(&x, &y);
X		if(slf)
X			if(!chose('x', &x, &y)){
X				pos(1, YZIZE + 2);
X				printf("Can't find a place for my 'x'\n");
X				break;
X			}
X		play[x][y] = ++playcnt;
X		pos(x, y); printf("x\b"); fflush(stdout);
X		board[x][y] = 'x';
X		if(update(x, y)){
X			pos(1, YZIZE + 2);
X			printf("Congratulations you won\n");
X			break;
X		}
X		if(playcnt > 1)
X			for(x = 0; x < XZIZE; x++)
X				for(y = 0; y < YZIZE; y++)
X					if(play[x][y] == playcnt - 1){
X						pos(x, y);
X						printf("o\b");
X						fflush(stdout);
X					}
X		if(!chose('o', &x, &y)){
X			pos(1, YZIZE + 2);
X			printf("Can't find a place for my 'o'\n");
X			break;
X		}
X		play[x][y] = ++playcnt;
X		if(!slf){
X			pos(1, YZIZE + 1);
X			printf("My move:  %c%d", 'a' + x, y);
X		}
X		pos(x, y);
X		printf("O\b");
X		fflush(stdout);
X		board[x][y] = 'o';
X		if(update(x, y)){
X			pos(1, YZIZE + 2);
X			printf("I won\n");
X			break;
X		}
X	}
X	signal(SIGINT, SIG_DFL); /* Skip cheat */
X	printf("Do you want to save the game? (y/n)  ");
X	svar[0] = getchar(); emptyline();
X	if(svar[0] == 'y'){
X		save();
X		exit();
X	}
X	if(svar[0] == 'n')
X		exit();
X	printf("Hmmm. Asumes you don't.\n");
X}
+ END-OF-FILE adm.c
chmod 'u=r,g=r,o=r' 'adm.c'
echo '	-r--r--r--  1 roland       1925 Jan 29  1985 adm.c        (as sent)'
echo -n '	'
/bin/ls -l adm.c
echo 'Extracting autom.c'
sed 's/^X//' > autom.c << '+ END-OF-FILE autom.c'
X# include "def.h"
X
X/* Scans the tabel who defines the finite automat */
X
Xautom(){
X    register int state, i, way;
X    short int who, j;
X    unsigned char *atm;
X    char (*p)[17], (*t)[17];
X    unsigned char *newpts;
X    char *oldpts;
X    unsigned char *newtht;
X    char *oldtht;
X    char max;
X
X    for(way = 0; way < 4; way++){
X        state = 0;
X        atm = automat[0];
X        p = tmppts[way];
X        t = tmptht[way];
X        for(i = 0; i < 17; i++){
X            p[0][i] = 0;
X            p[1][i] = 0;
X            t[0][i] = 0;
X            t[1][i] = 0;
X        }
X        for(i = 0; i < 17; i++){
X            switch(hvlr[way][i]){
X                case ' ':
X                    state = atm[0];
X                    break;
X                case 'o':
X                    state = atm[1];
X                    who = 0;
X                    break;
X                case 'x':
X                    state = atm[2];
X                    who = 1;
X                    break;
X                default:
X                    state = 0;
X            }
X            atm = automat[state];
X            if(atm[3]){
X                max = 3 * atm[3] + 4;
X                for(j = 4; j < max; j += 3){
X                    oldpts = &p[who][i - atm[j]];
X                    newpts = &atm[j + 2];
X                    oldtht = &t[who][i - atm[j]];
X                    newtht = &atm[j + 1];
X                    if(*newtht > *oldtht)
X                        *oldtht = *newtht;
X                    if(*newpts > *oldpts)
X                        *oldpts = *newpts;
X                }
X            }
X        }
X    }
X}
+ END-OF-FILE autom.c
chmod 'u=r,g=r,o=r' 'autom.c'
echo '	-r--r--r--  1 roland       1573 Feb  7  1985 autom.c        (as sent)'
echo -n '	'
/bin/ls -l autom.c
echo 'Extracting automat.c'
sed 's/^X//' > automat.c << '+ END-OF-FILE automat.c'
X# define __ 00,
X
X/* This is a tabel which deflnes a finit automat for pattern recognition */
X
Xunsigned char automat[][13] = {
X/*                  Automat     Number     1            2            3      */
X/*                  .   O   X         of  hot  po  of  hot  po  of  hot  po */
X
X/*  0           */  1, 74,117,    __   __  __  __   __  __  __   __  __  __
X/*  1 .         */  2, 32, 53,    __   __  __  __   __  __  __   __  __  __
X/*  2 ..        */  3, 12, 22,    __   __  __  __   __  __  __   __  __  __
X/*  3 ...       */  3,  4,  8,    __   __  __  __   __  __  __   __  __  __
X/*  4 ...O      */  5,  6,117,    __   __  __  __   __  __  __   __  __  __
X/*  5 ...O.     */ 14, 15, 53,    2,   3,  __  1,   2,  __  2,   __  __  __
X/*  6 ...OO     */  7, 20,117,    2,   3,  __  3,   2,  __  4,   __  __  __
X/*  7 ...OO.    */ 19, 47, 53,    3,   4,  1,  5,   3,  1, 10,   __  __  4,
X/*  8 ...X      */  9, 74, 10,    __   __  __  __   __  __  __   __  __  __
X/*  9 ...X.     */ 24, 32, 25,    2,   3,  __  1,   2,  __  2,   __  __  __
X/* 10 ...XX     */ 11, 74, 30,    2,   3,  __  3,   2,  __  4,   __  __  __
X/* 11 ...XX.    */ 29, 32, 68,    3,   4,  1,  5,   3,  1, 10,   __  __  4,
X/* 12 ..O       */ 13, 17,117,    __   __  __  __   __  __  __   __  __  __
X/* 13 ..O.      */ 14, 15, 53,    __   __  __  __   __  __  __   __  __  __
X/* 14 ..O..     */ 35, 36, 22,    2,   3,  __  2,   1,  __  2,   __  __  __
X/* 15 ..O.O     */ 16, 41,117,    2,   3,  __  3,   1,  __  4,   __  __  __
X/* 16 ..O.O.    */ 40, 85, 53,    3,   4,  1,  5,   2,  1, 10,   __  __  3,
X/* 17 ..OO      */ 18, 20,117,    __   __  __  __   __  __  __   __  __  __
X/* 18 ..OO.     */ 19, 47, 53,    3,   4,  __  3,   3,  __  4,   __  __  4,
X/* 19 ..OO..    */ 46, 97, 22,    3,   4,  1, 10,   1,  1, 10,   __  __  3,
X/* 20 ..OOO     */ 21, 52,117,    2,   4,  2,  5,   3,  2, 10,   __  __  __
X/* 21 ..OOO.    */ 51,114, 53,    2,   4,  3, 20,   __  2, 10,   __  __  __
X/* 22 ..X       */ 23, 74, 27,    __   __  __  __   __  __  __   __  __  __
X/* 23 ..X.      */ 24, 32, 25,    __   __  __  __   __  __  __   __  __  __
X/* 24 ..X..     */ 56, 12, 57,    2,   3,  __  2,   1,  __  2,   __  __  __
X/* 25 ..X.X     */ 26, 74, 62,    2,   3,  __  3,   1,  __  4,   __  __  __
X/* 26 ..X.X.    */ 61, 32,128,    3,   4,  1,  5,   2,  1, 10,   __  __  3,
X/* 27 ..XX      */ 28, 74, 30,    __   __  __  __   __  __  __   __  __  __
X/* 28 ..XX.     */ 29, 32, 68,    3,   4,  __  3,   3,  __  4,   __  __  4,
X/* 29 ..XX..    */ 67, 12,140,    3,   4,  1, 10,   1,  1, 10,   __  __  3,
X/* 30 ..XXX     */ 31, 74, 73,    2,   4,  2,  5,   3,  2, 10,   __  __  __
X/* 31 ..XXX.    */ 72, 32,157,    2,   4,  3, 20,   __  2, 10,   __  __  __
X/* 32 .O        */ 33, 43,117,    __   __  __  __   __  __  __   __  __  __
X/* 33 .O.       */ 34, 38, 53,    __   __  __  __   __  __  __   __  __  __
X/* 34 .O..      */ 35, 36, 22,    __   __  __  __   __  __  __   __  __  __
X/* 35 .O...     */  3,  4,  8,    2,   2,  __  2,   1,  __  1,   __  __  __
X/* 36 .O..O     */ 37, 79,117,    2,   2,  __  3,   1,  __  3,   __  __  __
X/* 37 .O..O.    */ 14, 15, 53,    2,   3,  1,  5,   2,  1,  5,   __  __  __
X/* 38 .O.O      */ 39, 41,117,    __   __  __  __   __  __  __   __  __  __
X/* 39 .O.O.     */ 40, 85, 53,    3,   4,  __  3,   2,  __  4,   __  __  3,
X/* 40 .O.O..    */ 35, 36, 22,    2,   3,  1, 10,   1,  1,  5,   __  __  __
X/* 41 .O.OO     */ 42, 92,117,    2,   4,  2,  5,   2,  2, 10,   __  __  __
X/* 42 .O.OO.    */ 90, 47, 53,    2,   3,  3, 20,   __  2,  5,   __  __  __
X/* 43 .OO       */ 44, 49,117,    __   __  __  __   __  __  __   __  __  __
X/* 44 .OO.      */ 45, 47, 53,    __   __  __  __   __  __  __   __  __  __
X/* 45 .OO..     */ 46, 97, 22,    3,   4,  __  4,   1,  __  4,   __  __  3,
X/* 46 .OO...    */  3,  4,  8,    2,   2,  1, 10,   1,  1,  5,   __  __  __
X/* 47 .OO.O     */ 48,106,117,    2,   4,  2,  5,   1,  2, 10,   __  __  __
X/* 48 .OO.O.    */103, 85, 53,    2,   2,  3, 20,   __  2,  5,   __  __  __
X/* 49 .OOO      */ 50, 52,117,    __   __  __  __   __  __  __   __  __  __
X/* 50 .OOO.     */ 51,114, 53,    2,   4,  2, 10,   __  2, 10,   __  __  __
X/* 51 .OOO..    */110, 97, 22,    2,   1,  3, 20,   __  2,  5,   __  __  __
X/* 52 .OOOO     */116,115,117,    1,   4,  4, 30,   __  __  __   __  __  __
X/* 53 .X        */ 54, 74, 64,    __   __  __  __   __  __  __   __  __  __
X/* 54 .X.       */ 55, 32, 59,    __   __  __  __   __  __  __   __  __  __
X/* 55 .X..      */ 56, 12, 57,    __   __  __  __   __  __  __   __  __  __
X/* 56 .X...     */  3,  4,  8,    2,   2,  __  2,   1,  __  1,   __  __  __
X/* 57 .X..X     */ 58, 74,122,    2,   2,  __  3,   1,  __  3,   __  __  __
X/* 58 .X..X.    */ 24, 32, 25,    2,   3,  1,  5,   2,  1,  5,   __  __  __
X/* 59 .X.X      */ 60, 74, 62,    __   __  __  __   __  __  __   __  __  __
X/* 60 .X.X.     */ 61, 32,128,    3,   4,  __  3,   2,  __  4,   __  __  3,
X/* 61 .X.X..    */ 56, 12, 57,    2,   3,  1, 10,   1,  1,  5,   __  __  __
X/* 62 .X.XX     */ 63, 74,135,    2,   4,  2,  5,   2,  2, 10,   __  __  __
X/* 63 .X.XX.    */133, 32, 68,    2,   3,  3, 20,   __  2,  5,   __  __  __
X/* 64 .XX       */ 65, 74, 70,    __   __  __  __   __  __  __   __  __  __
X/* 65 .XX.      */ 66, 32, 68,    __   __  __  __   __  __  __   __  __  __
X/* 66 .XX..     */ 67, 12,140,    3,   4,  __  4,   1,  __  4,   __  __  3,
X/* 67 .XX...    */  3,  4,  8,    2,   2,  1, 10,   1,  1,  5,   __  __  __
X/* 68 .XX.X     */ 69, 74,149,    2,   4,  2,  5,   1,  2, 10,   __  __  __
X/* 69 .XX.X.    */146, 32,128,    2,   2,  3, 20,   __  2,  5,   __  __  __
X/* 70 .XXX      */ 71, 74, 73,    __   __  __  __   __  __  __   __  __  __
X/* 71 .XXX.     */ 72, 32,157,    2,   4,  2, 10,   __  2, 10,   __  __  __
X/* 72 .XXX..    */153, 12,140,    2,   1,  3, 20,   __  2,  5,   __  __  __
X/* 73 .XXXX     */159, 74,158,    1,   4,  4, 30,   __  __  __   __  __  __
X/* 74 O         */ 75, 93,117,    __   __  __  __   __  __  __   __  __  __
X/* 75 O.        */ 76, 82, 53,    __   __  __  __   __  __  __   __  __  __
X/* 76 O..       */  3, 77, 22,    __   __  __  __   __  __  __   __  __  __
X/* 77 O..O      */ 78, 79,117,    __   __  __  __   __  __  __   __  __  __
X/* 78 O..O.     */ 14, 15, 53,    2,   3,  __  3,   2,  __  3,   __  __  __
X/* 79 O..OO     */ 80, 20,117,    __   __  __  __   __  __  __   __  __  __
X/* 80 O..OO.    */ 19, 81, 53,    1,   __  __  4,   __  __  __   __  __  __
X/* 81 O..OO.O   */ 48,106,117,    2,   4,  3, 20,   1,  2, 10,   __  __  __
X/* 82 O.O       */ 83, 88,117,    __   __  __  __   __  __  __   __  __  __
X/* 83 O.O.      */ 84, 85, 53,    __   __  __  __   __  __  __   __  __  __
X/* 84 O.O..     */ 35, 36, 22,    2,   3,  __  4,   1,  __  3,   __  __  __
X/* 85 O.O.O     */ 86, 41,117,    __   __  __  __   __  __  __   __  __  __
X/* 86 O.O.O.    */ 40, 87, 53,    1,   __  __  4,   __  __  __   __  __  __
X/* 87 O.O.O.O   */ 86, 41,117,    2,   3,  3, 20,   1,  2,  5,   __  __  __
X/* 88 O.OO      */ 89, 92,117,    __   __  __  __   __  __  __   __  __  __
X/* 89 O.OO.     */ 90, 47, 53,    2,   3,  2, 10,   __  2,  5,   __  __  __
X/* 90 O.OO..    */ 46, 91, 22,    1,   __  __  4,   __  __  __   __  __  __
X/* 91 O.OO..O   */ 98, 79,117,    2,   2,  3, 20,   1,  2,  5,   __  __  __
X/* 92 O.OOO     */ 50, 52,117,    1,   3,  4, 30,   __  __  __   __  __  __
X/* 93 OO        */ 94,107,117,    __   __  __  __   __  __  __   __  __  __
X/* 94 OO.       */ 95,101, 53,    __   __  __  __   __  __  __   __  __  __
X/* 95 OO..      */ 96, 97, 22,    __   __  __  __   __  __  __   __  __  __
X/* 96 OO...     */  3,  4,  8,    2,   2,  __  4,   1,  __  3,   __  __  __
X/* 97 OO..O     */ 98, 79,117,    __   __  __  __   __  __  __   __  __  __
X/* 98 OO..O.    */ 14, 99, 53,    __   __  __  __   __  __  __   __  __  __
X/* 99 OO..O.O   */ 16,100,117,    2,   3,  __  3,   1,  __  4,   __  __  __
X/*100 OO..O.OO  */ 42, 92,117,    2,   4,  3, 20,   2,  2, 10,   __  __  __
X/*101 OO.O      */102,106,117,    __   __  __  __   __  __  __   __  __  __
X/*102 OO.O.     */103, 85, 53,    2,   2,  2, 10,   __  2,  5,   __  __  __
X/*103 OO.O..    */ 35,104, 22,    __   __  __  __   __  __  __   __  __  __
X/*104 OO.O..O   */ 37,105,117,    2,   2,  __  3,   1,  __  3,   __  __  __
X/*105 OO.O..OO  */ 80, 20,117,    2,   3,  3, 20,   2,  2,  5,   __  __  __
X/*106 OO.OO     */ 89, 92,117,    1,   2,  4, 30,   __  __  __   __  __  __
X/*107 OOO       */108,115,117,    __   __  __  __   __  __  __   __  __  __
X/*108 OOO.      */109,114, 53,    __   __  __  __   __  __  __   __  __  __
X/*109 OOO..     */110, 97, 22,    2,   1,  2, 10,   __  2,  5,   __  __  __
X/*110 OOO...    */  3,111,  8,    __   __  __  __   __  __  __   __  __  __
X/*111 OOO...O   */  5,112,117,    __   __  __  __   __  __  __   __  __  __
X/*112 OOO...OO  */  7,113,117,    1,   2,  __  4,   __  __  __   __  __  __
X/*113 OOO...OOO */ 21, 52,117,    2,   4,  3, 20,   3,  2, 10,   __  __  __
X/*114 OOO.O     */102,106,117,    1,   1,  4, 30,   __  __  __   __  __  __
X/*115 OOOO      */116,115,117,    __   __  __  __   __  __  __   __  __  __
X/*116 OOOO.     */109,114, 53,    1,   __  4, 30,   __  __  __   __  __  __
X/*117 X         */118, 74,136,    __   __  __  __   __  __  __   __  __  __
X/*118 X.        */119, 32,125,    __   __  __  __   __  __  __   __  __  __
X/*119 X..       */  3, 12,120,    __   __  __  __   __  __  __   __  __  __
X/*120 X..X      */121, 74,122,    __   __  __  __   __  __  __   __  __  __
X/*121 X..X.     */ 24, 32, 25,    2,   3,  __  3,   2,  __  3,   __  __  __
X/*122 X..XX     */123, 74, 30,    __   __  __  __   __  __  __   __  __  __
X/*123 X..XX.    */ 29, 32,124,    1,   __  __  4,   __  __  __   __  __  __
X/*124 X..XX.X   */ 69, 74,149,    2,   4,  3, 20,   1,  2, 10,   __  __  __
X/*125 X.X       */126, 74,131,    __   __  __  __   __  __  __   __  __  __
X/*126 X.X.      */127, 32,128,    __   __  __  __   __  __  __   __  __  __
X/*127 X.X..     */ 56, 12, 57,    2,   3,  __  4,   1,  __  3,   __  __  __
X/*128 X.X.X     */129, 74, 62,    __   __  __  __   __  __  __   __  __  __
X/*129 X.X.X.    */ 61, 32,130,    1,   __  __  4,   __  __  __   __  __  __
X/*130 X.X.X.X   */129, 74, 62,    2,   3,  3, 20,   1,  2,  5,   __  __  __
X/*131 X.XX      */132, 74,135,    __   __  __  __   __  __  __   __  __  __
X/*132 X.XX.     */133, 32, 68,    2,   3,  2, 10,   __  2,  5,   __  __  __
X/*133 X.XX..    */ 67, 12,134,    1,   __  __  4,   __  __  __   __  __  __
X/*134 X.XX..X   */141, 74,122,    2,   2,  3, 20,   1,  2,  5,   __  __  __
X/*135 X.XXX     */ 71, 74, 73,    1,   3,  4, 30,   __  __  __   __  __  __
X/*136 XX        */137, 74,150,    __   __  __  __   __  __  __   __  __  __
X/*137 XX.       */138, 32,144,    __   __  __  __   __  __  __   __  __  __
X/*138 XX..      */139, 12,140,    __   __  __  __   __  __  __   __  __  __
X/*139 XX...     */  3,  4,  8,    2,   2,  __  4,   1,  __  3,   __  __  __
X/*140 XX..X     */141, 74,122,    __   __  __  __   __  __  __   __  __  __
X/*141 XX..X.    */ 24, 32,142,    __   __  __  __   __  __  __   __  __  __
X/*142 XX..X.X   */ 26, 74,143,    2,   3,  __  3,   1,  __  4,   __  __  __
X/*143 XX..X.XX  */ 63, 74,135,    2,   4,  3, 20,   2,  2, 10,   __  __  __
X/*144 XX.X      */145, 74,149,    __   __  __  __   __  __  __   __  __  __
X/*145 XX.X.     */146, 32,128,    2,   2,  2, 10,   __  2,  5,   __  __  __
X/*146 XX.X..    */ 56, 12,147,    __   __  __  __   __  __  __   __  __  __
X/*147 XX.X..X   */ 58, 74,148,    2,   2,  __  3,   1,  __  3,   __  __  __
X/*148 XX.X..XX  */123, 74, 30,    2,   3,  3, 20,   2,  2,  5,   __  __  __
X/*149 XX.XX     */132, 74,135,    1,   2,  4, 30,   __  __  __   __  __  __
X/*150 XXX       */151, 74,158,    __   __  __  __   __  __  __   __  __  __
X/*151 XXX.      */152, 32,157,    __   __  __  __   __  __  __   __  __  __
X/*152 XXX..     */153, 12,140,    2,   1,  2, 10,   __  2,  5,   __  __  __
X/*153 XXX...    */  3,  4,154,    __   __  __  __   __  __  __   __  __  __
X/*154 XXX...X   */  9, 74,155,    __   __  __  __   __  __  __   __  __  __
X/*155 XXX...XX  */ 11, 74,156,    1,   2,  __  4,   __  __  __   __  __  __
X/*156 XXX...XXX */ 31, 74, 73,    2,   4,  3, 20,   3,  2, 10,   __  __  __
X/*157 XXX.X     */145, 74,149,    1,   1,  4, 30,   __  __  __   __  __  __
X/*158 XXXX      */159, 74,158,    __   __  __  __   __  __  __   __  __  __
X/*159 XXXX.     */152, 32,157,    1,   __  4, 30,   __  __  __   __  __  __
X};
+ END-OF-FILE automat.c
chmod 'u=r,g=r,o=r' 'automat.c'
echo '	-r--r--r--  1 roland      12448 Jan 29  1985 automat.c        (as sent)'
echo -n '	'
/bin/ls -l automat.c
echo 'Extracting catch.c'
sed 's/^X//' > catch.c << '+ END-OF-FILE catch.c'
X# include "def.h"
X
X/* Fetches patterns in the board and puts them in temporary strings */
Xcatch(x, y) int x, y;{
X	char *h, *v, *l, *r;
X	register int i;
X
X	h = hvlr[0];
X	v = hvlr[1];
X	l = hvlr[2];
X	r = hvlr[3];
X
X	for(i = -8; i <= 8; i++){
X		if((x + i >= 0) && (x + i < XZIZE))
X			*h++ = board[x + i][y];
X		else
X			*h++ = 'z';
X		if((y + i >= 0) && (y + i < YZIZE))
X			*v++ = board[x][y + i];
X		else
X			*v++ = 'z';
X		if((x + i >= 0) && (x + i < XZIZE) && (y + i >= 0) && (y + i < YZIZE))
X			*l++ = board[x + i][y + i];
X		else
X			*l++ = 'z';
X		if((x + i >= 0) && (x + i < XZIZE) && (y - i >= 0) && (y - i < YZIZE))
X			*r++ = board[x + i][y - i];
X		else
X			*r++ = 'z';
X	}
X}
+ END-OF-FILE catch.c
chmod 'u=r,g=r,o=r' 'catch.c'
echo '	-r--r--r--  1 roland        668 Feb  7  1985 catch.c        (as sent)'
echo -n '	'
/bin/ls -l catch.c
echo 'Extracting chose.c'
sed 's/^X//' > chose.c << '+ END-OF-FILE chose.c'
X# include "def.h"
X
X/* Chose what move shall be done depending on threats and points */
Xchose(who, dox, doy) char who; int *dox, *doy;{
X	short int maxpts, movbuf[2][BZIZE], movp, i, good, whomax;
X	register int x, y, n;
X
X	if(who == 'x')
X		who = 1;
X	else
X		who = 0;
X
X	for(x = 0; x < 2; x++){
X		thtmax[x] = 0;
X		for(y = 4; y > 0; y--){
X			if(thtcnt[x][y]){
X				thtmax[x] = y;
X				break;
X			}
X		}
X	}
X
X	good = movp = 0;
X	maxpts = -1;
X	if(thtmax[who] >= thtmax[!who])
X		whomax = who;
X	else{
X		whomax = !who;
X		if(thtmax[!who] == 1)
X			whomax = who;
X	}
X	for(x = 0; x < XZIZE; x++)
X		for(y = 0; y < YZIZE; y++)
X			if((board[x][y] == ' ') &&
X			   (threat[whomax][x][y] == thtmax[whomax])){
X				good++;
X				if((threat[whomax][x][y]) || (point[x][y] != 0)){
X					movbuf[0][movp] = x;
X					movbuf[1][movp++] = y;
X					if(point[x][y] > maxpts)
X						maxpts = point[x][y];
X				}
X			}
X	n = 1;
X	for(i = 0; i < movp; i++){
X		if(!maxpts || (point[movbuf[0][i]][movbuf[1][i]] * 11) / (10 * maxpts)){
X			if(!((rand()>>4) % n++)){
X				*dox = movbuf[0][i];
X				*doy = movbuf[1][i];
X			}
X		}
X	}
X	if(!movp && good)
X		for(x = 0; x < XZIZE; x++)
X			for(y = 0; y < YZIZE; y++)
X				if( (board[x][y] == ' ') &&
X				   !((rand()>>4) % n++)){
X					*dox = x;
X					*doy = y;
X				}
X	return(good);
X}
+ END-OF-FILE chose.c
chmod 'u=r,g=r,o=r' 'chose.c'
echo '	-r--r--r--  1 roland       1265 Feb  7  1985 chose.c        (as sent)'
echo -n '	'
/bin/ls -l chose.c
echo 'Extracting def.h'
sed 's/^X//' > def.h << '+ END-OF-FILE def.h'
X# define TH_3 1
X# define TH_4 2
X# define FORCED 3
X# define READY 4
X
X# define LOGIC char
X# define TRUE 1
X# define FALSE 0
X
X/* ZIZEs are different from unixluff */
X# define XZIZE 19
X# define YZIZE 19
X# define BZIZE 361 /* YZIZE * XZIZE */
X
Xint width;
Xint height;
X
Xchar board[XZIZE][YZIZE];
Xshort int play[XZIZE][YZIZE];
Xshort int playcnt;
X
Xchar point[XZIZE][YZIZE];
Xchar p_hvlr[4][XZIZE][YZIZE];
Xchar threat[2][XZIZE][YZIZE];
Xchar t_hvlr[4][2][XZIZE][YZIZE];
Xshort int thtcnt[2][5];
Xchar thtmax[2];
Xchar hvlr[4][18];
X
Xunsigned char automat[][13];
Xchar tmppts[4][2][17];
Xchar tmptht[4][2][17];
X
XLOGIC slf;
X
+ END-OF-FILE def.h
chmod 'u=r,g=r,o=r' 'def.h'
echo '	-r--r--r--  1 roland        604 Feb  7  1985 def.h        (as sent)'
echo -n '	'
/bin/ls -l def.h
echo 'Extracting inmove.c'
sed 's/^X//' > inmove.c << '+ END-OF-FILE inmove.c'
X# include "def.h"
X# include <stdio.h>
X# include <signal.h>
Xextern cheat();
X
X/* makes the program play self */
Xnormal(){
X	signal(SIGINT, cheat);
X	slf = 0;
X}
X
X/* Routin for input of moves and commands */
Xinmove(x, y) int *x, *y;{
X	char buff[11], who;
X	int i, j, xx, yy;
X
X	while(TRUE){
X		pos(1, YZIZE + 2);
X		printf("Your move: ");
X		scanf("%s", buff); emptyline();
X		up(); up(); clear();
X		if(!strcmp(buff, "board")){
X			utboard(0);
X			continue;
X		}
X		if((playcnt == 0) && !strcmp(buff, "start")){
X			xx = XZIZE/2;
X			yy = YZIZE/2;
X			board[xx][yy] = 'o';
X			update(xx, yy);
X			play[xx][yy] = ++playcnt;
X			pos(xx, yy);
X			putchar('o');
X			pos(1, YZIZE +1);
X			clear();
X			continue;
X		}
X		if(!strcmp(buff,"remove")){
X			while(TRUE){
X				if(playcnt == 0)
X					break;
X				for(xx = 0; xx < XZIZE; xx++)
X					for(yy = 0; yy < YZIZE; yy++)
X						if(play[xx][yy] == playcnt){
X							play[xx][yy] = 0;
X							who = board[xx][yy];
X							board[xx][yy] = ' ';
X							update(xx, yy);
X							pos(xx, yy);
X							printf(".\b");
X						}
X				playcnt--;
X				if(who == 'x')
X					break;
X			}
X			continue;
X		}
X		if(!strcmp(buff, "play")){
X			for(xx = 0; xx < XZIZE; xx++)
X				for(yy = 0; yy < YZIZE; yy++)
X					if(play[xx][yy]){
X						pos(xx, yy);
X						printf("%2d", play[xx][yy]);
X					}
X			continue;
X		}
X		if(!strcmp(buff, "help")){
X			home(); clear();
X			printf("b5, c12 :Examples on moveformats\n");
X			printf("remove  :Taking back moves\n");
X			printf("slf     :The program plays self\n");
X			printf("point   :Shows pointboard\n");
X			printf("pts     :Shows way pointboard\n");
X			printf("threat  :Shows threatboard\n");
X			printf("tht     :Shows way threatboard\n");
X			printf("play    :Shows the game\n");
X			printf("board   :Rewrite board\n");
X			printf("save    :Saves the game\n");
X			printf("resave  :Resave the game\n");
X			printf("automat :Runs pattern recognition\n");
X			printf("hint    :gives you a hint\n");
X			printf("\n\n\nPush <return> when you'r ready\n");
X			emptyline();
X			utboard(0);
X			continue;
X		}
X		if(!strcmp(buff, "save")){
X			save();
X			continue;
X		}
X		if(!strcmp(buff, "resave")){
X			resave();
X			continue;
X		}
X		if(!strcmp(buff, "slf")){
X			signal(SIGINT, normal);
X			slf = TRUE;
X			return;
X		}
X		if(!strcmp(buff, "point")){
X			utboard(point);
X			continue;
X		}
X		if(!strcmp(buff, "pts")){
X			printf("Which way -|\\/(0123): ");
X			scanf("%d", &i); emptyline();
X			utboard(p_hvlr[i]);
X			continue;
X		}
X		if(!strcmp(buff, "threat")){
X			printf("Which player ox(01): ");
X			scanf("%d", &i); emptyline();
X			utboard(threat[i]);
X			continue;
X		}
X		if(!strcmp(buff, "tht")){
X			printf("Which way and player -|\\/(0123) ox(01): ");
X			scanf("%d%d", &i, &j); emptyline();
X			utboard(t_hvlr[i][j]);
X			continue;
X		}
X		if(!strcmp(buff, "automat")){
X			printf("What position: ");
X			scanf("%s", buff); emptyline();
X			up();
X			printf("Which way -|\\/(0123); ");
X			scanf("%d", &j); emptyline();
X			if(inposition(x, y, buff)){
X				catch(*x, *y);
X				autom();
X				pos(XZIZE + 2, 0);
X				printf("    pto ptx tho thx");
X				for(i = 0; i < 17; i++){
X					pos(XZIZE + 2, i + 1);
X					printf("%3c", hvlr[j][i]);
X					printf("%4d", tmppts[j][0][i]);
X					printf("%4d", tmppts[j][1][i]);
X					printf("%4d", tmptht[j][0][i]);
X					printf("%4d", tmptht[j][1][i]);
X				}
X			}
X			continue;
X		}
X		if(!strcmp(buff, "hint")){
X			if(chose('x', &xx, &yy))
X				printf("My hint is: %c%d", 'a' + xx, yy);
X			continue;
X		}
X		if(inposition(x, y, buff))
X			return;
X		printf("\n\nType help for help");
X	}
X}
X
X/* Converts a text string type g11 to a position */
X
Xinposition(x, y, buff) int *x, *y; char buff[11];{
X	*x = buff[0] - 'a';
X	*y = atoi(&buff[1]);
X	if((*x >= 0) && (*x < XZIZE) && (*y >= 0) && (*y < YZIZE)
X	    && (buff[1] >= '0') && (buff[1] <= '9')
X	    && board[*x][*y] == ' ')
X		return(1);
X	return(0);
X}
X
X/* Empty a line */
X
Xemptyline(){
X	while(getchar() != '\n');
X}
+ END-OF-FILE inmove.c
chmod 'u=r,g=r,o=r' 'inmove.c'
echo '	-r--r--r--  1 roland       3857 Jan 29  1985 inmove.c        (as sent)'
echo -n '	'
/bin/ls -l inmove.c
echo 'Extracting make_header'
sed 's/^X//' > make_header << '+ END-OF-FILE make_header'
X# define __ 00,
X
X/* Detta {r en tabell vilken defenierar en finit automat f|r m|nsters|kning */
X
Xunsigned char automat[][13] = {
X/*                  Automat     Antal      1            2            3      */
X/*                  .   O   X         of  hot  po  of  hot  po  of  hot  po */
X
+ END-OF-FILE make_header
chmod 'u=r,g=r,o=r' 'make_header'
echo '	-r--r--r--  1 roland        288 Oct 18 10:03 make_header        (as sent)'
echo -n '	'
/bin/ls -l make_header
echo 'Extracting makeautomat.c'
sed 's/^X//' > makeautomat.c << '+ END-OF-FILE makeautomat.c'
X# include "stdio.h"
X# define FOUND 1
X# define NOT_FOUND 0
X# define DUMMY 'd'
X
Xempty(){
X	while(getchar() != '\n');
X}
X
Xfempty(fd) FILE *fd;{
X	while(getc(fd) != '\n');
X}
X
Xmain(){
X	char text[128], uttext[128], c;
X	char textarray[512][16];
X	int automat[512][3]; /* .=0 O=1 X=2 */
X	char pattern[4];
X	int offs, offset[3], point[3], threat[3];
X	int p[10], t[10], count, length;
X	FILE *fd_in, *fd_out;
X	int i, j, k;
X	int flag;
X
X/* ********** Pass 1 *********************************************************
XL{ser in en fil fr}n standard input med formatet:
X---------
X|
X|
X| Block vilket inneh}ller po{ngdefenitioner.
X|
X|
X---------
X|
X|
X| Block vilket inneh}ller m|nster vilka ger po{ng.
X|
X|
X---------
XUtdata skrivs p} filen make_first och inneh}ller m|nster plus po{ng.
X*************************************************************************** */
X
X	printf("Pass 1\n");
X	for(i = 0; i < 10; i++){
X		scanf("%*c%d%d", &t[i], &p[i]); empty();
X	}
X
X	fd_out = fopen("make_first", "w");
X	while(scanf("%s", text) != EOF){
X		if(text[0] == 0)
X			continue;
X		j = 0;
X		for(i = 0; i < 3; i++){
X			offset[i] = 0;
X			point[i] = 0;
X			threat[i] = 0;
X		}
X		for(count = 0; text[count] != 0; count++);
X		for(i = 0; text[i] !=0; i++){
X			if((text[i] == '.') || (text[i] == 'X'))
X				uttext[i] = text[i];
X			else{
X				offset[j] = count - i - 1;
X				threat[j] = t[text[i] - 'a'];
X				point[j] = p[text[i] - 'a'];
X				uttext[i] = '.';
X				j++;
X			}
X		}
X		uttext[i] = 0;
X		fprintf(fd_out, "%-10s%3d", uttext, j);
X		for(i = 0; i < 3; i++)
X			fprintf(fd_out,"%5d%3d%3d", offset[i], threat[i], point[i]);
X		fprintf(fd_out,"\n");
X	}
X	fclose(fd_out);
X
X/* ********** Pass 2 *********************************************************
XL{ser filen make_first samt l{gger till motsvarande m|nster med
XO i st}llet f|r X.
X*************************************************************************** */
X
X	printf("Pass 2\n");
X	fd_in = fopen("make_first", "r");
X	fd_out = fopen("make_temp1", "w");
X	while((fscanf(fd_in, "%c", &c)) != EOF)
X		if(c == 'X')
X			fprintf(fd_out, "O");
X		else
X			fprintf(fd_out, "%c", c);
X	fclose(fd_in);
X	fclose(fd_out);
X	system("cat make_first make_temp1 > make_temp2");
X	system("mv make_temp2 make_first");
X	system("rm make_temp1");
X
X/* ********** Pass 3 *********************************************************
XL{ser filen make_first samt l{gger till delm|nster vilka leder till m|nstren.
XOm delm|nstret redan finns skall det ej l{ggas till. D.v.s inga kopior
Xskall uppst}. Delm|nstren ges po{ng noll. Filen sorteras.
X*************************************************************************** */
X
X	printf("Pass 3\n");
X	fd_in = fopen("make_first", "r");
X	length = 0;
X	while((fscanf(fd_in, "%s", textarray[length])) != EOF){
X		length++;
X		fempty(fd_in);
X	}
X	count = length;
X	fclose(fd_in);
X	fd_out = fopen("make_first", "a");
X	for(i = 0; i < count; i++){
X		strcpy(text, textarray[i]);
X		for(; text[0] != 0; text[strlen(text) - 1] = 0){
X			flag = NOT_FOUND;
X			for(j = 0; j < length; j++)
X				if(!strcmp(text, textarray[j])){
X					flag = FOUND;
X					break;
X				}
X			if(flag == NOT_FOUND){
X				strcpy(textarray[length++], text);
X				fprintf(fd_out, "%-10s%3d", text, 0);
X				for(k = 0; k < 3; k++)
X					fprintf(fd_out, "%5d%3d%3d", 0, 0, 0);
X				fprintf(fd_out, "\n");
X				length++;
X			}
X		}
X	}
X	fclose(fd_out);
X	system("sort make_first -o make_sort");
X
X/* ********** Pass 4 *********************************************************
XDet sista passet vilket konstruerar automaten samt g|r om filen till en
Xc-fil med namnet automat.c.
X*************************************************************************** */
X
X	printf("Pass 4\n");
X	fd_in = fopen("make_sort", "r");
X	strcpy(textarray[0], "");
X	length = 1;
X	while((fscanf(fd_in, "%s", textarray[length])) != EOF){
X		length++;
X		fempty(fd_in);
X	}
X	strcpy(pattern, ".OX");
X	for(i = 0; i < length; i++){
X		strcpy(text, textarray[i]);
X		for(j = strlen(text) + 1; j < 20; j++)
X			text[j] = 0;
X		text[strlen(text)] = DUMMY;
X		for(j = 0; j < 3; j++){
X			text[strlen(text) - 1] = pattern[j];
X			flag = NOT_FOUND;
X			for(offs = 0; offs < 11; offs++){
X				for(k = 0; k < length; k++)
X					if(!strcmp(text + offs, textarray[k])){
X						flag = FOUND;
X						automat[i][j] = k;
X						break;
X					}
X				if(flag == FOUND)
X					break;
X			}
X			if(flag == NOT_FOUND)
X				printf("Cant find %s\n", text);
X		}
X	}
X	fclose(fd_in);
X	fd_in = fopen("make_sort", "r");
X	fd_out = fopen("make_automat", "w");
X	for(i = 0; i < 3; i++){
X		offset[i] = 0;
X		point[i] = 0;
X		threat[i] = 0;
X	}
X	count = 0;
X	for(i = 0; i < length; i++){
X		fprintf(fd_out, "/*%3d %-10s*/", i, textarray[i]);
X		fprintf(fd_out, "%3d,%3d,%3d,", automat[i][0], automat[i][1],
X			automat[i][2]);
X		fprintf(fd_out, "%5d,", count);
X		for(j = 0; j < 3; j++)
X			fprintf(fd_out, "%4d,%3d,%3d,", offset[j], threat[j],
X				point[j]);
X		fprintf(fd_out, "\n");
X		fscanf(fd_in, "%*s%d", &count);
X		for(j = 0; j < 3; j++)
X			fscanf(fd_in, "%d%d%d\n", &offset[j], &threat[j],
X				&point[j]);
X	}
X	fprintf(fd_out, "};\n");
X	fclose(fd_in);
X	fclose(fd_out);
X	system("cat make_header make_automat | sed 's/ 0,/ __/g' > automat.c");
X	system("rm make_first make_sort make_automat");
X}
+ END-OF-FILE makeautomat.c
chmod 'u=r,g=r,o=r' 'makeautomat.c'
echo '	-r--r--r--  1 roland       5132 Oct 18 10:01 makeautomat.c        (as sent)'
echo -n '	'
/bin/ls -l makeautomat.c
echo 'Extracting makefile'
sed 's/^X//' > makefile << '+ END-OF-FILE makefile'
X.SUFFIXES: .o .c
XSOURCES=adm.c automat.c autom.c chose.c inmove.c\
X	terminal.c upd.c catch.c  updtht.c utboard.c save.c
XOBJECTS=adm.o automat.o autom.o chose.o inmove.o\
X	terminal.o upd.o catch.o  updtht.o utboard.o save.o
X
X.c.o:   ; cc -c $*.c
X
Xluff: ${OBJECTS}
X	cc -o luff ${OBJECTS} -ltermcap
X
Xadm.o autom.o chose.o inmove.o\
Xterminal.o upd.o catch.o  updtht.o utboard.o save.o: def.h
X
Xcleanup:
X	rm -f *.o
X
Xprint:
X	print makefile def.h\
X	adm.c automat.c autom.c chose.c inmove.c\
X	terminal.c upd.c catch.c  updtht.c utboard.c save.c
+ END-OF-FILE makefile
chmod 'u=rw,g=r,o=r' 'makefile'
echo '	-rw-r--r--  1 roland        536 Jan 29  1985 makefile        (as sent)'
echo -n '	'
/bin/ls -l makefile
echo 'Extracting save.c'
sed 's/^X//' > save.c << '+ END-OF-FILE save.c'
X# include "def.h"
X# include "stdio.h"
X
X/* Saves and resaves a position. File for saving is luff.out */
X
Xsave(){
X	int x, y;
X	FILE *fd;
X
X	fd = fopen("luff.out", "w");
X	for(y = 0; y < YZIZE; y++){
X		for(x = 0; x < XZIZE; x++)
X			fprintf(fd, "%3d%c", play[x][y], board[x][y]);
X		fprintf(fd, "\n");
X	}
X}
X
Xresave(){
X	int x, y;
X	char temp;
X	FILE *fd;
X
X	if((fd = fopen("luff.out", "r")) == 0){
X		printf("Can't open the file luff.out\n");
X		return;
X	}
X	playcnt = 0;
X	for(y = 0; y < YZIZE; y++){
X		for(x = 0; x < XZIZE; x++){
X			fscanf(fd, "%3d%c", &play[x][y], &temp);
X			if(play[x][y] > playcnt)
X				playcnt = play[x][y];
X			if(temp != board[x][y]){ /* [ndring */
X				board[x][y] = temp;
X				update(x, y);
X				pos(x, y);
X				if(board[x][y] == ' ')
X					putchar('.');
X				else
X					putchar(board[x][y]);
X			}
X		}
X		fscanf(fd, "\n");
X	}
X}
+ END-OF-FILE save.c
chmod 'u=r,g=r,o=r' 'save.c'
echo '	-r--r--r--  1 roland        829 Jan 29  1985 save.c        (as sent)'
echo -n '	'
/bin/ls -l save.c
echo 'Extracting tabell'
sed 's/^X//' > tabell << '+ END-OF-FILE tabell'
Xa  0  1 /* Splittrad 2:a  a=type 0=threat 1=points */
Xb  0  2 /* Solid 2:a */
Xc  0  3 /* Splittrad 3:a */
Xd  0  4 /* Solid 3:a */
Xe  1  5 /* Splittrad ostoppad 3:a */
Xf  1 10 /* Solid ostoppad 3:a */
Xg  2  5 /* Splittrad 4:a */
Xh  2 10 /* Solid 4:a */
Xi  3 20 /* Forcerad vinst */
Xj  4 30 /* 5:a */
X
X.abX.
X.bXb.
X.Xba.
X
X.cdXX
X.cXdX
XcdXXd
X.XccX
XcXdXc
XdXXdc
XXccX.
XXdXc.
XXXdc.
X
X.efXXd
X.eXfXc
X.fXXfc
X.XeeX.
X.XfXe.
X.XXfe.
X
XghXXX
XgXhXX
XgXXhX
XhXXXh
XXhXXg
XXXhXg
XXXXhg
X
X.iXXXh
X.XiXXg
X.XXiXg
X.XXXig
X
XX..XXd
XX.iXXhX
XX.X.Xd
XX.XiXgX
XX.XX.d
XX.XXigX
X
XXX.cXdX
XXX.iXhXX
XXX.XccX
XXX.XigXX
X
XXXX..dXX
XXXX.ihXXX
X
XjXXXX
XXjXXX
XXXjXX
XXXXjX
XXXXXj
+ END-OF-FILE tabell
chmod 'u=r,g=r,o=r' 'tabell'
echo '	-r--r--r--  1 roland        620 Oct 18 09:51 tabell        (as sent)'
echo -n '	'
/bin/ls -l tabell
echo 'Extracting terminal.c'
sed 's/^X//' > terminal.c << '+ END-OF-FILE terminal.c'
X# include "def.h"
X
X/* Routines using termcap for positioning */
X
X# include <sgtty.h>
Xstruct sgttyb argp;
Xchar ospeed;
X
Xextern putchar();
X
Xchar *BC;     /* Backspace if not ^H */
Xchar *UP;     /* Up one line         */
Xchar *HO;     /* Home                */
Xchar *CD;     /* Clear from cursor   */
Xchar *CM;     /* cursor motions      */
Xchar tcbuf[1024]; /* Buffert for initialising capabilities */
Xchar cp[256];     /* Buffert for storing capabilities      */
X
X/* Initialising the string containing terminal depending functions */
X
Xgetcap(term)
Xchar *term;
X{
X	char *pc;
X	char *tgetstr();
X
X	gtty(0, &argp);
X	ospeed = argp.sg_ospeed;
X
X	switch (tgetent(tcbuf, term)) {
X	case -1:
X	case 0:
X		return -1;
X	}
X	pc = cp;
X	BC = tgetstr("bc", &pc);
X	if (BC == 0)
X		BC = "\b";
X	UP = tgetstr("up", &pc);
X	HO = tgetstr("ho", &pc);
X	CD = tgetstr("cd", &pc);
X	CM = tgetstr("cm", &pc);
X
X	width = tgetnum("co");
X	height = tgetnum("li");
X
X	return 0;
X}
X
X
X/* positions on the screen. Origin in the left upper corner. */
Xpos(x, y) int x, y;{
X	if((x > -2) && (x < 39) && (y > -2) && (y < 22)){
X		x = 3 + x + x;
X		y = 1 + y;
X		tputs( tgoto(CM, x, y), 1, putchar);
X	}
X	else
X		printf("Out of board %d %d", x, y);
X}
X
X/* Cursor up one line */
Xup(){
X	tputs(UP, 1, putchar);
X}
X
X/* Clears screen from cursor */
Xclear(){
X	tputs(CD, 1, putchar);
X}
X
X/* Cursor home */
Xhome(){
X	tputs(HO, 1, putchar);
X}
X
+ END-OF-FILE terminal.c
chmod 'u=r,g=r,o=r' 'terminal.c'
echo '	-r--r--r--  1 roland       1370 Jan 29  1985 terminal.c        (as sent)'
echo -n '	'
/bin/ls -l terminal.c
echo 'Extracting upd.c'
sed 's/^X//' > upd.c << '+ END-OF-FILE upd.c'
X# include "def.h"
X
X/* Administrate the updating of point and threat boards */
Xupdate(x, y) int x, y;{
X    register int i, way;
X    short int xx, yy, step, j;
X    char who;
X    LOGIC xflag, oflag, blankflag, stopflag, win;
X
X    win = FALSE;
X    who = board[x][y];
X    catch(x, y);
X    autom();
X    if(who != ' '){
X	if((who == 'o') && (threat[0][x][y] == 4))
X	    win = TRUE;
X	if((who == 'x') && (threat[1][x][y] == 4))
X	    win = TRUE;
X	thtcnt[0][threat[0][x][y]] -= 1;
X	threat[0][x][y] = 0;
X	thtcnt[1][threat[1][x][y]] -= 1;
X	threat[1][x][y] = 0;
X    }
X    else{
X	for(way = 0; way < 4; way++){
X	    p_hvlr[way][x][y] = tmppts[way][0][8] + tmppts[way][1][8];
X	    t_hvlr[way][0][x][y] = tmptht[way][0][8];
X	    t_hvlr[way][1][x][y] = tmptht[way][1][8];
X	}
X	point[x][y] = p_hvlr[0][x][y] + p_hvlr[1][x][y] +
X		      p_hvlr[2][x][y] + p_hvlr[3][x][y];
X	if( t_hvlr[0][0][x][y] | t_hvlr[1][0][x][y] |
X	    t_hvlr[2][0][x][y] | t_hvlr[3][0][x][y] )
X	    updtht('o', x, y);
X	else{
X	    thtcnt[0][threat[0][x][y]] -= 1;
X	    threat[0][x][y] = 0;
X	}
X	if( t_hvlr[0][1][x][y] | t_hvlr[1][1][x][y] |
X	    t_hvlr[2][1][x][y] | t_hvlr[3][1][x][y] )
X	    updtht('x', x, y);
X	else{
X	    thtcnt[1][threat[1][x][y]] -= 1;
X	    threat[1][x][y] = 0;
X	}
X    }
X    for(way = 0; way < 4; way++){
X	for(step = -1; step <= 1; step += 2){
X	    xflag = oflag = blankflag = stopflag = FALSE;
X	    i = 8;
X	    for(j = 0; j < 4; j++){
X		i += step;
X		if(blankflag == 2)
X		    break;
X		switch(hvlr[way][i]){
X		    case ' ':
X			blankflag++;
X			break;
X		    case 'o':
X			oflag = TRUE;
X			blankflag = FALSE;
X			break;
X		    case 'x':
X			xflag = TRUE;
X			blankflag = FALSE;
X			break;
X		    case 'z':
X			stopflag = TRUE;
X			break;
X		}
X		if(stopflag)
X		    break;
X		if(!blankflag)
X		    continue;
X		switch(way){
X		    case 0:
X			xx = x + i - 8;
X			yy = y;
X			break;
X		    case 1:
X			xx = x;
X			yy = y + i - 8;
X			break;
X		    case 2:
X			xx = x + i - 8;
X			yy = y + i - 8;
X			break;
X		    case 3:
X			xx = x + i - 8;
X			yy = y - i + 8;
X			break;
X		}
X		p_hvlr[way][xx][yy] = tmppts[way][0][i] + tmppts[way][1][i];
X		point[xx][yy] = p_hvlr[0][xx][yy] + p_hvlr[1][xx][yy] +
X				p_hvlr[2][xx][yy] + p_hvlr[3][xx][yy];
X		if(!xflag){
X		    t_hvlr[way][0][xx][yy] = tmptht[way][0][i];
X		    if( t_hvlr[0][0][xx][yy] | t_hvlr[1][0][xx][yy] |
X			t_hvlr[2][0][xx][yy] | t_hvlr[3][0][xx][yy] )
X			updtht('o', xx, yy);
X		    else{
X			thtcnt[0][threat[0][xx][yy]] -= 1;
X			threat[0][xx][yy] = 0;
X		    }
X		}
X		if(!oflag){
X		    t_hvlr[way][1][xx][yy] = tmptht[way][1][i];
X		    if( t_hvlr[0][1][xx][yy] | t_hvlr[1][1][xx][yy] |
X			t_hvlr[2][1][xx][yy] | t_hvlr[3][1][xx][yy] )
X			updtht('x', xx, yy);
X		    else{
X			thtcnt[1][threat[1][xx][yy]] -= 1;
X			threat[1][xx][yy] = 0;
X		    }
X		}
X	    }
X	}
X    }
X    return(win);
X}
X
+ END-OF-FILE upd.c
chmod 'u=r,g=r,o=r' 'upd.c'
echo '	-r--r--r--  1 roland       2771 Feb  7  1985 upd.c        (as sent)'
echo -n '	'
/bin/ls -l upd.c
echo 'Extracting updtht.c'
sed 's/^X//' > updtht.c << '+ END-OF-FILE updtht.c'
X# include "def.h"
X
X/* Updates the threat board */
Xupdtht(who, x, y) char who; int x, y;{
X	short int t[5];
X	register int i;
X
X	for(i = 0; i < 5; i++)
X		t[i] = 0;
X
X	if(who == 'x')
X		who = 1;
X	else
X		who = 0;
X
X	for(i = 0; i < 4; i++) /* Count threats in the four ways */
X		t[t_hvlr[i][who][x][y]]  += 1;
X
X	thtcnt[who][threat[who][x][y]] -= 1;
X	threat[who][x][y] = 0;
X
X	if((  t[1])                       /* 3 */
X	  || (t[2]))                      /* stopped 4 */
X		threat[who][x][y] = 1;
X
X	if(t[1] > 1)                      /* 3-3-combination */
X		threat[who][x][y] = 2;
X
X	if(((t[2] > 0) && (t[1] > 0))     /* 4-3-combination */
X	  || (t[2] > 1)                   /* 4-4-combination */
X	  || (t[3] > 0))                  /* Free 4 */
X		threat[who][x][y] = 3;
X
X	if(t[4] > 0)                      /* 5 = win */
X		threat[who][x][y] = 4;
X
X	thtcnt[who][threat[who][x][y]] += 1;
X}
+ END-OF-FILE updtht.c
chmod 'u=r,g=r,o=r' 'updtht.c'
echo '	-r--r--r--  1 roland        870 Feb  7  1985 updtht.c        (as sent)'
echo -n '	'
/bin/ls -l updtht.c
echo 'Extracting utboard.c'
sed 's/^X//' > utboard.c << '+ END-OF-FILE utboard.c'
X# include "def.h"
X
X/* Prints out an image of th board with or without points */
Xutboard(p) char p[XZIZE][YZIZE];{
X	register int x, y;
X
X	home(); clear();
X	printf("  ");
X	for(x = 0; x < XZIZE; x++)
X		printf(" %c", 'a' + x);
X	putchar('\n');
X	for(y = 0; y < YZIZE; y++){
X		printf("%2d", y);
X		for(x = 0; x < XZIZE; x++){
X			if(board[x][y] == ' ')
X				if(p && p[x][y])
X					if(p[x][y] > 077)
X						printf(" >");
X					else
X						printf("%2o", p[x][y]);
X				else{
X					putchar(' ');
X					putchar('.');
X				}
X			else{
X				putchar(' ');
X				putchar(board[x][y]);
X			}
X		}
X		printf(" %2d\n", y);
X	}
X	printf("  ");
X	for(x = 0; x < XZIZE; x++)
X		printf(" %c", 'a' + x);
X	pos(XZIZE + 2, 0); printf("Luff7.1");
X	pos(XZIZE + 2, 1); printf("6/4 1982");
X}
+ END-OF-FILE utboard.c
chmod 'u=r,g=r,o=r' 'utboard.c'
echo '	-r--r--r--  1 roland        739 Jan 29  1985 utboard.c        (as sent)'
echo -n '	'
/bin/ls -l utboard.c
exit 0