[net.sources.mac] Source code for luff

roland@ttds.UUCP (Roland Karlsson) (10/22/85)

This program plays the game of noughts and crosses.  It plays a rather
simple and fast game but perhaps (if i get the time) i will add a mode of
slower and better play.

After adding some comments to the source code and writing a README file
i am posting the source code for the luff program posted earlier. If
someone makes some hacks to it i would be very greatfull if you send me
the changes made.

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

------ Cut here ------------------------------ and here ---------------------
: 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'
XThe shar file contains following files:
X
XREADME          This file.
X
Xmakefile
X
XMacLuff.rc      Resource file for rmaker.
X
XMacLuff.h       Macdependent header.
X
Xdef.h           Macindependent header.
X
Xadm.c
X	main()          The main program which make initialisations and
X			administrates who is on the move.
X	init_the_w()    Window initialisation.
X	init_the_menu() Menu initialisation.
X
Xinmove.c
X	inmove()                The main event loop.
X	do_command()            Input off commands.
X	adjust_cursor()
X	the_w_click()           Input of moves.
X	say_something()         The ABOUT AUTHOR subroutine.
X	say_something_else()    The HELP subroutine.
X
Xterminal.c
X	draw_x()        I
X	draw_o()        I Three subroutines which draws on board.
X	draw_empty()    I
X	draw_hint()     Draws a hint.
X	draw_message()  Draws a message over the holes in the paper.
X
Xutboard.c
X	utboard()       Draws the board.
X	draw_holes()    Draws the holes in the paper.
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       2812 Oct 21 09:16 README        (as sent)'
echo -n '	'
/bin/ls -l README
echo 'Extracting makefile'
sed 's/^X//' > makefile << '+ END-OF-FILE makefile'
X.SUFFIXES: .b .c
XSOURCES=adm.c automat.c autom.c chose.c inmove.c\
X	terminal.c upd.c catch.c  updtht.c utboard.c
XOBJECTS=adm.b automat.b autom.b chose.b inmove.b\
X	terminal.b upd.b catch.b  updtht.b utboard.b
X
X.c.b:   ; cc68 -m -c $*.c
X
XMacLuff.rsrc:   b.out MacLuff.rc
X		rmaker MacLuff.rc
X
Xb.out: ${OBJECTS}
X	cc68 -m ${OBJECTS}
X
Xadm.b autom.b chose.b inmove.b\
Xterminal.b upd.b catch.b  updtht.b utboard.b: def.h
X
Xadm.b inmove.b terminal.b : MacLuff.h
X
Xcleanup:
X	rm -f *.b
X
Xload:
X	macput -r MacLuff -a LUFF
X
Xprint:
X	print makefile MacLuff.rc MacLuff.h def.h\
X	adm.c automat.c autom.c chose.c inmove.c\
X	terminal.c upd.c catch.c  updtht.c utboard.c
+ END-OF-FILE makefile
chmod 'u=rw,g=r,o=r' 'makefile'
echo '	-rw-r--r--  1 roland        649 Feb  4  1985 makefile        (as sent)'
echo -n '	'
/bin/ls -l makefile
echo 'Extracting MacLuff.rc'
sed 's/^X//' > MacLuff.rc << '+ END-OF-FILE MacLuff.rc'
XMacLuff.rsrc
X*
XType LufF = STR
X  ,0(0)
XMacLuff 7.0 made by Roland Karlsson 1985.
X
X* pointing index finger
XType CURS = HEXA
X  ,256(0)
X00002000 51402aa0 15500a88 1d041602 08010400 03e00010 00080004 00000000
X00002000 71403be0 1ff00ff8 1ffc1ffe 0fff07fe 03fe001c 000c0004 00000000
X00010001 
X
XType WIND
X  ,128(0)
X  Paper
X  30 31 335 481
X  Visible noGoAway
X  2
X  0
X
XType MENU
X  ,1(0)
X  About...
X    ...MacLuff
X
XType MENU
X  ,256(0)
X  File
X    New game
X   (-
X    Quit<B
X
XType MENU
X  ,257(0)
X  Help
X   Tell me how
X
XType MENU
X  ,258(0)
X  Command
X    Your move please
X    Remove
X    Show me a game
X    Give me a hint
X
XType CODE
X  b.out,0
X
XType BNDL = HEXA
X  ,128(0)
X* LufF 0
X*   ICN#
X*     0 128
X*   FREF
X*     0 128
X4c756646 00000001 49434e23 00000000 00804652 45460000 00000080
X
XType FREF = HEXA
X  ,128(0)
X* APPL 0
X4150504c 000000ff 
X
XType ICN# = HEXA
X  ,128(0)
X208e2080 11111100 0a208a00 04208400 0a208a00 11111100 208e2080 00000000
Xfffffff8 8000000c 8140140e 8000000e fffffffe 8888888e 8888888e 8888888e
Xfffffffe 8888888e 8888888e 8888888e fffffffe 8888888e 8888888e 8888888e
Xfffffffe 8888888e 8888888e 8888888e fffffffe 7ffffffe 3ffffffe 00000000
X*
X3fffff80 3fffff80 3fffff80 3fffff80 3fffff80 3fffff80 3fffff80 00000000
Xfffffff8 fffffffc fffffffe fffffffe fffffffe fffffffe fffffffe fffffffe
Xfffffffe fffffffe fffffffe fffffffe fffffffe fffffffe fffffffe fffffffe
Xfffffffe fffffffe fffffffe fffffffe fffffffe 7ffffffe 3ffffffe 00000000
X
X
+ END-OF-FILE MacLuff.rc
chmod 'u=r,g=r,o=r' 'MacLuff.rc'
echo '	-r--r--r--  1 roland       1433 Aug 30 14:56 MacLuff.rc        (as sent)'
echo -n '	'
/bin/ls -l MacLuff.rc
echo 'Extracting MacLuff.h'
sed 's/^X//' > MacLuff.h << '+ END-OF-FILE MacLuff.h'
X#include <mac/quickdraw.h>
X#include <mac/toolintf.h>
X#include <mac/osintf.h>
X#include "def.h"
X
X#define WINDOW 128
X
X#define MENUS 4
X
X#define APPLE 1
X
X#define FILE 256
X#define NEW_GAME 1
X#define QUIT 3
X
X#define HELP 257
X
X#define COMMAND 258
X#define YOUR_MOVE 1
X#define REMOVE 2
X#define SHOW_GAME 3
X#define HINT 4
X
X#define FINGER 256
X
XMenuHandle my_menus[MENUS];
Xint the_menu, the_item;
XEventRecord my_event;
XCursHandle h_curs;
XCursor finger;
XWindowPtr which_w, the_w;
XWindowRecord w_record;
XRect play_r, xy_r[XZIZE][YZIZE], hole_r[4], drag_r, message_r;
XPoint mouse_p;
XGrafPort *save_port;
XLOGIC done_flag, message_flag;
+ END-OF-FILE MacLuff.h
chmod 'u=r,g=r,o=r' 'MacLuff.h'
echo '	-r--r--r--  1 roland        619 Feb  4  1985 MacLuff.h        (as sent)'
echo -n '	'
/bin/ls -l MacLuff.h
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 30
X# define YZIZE 18
X# define BZIZE 540 /* 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 adm.c'
sed 's/^X//' > adm.c << '+ END-OF-FILE adm.c'
X#include "MacLuff.h"
X
X/* The main program which administrate who's on the move etc */
X
Xmain(){
X    int x, y;
X    struct QDVar QDVar;
X    DateTimeRec date_record;
X
X    QD = &QDVar;
X
X    /* Standard initialisation */
X    InitGraf(&thePort);
X    InitFonts();
X/*  FlushEvents(everyEvent, 0);                 */
X    InitWindows();
X    InitMenus();
X/*  TEInit();                                   */
X    InitDialogs((ProcPtr) 0);
X    InitCursor();
X
X    /* Application dependent initialisation */
X    init_the_w();
X    SetPort(the_w);
X    init_the_menu();
X    h_curs = GetCursor(FINGER); finger = **h_curs;
X
X    for(x = 0; x < XZIZE; x++)
X       for(y = 0; y < YZIZE; y++)
X	    board[x][y] = ' ';
X    done_flag = message_flag = FALSE;
X
X    GetTime(&date_record);
X    srand(date_record.second);
X
X    while(TRUE){
X	while(TRUE){
X	    if(Button())
X		slf = FALSE;
X	    if(!slf)
X		inmove(&x, &y); /* This is the main event loop */
X	    if(slf){
X		if(playcnt){
X		    if(!chose('x', &x, &y)){
X			draw_message("Can't find a place for my 'x'");
X			break;
X		    }
X		}
X		else{
X		    x = XZIZE/2;
X		    y = YZIZE/2;
X		}
X	    }
X	    play[x][y] = ++playcnt;
X	    draw_x(x, y);
X	    board[x][y] = 'x';
X	    if(update(x, y)){
X		draw_message("Congratulations you won");
X		break;
X	    }
X	    if(!chose('o', &x, &y)){
X		draw_message("Can't find a place for my 'o'");
X		break;
X	    }
X	    play[x][y] = ++playcnt;
X	    draw_o(x, y);
X	    board[x][y] = 'o';
X	    if(update(x, y)){
X		draw_message("I won");
X		break;
X	    }
X	}
X	DisableItem(my_menus[3], SHOW_GAME);
X	DisableItem(my_menus[3], HINT);
X	done_flag = TRUE;
X	slf = FALSE;
X    }
X}
X
Xinit_the_w(){
X    int x, y;
X
X    the_w = GetNewWindow(WINDOW, &w_record, (WindowPtr) -1);
X
X    SetRect(&play_r, 0, 35, XZIZE*15, YZIZE*15 + 35);
X    SetRect(&message_r, 0, 0, 450, 34);
X    for(x = 0; x < XZIZE; x++)
X	for(y = 0; y < YZIZE; y++)
X	    SetRect(&xy_r[x][y], x*15 - 1, y*15 + 34, x*15 + 15, y*15 + 50);
X    SetRect(&hole_r[0], 130, 15, 140, 25);
X    SetRect(&hole_r[1], 160, 15, 170, 25);
X    SetRect(&hole_r[2], 270, 15, 280, 25);
X    SetRect(&hole_r[3], 300, 15, 310, 25);
X}
X
Xinit_the_menu(){
X    my_menus[0] = GetMenu(APPLE);
X    InsertMenu(my_menus[0], 0);
X
X    my_menus[1] = GetMenu(FILE);
X    InsertMenu(my_menus[1], 0);
X
X    my_menus[2] = GetMenu(HELP);
X    InsertMenu(my_menus[2], 0);
X
X    my_menus[3] = GetMenu(COMMAND);
X    InsertMenu(my_menus[3], 0);
X
X    DrawMenuBar();
X}
+ END-OF-FILE adm.c
chmod 'u=r,g=r,o=r' 'adm.c'
echo '	-r--r--r--  1 roland       2403 Oct 21 15:12 adm.c        (as sent)'
echo -n '	'
/bin/ls -l adm.c
echo 'Extracting inmove.c'
sed 's/^X//' > inmove.c << '+ END-OF-FILE inmove.c'
X#include "MacLuff.h"
X
X/* Routin for input of moves and commands (Main event loop) */
Xinmove(x, y) int *x, *y;{
X    FlushEvents(everyEvent, 0);
X    HiliteMenu(0);
X
X    while(TRUE){
X	GetNextEvent(everyEvent, &my_event);
X	adjust_cursor();
X	mouse_p.h = my_event.where.h;
X	mouse_p.v = my_event.where.v;
X	GlobalToLocal(&mouse_p);
X	switch(my_event.what){
X	    case mouseDown:
X		if(playcnt){
X		    DisableItem(my_menus[3], YOUR_MOVE);
X		    EnableItem(my_menus[3], REMOVE);
X		}
X		else{
X		    EnableItem(my_menus[3], YOUR_MOVE);
X		    DisableItem(my_menus[3], REMOVE);
X		}
X		switch(FindWindow(&my_event.where, &which_w)){
X		    case inMenuBar:
X			if( do_command(MenuSelect(&my_event.where)) )
X			    return;
X			FlushEvents(everyEvent, 0);
X			break;
X		    case inContent:
X			if(message_flag){
X			    EraseRect(&message_r);
X			    draw_holes();
X			    message_flag = FALSE;
X			}
X			if( !done_flag )
X			    if( the_w_click(x, y) )
X				return;
X			break;
X		    case inDrag:
X			DragWindow(which_w, &my_event.where, &drag_r);
X			break;
X		}
X		break;
X	    case updateEvt:
X		BeginUpdate(the_w);
X		utboard();
X		EndUpdate(the_w);
X		break;
X	 }
X    }
X}
X
Xdo_command(help) int help;{
X    char who;
X    int x, y;
X
X    the_menu =  HiWord(help);
X    the_item =  LoWord(help);
X    switch(the_menu){
X	case APPLE:
X	    say_something();
X	    break;
X	case FILE:
X	    switch(the_item){
X		case NEW_GAME:
X		    if(message_flag){
X			EraseRect(&message_r);
X			draw_holes();
X			message_flag = FALSE;
X		    }
X		    for(x = 0; x < XZIZE; x++)
X			for(y = 0; y < YZIZE; y++){
X			    if(board[x][y] != ' '){
X				play[x][y] = 0;
X				board[x][y] = ' ';
X				update(x, y);
X				draw_empty(x, y);
X			    }
X			}
X		    EnableItem(my_menus[3], HINT);
X		    EnableItem(my_menus[3], SHOW_GAME);
X		    done_flag = FALSE;
X		    playcnt = 0;
X		    break;
X		case QUIT:
X		    ExitToShell();
X		    break;
X	    }
X	    break;
X	case HELP:
X	    say_something_else();
X	    break;
X	case COMMAND:
X	    if(message_flag){
X		EraseRect(&message_r);
X		draw_holes();
X		message_flag = FALSE;
X	    }
X	    switch(the_item){
X		case YOUR_MOVE:
X		    x = XZIZE/2;
X		    y = YZIZE/2;
X		    board[x][y] = 'o';
X		    update(x, y);
X		    play[x][y] = ++playcnt;
X		    draw_o(x, y);
X		    break;
X		case REMOVE:
X		    while(TRUE){
X			if(playcnt == 0)
X			    break;
X			for(x = 0; x < XZIZE; x++)
X			    for(y = 0; y < YZIZE; y++)
X				if(play[x][y] == playcnt){
X				    play[x][y] = 0;
X				    who = board[x][y];
X				    board[x][y] = ' ';
X				    update(x, y);
X				    draw_empty(x, y);
X				}
X			playcnt--;
X			if(who == 'x')
X			    break;
X		    }
X		    EnableItem(my_menus[3], HINT);
X		    EnableItem(my_menus[3], SHOW_GAME);
X		    done_flag = FALSE;
X		    break;
X		case SHOW_GAME:
X		    slf = TRUE;
X		    draw_message("Push mouse button to stop");
X		    return(TRUE);
X		    break;
X		case HINT:
X		    if(chose('x', &x, &y))
X			draw_hint(x, y);
X		    break;
X	    }
X	break;
X    }
X    HiliteMenu(0);
X    return(FALSE);
X}
X
Xadjust_cursor(){
X    if(PtInRect(&mouse_p, &play_r))
X	SetCursor(&finger);
X    else
X	SetCursor(&QD->arrow);
X}
X
Xthe_w_click(x, y) int *x, *y;{
X    if(PtInRect(&mouse_p, &play_r)){
X	*x = mouse_p.h/15;
X	*y = (mouse_p.v - 35)/15;
X	if(board[*x][*y] == ' '){
X	    InvertRect(&xy_r[*x][*y]);
X	    while(StillDown());
X	    InvertRect(&xy_r[*x][*y]);
X	    return(TRUE);
X	}
X    }
X    return(FALSE);
X}
X
Xsay_something(){
X    EraseRect(&play_r);
X    MoveTo(50, 50);  DrawString("Luff is written by:");
X    MoveTo(50, 80);  DrawString("Roland Karlsson");
X    MoveTo(50, 95);  DrawString("Dpt. of Telecomm. & Computer Systems");
X    MoveTo(50, 110); DrawString("Royal Institute of Technology");
X    MoveTo(50, 125); DrawString("S-100 44 Stockholm, SWEDEN");
X    MoveTo(50, 150); DrawString("roland@ttds");
X    while( ! Button() );
X    utboard();
X}
X
Xsay_something_else(){
X    draw_message("Just point and push until you get 5 in a row");
X}
+ END-OF-FILE inmove.c
chmod 'u=r,g=r,o=r' 'inmove.c'
echo '	-r--r--r--  1 roland       3855 Aug 29 15:40 inmove.c        (as sent)'
echo -n '	'
/bin/ls -l inmove.c
echo 'Extracting terminal.c'
sed 's/^X//' > terminal.c << '+ END-OF-FILE terminal.c'
X#include "MacLuff.h"
X
Xdraw_x(x, y){
X	int dummy;
X
X	EraseRect(&xy_r[x][y]);
X	FrameRect(&xy_r[x][y]);
X
X	MoveTo(x*15 + 1, y*15 + 36);
X	Line(11, 11);
X	Move(0, -11);
X	Line(-11, 11);
X
X	InvertRect(&xy_r[x][y]);
X	Delay(10, &dummy);
X	InvertRect(&xy_r[x][y]);
X}
X
Xdraw_o(x, y){
X	int dummy;
X
X	EraseRect(&xy_r[x][y]);
X	FrameRect(&xy_r[x][y]);
X
X	InsetRect(&xy_r[x][y], 2, 2);
X	FrameOval(&xy_r[x][y]);
X	InsetRect(&xy_r[x][y], -2, -2);
X
X	InvertRect(&xy_r[x][y]);
X	Delay(10, &dummy);
X	InvertRect(&xy_r[x][y]);
X}
X
Xdraw_empty(x, y){
X	EraseRect(&xy_r[x][y]);
X	FrameRect(&xy_r[x][y]);
X}
X
Xdraw_hint(x, y){
X	int dummy;
X
X	InvertRect(&xy_r[x][y]);
X	Delay(60, &dummy);
X	InvertRect(&xy_r[x][y]);
X}
X
Xdraw_message(string) char *string;{
X	int dummy;
X
X	EraseRect(&message_r);
X	MoveTo(5, 20);
X	DrawString(string);
X	InvertRect(&message_r);
X	SysBeep(1);
X	Delay(60, &dummy);
X	InvertRect(&message_r);
X	message_flag = TRUE;
X}
+ END-OF-FILE terminal.c
chmod 'u=r,g=r,o=r' 'terminal.c'
echo '	-r--r--r--  1 roland        888 Mar  6  1985 terminal.c        (as sent)'
echo -n '	'
/bin/ls -l terminal.c
echo 'Extracting utboard.c'
sed 's/^X//' > utboard.c << '+ END-OF-FILE utboard.c'
X# include "MacLuff.h"
X
X/* Prints out an image of th board */
Xutboard(){
X	int x, y;
X
X	HideCursor();
X
X	EraseRect(&the_w->portRect);
X
X	draw_holes();
X
X	for(y = 0; y < YZIZE; y++){
X		for(x = 0; x < XZIZE; x++){
X			switch(board[x][y]){
X				case ' ':
X					draw_empty(x, y);
X					break;
X				case 'o':
X					draw_o(x, y);
X					break;
X				case 'x':
X					draw_x(x, y);
X					break;
X			}
X
X		}
X	}
X	ShowCursor();
X}
X
Xdraw_holes(){
X	int x, y;
X
X	for(x = 0; x < 4; x++){
X		PenPat(&QD->gray);
X		PaintOval(&hole_r[x]);
X		PenPat(&QD->black);
X		FrameOval(&hole_r[x]);
X	}
X}
+ END-OF-FILE utboard.c
chmod 'u=r,g=r,o=r' 'utboard.c'
echo '	-r--r--r--  1 roland        549 Aug 29 15:09 utboard.c        (as sent)'
echo -n '	'
/bin/ls -l utboard.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 Feb  4  1985 automat.c        (as sent)'
echo -n '	'
/bin/ls -l automat.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 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 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 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 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 21 08:55 make_header        (as sent)'
echo -n '	'
/bin/ls -l make_header
echo 'Extracting maketabell'
sed 's/^X//' > maketabell << '+ END-OF-FILE maketabell'
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 maketabell
chmod 'u=r,g=r,o=r' 'maketabell'
echo '	-r--r--r--  1 roland        620 Oct 21 08:55 maketabell        (as sent)'
echo -n '	'
/bin/ls -l maketabell
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 21 08:55 makeautomat.c        (as sent)'
echo -n '	'
/bin/ls -l makeautomat.c
exit 0