DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T c

⟦f9f44a210⟧ TextFile

    Length: 2257 (0x8d1)
    Types: TextFile
    Names: »comp2.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Dots/comp2.c« 

TextFile

/*    COMP2.C    */

#include "dots.h"

goto_next_square(BorG, x, y)	/* returns 1 if there is one, 0 if not */
int BorG, *x, *y;
{
    int x1, y1, x2, y2;

    find_adj_squares(*x, *y, &x1, &y1, &x2, &y2);
    if (x1 != NULL && closure(BorG, x1, y1) == 3) {
	*x = x1, *y = y1;
	return (1);
    }
    if (x2 != NULL && closure(BorG, x2, y2) == 3) {
	*x = x2, *y = y2;
	return (1);
    }
    return (0);
}

find_adj_squares(x, y, x1, y1, x2, y2)
int x, y, *x1, *y1, *x2, *y2;
{
    if (isodd(x)) {	/* Vertical line */
	*x1 = x - 1;
	*y1 = y;
	*x2 = x + 1;
	*y2 = y;
    } else {		/* Horizontal line */
	*x1 = x;
	*y1 = y - 1;
	*x2 = x;
	*y2 = y + 1;
    }
    if (!is_on_board(*x1, *y1))
	*x1 = NULL, *y1 = NULL;
    if (!is_on_board(*x2, *y2))
	*x2 = NULL, *y2 = NULL;
}

goto_adj_free_line(BorG, x, y)
int BorG;
int *x, *y;
{
    int xtemp, ytemp;

    for (xtemp = *x - 1; xtemp <= *x + 1; xtemp += 2)
	if ((BorG == BAD ? badboard[xtemp][*y] : board[xtemp][*y]) == FREE) {
	    *x = xtemp;
	    return;
	}
    for (ytemp = *y - 1; ytemp <= *y + 1; ytemp += 2)
	if (board[*x][ytemp] == FREE)
	    if (((BorG == BAD)? badboard[*x][ytemp] : board[*x][ytemp])
		    == FREE) {
		*y = ytemp;
		return;
	    }
    printf("You fucked up, buddy!");
    fflush(stdout);
    die();
}

/*****************************************************************************\
|*  right now, this function doesn't actually go to the middle of a path,    *|
|*  it simply goes one line away from the edge. If the length of the path is *|
|*  two, the effect is the same.                                             *|
\*****************************************************************************/
goto_middle_of_path(BorG, x, y)
int BorG, *x, *y;
{
    int origx, origy, x1, y1, x2, y2;

    find_adj_squares(*x, *y, &x1, &y1, &x2, &y2);
    if (closure(BorG, x1, y1) == 2 && closure(BorG, x2, y2) == 2)
	return;		/* you're sitting on it to begin with */
    origx = *x, origy = *y;
    if (BorG == GOOD)
	board[origx][origy] = USED;
    else
	badboard[origx][origy] = USED;
    /* Temporarily */
    goto_next_square(BorG, x, y);
    goto_adj_free_line(BorG, x, y);

    if (BorG == GOOD)
	board[origx][origy] = FREE;
    else
	badboard[origx][origy] = FREE;
    /* SIGH! */
}