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

⟦8c3403360⟧ TextFile

    Length: 1589 (0x635)
    Types: TextFile
    Names: »check.c«

Derivation

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

TextFile

/* check.c */

#include "externs.h"

moveintocheck (from, to)
	int from, to;
{
	int victim, intocheck, color;
	LIST check ();

	color = whose [from];			/* make move on board */
	victim = findvictim (from, to);
	if (victim)
		whose [victim] = EMPTY;
	whose [to] = color;
	whose [from] = EMPTY;
	if (occupant [from] == KING)
		kingloc [color] = to;
	intocheck = (check (color) != NIL);	/* see if now in check */
	if (occupant [from] == KING)		/* restore board position */
		kingloc [color] = from;
	whose [from] = color;
	whose [to] = EMPTY;
	if (victim)
		whose [victim] = 1 - color;
	return intocheck;
}

LIST
check (color)
	int color;
{
	LIST l, checkdirs, lmember (), linsert ();
	int direction, spot, dist, side;

	checkdirs = NIL;
	l = dirlist [QUEEN];
	while (l != NIL) {
		direction = l->i;
		l = l->n;
		spot = kingloc [color];
		for (dist = 1; TRUE; dist++) {
			spot += direction;
			if ((whose [spot] == 1 - color)
			&& (lmember (-direction, dirlist [occupant [spot]])
			    && !(occupant [spot] == KING && dist > 1)))
				checkdirs = linsert (checkdirs, direction);
			if (whose [spot] != EMPTY)
				break;
		}
	}
	l = dirlist [KNIGHT];
	while (l != NIL) {
		direction = l->i;
		l = l->n;
		spot = kingloc [color] + direction;
		if (whose [spot] == 1 - color && occupant [spot] == KNIGHT)
			checkdirs = linsert (checkdirs, direction);
	}
	for (side = -1; side <= 1; side += 2) {
		spot = kingloc [color] + pawndir [color] + side;
		if (whose [spot] == 1 - color && occupant [spot] == PAWN)
			checkdirs = linsert(checkdirs, pawndir [color] + side);
	}
	
	return checkdirs;
}