[net.chess] filter to generate boards for troff

trb@masscomp.UUCP (Andy Tannenbaum) (04/02/85)

Has anyone written a filter to convert human-readable
board positions into input for the chess macros which came with 4bsd?
(The documentation says that they're from Stanford, and I think you
can also get them from Imagen and elsewhere.)

It would take a board that looked like

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

And transform it into

HTTTTTTTTX
VrmblkansF
VopopopopF
V0Z0Z0Z0ZF
VZ0Z0Z0Z0F
V0Z0Z0Z0ZF
VZ0Z0Z0Z0F
VPOPOPOPOF
VSNAQJBMRF
WUUUUUUUUG

The filter would work like tbl, eqn, pic, etc., fiddling with data
between .CS and .CE or something.  If no one out there has one, I
suppose I might write it on some rainy day soon.

Also, I have this font on an Imagen 8/300.  What are the
settings for spacing (with .cs and .vs) which yield the prettiest
boards?  (I have been using .ps 14, and .cs <point-size*2> doesn't
work as nicely as it does in the Berkeley font catalog.

	Andy Tannenbaum   Masscomp  Westford, MA   (617) 692-6200 x274

trb@masscomp.UUCP (Andy Tannenbaum) (04/02/85)

I decided after posting the message which this one follows that I
should write the filter I requested, for a program which takes human
readable chess board listings as input, and puts out troff chess font
output.

	Andy Tannenbaum   Masscomp  Westford, MA   (617) 692-6200 x274
<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>
/*
 * cbtpp - chess board troff preprocessor
 * Andy Tannenbaum MASSCOMP 4/1/85
 *
 *	maps		to
 *
 *	HTTTTTTTTX	HTTTTTTTTX
 *	VrnbqkbnrF	VrmblkansF
 *	VppppppppF	VopopopopF
 *	V........F	V0Z0Z0Z0ZF
 *	V........F	VZ0Z0Z0Z0F
 *	V........F	V0Z0Z0Z0ZF
 *	V........F	VZ0Z0Z0Z0F
 *	V........F	V0Z0Z0Z0ZF
 *	V........F	VZ0Z0Z0Z0F
 *	VPPPPPPPPF	VPOPOPOPOF
 *	VRNBQKBNRF	VSNAQJBMRF
 *	WUUUUUUUUG	WUUUUUUUUG
 *
 * Reads stdin, writes stdout.
 * CAPS are white pieces, dots are blank squares.
 * It doesn't add borders, it will filter them properly.
 * You might want to write a separate filter which calls
 * cbtpp on a buffer bracketed by a .CS/.CE pair a la eqn or tbl.
 *
 */

#include <stdio.h>
#define BLACK 0
#define WHITE 1
#define flip(x) (x ^= 1)

/*
 * \n is part of these arrays so that it will cause
 * the square color to flip at end of line, this assumes a
 * board of even width.  The border characters are in here
 * so that there will always be an even number of mapped
 * characters output before the first white square, whether
 * you include borders or not.
 */

char in[] = "rnbqkp.RNBQKPHTXFGUWV\n";	/* input tokens */
char wh[] = "rnbqkp0RNBQKPHTXFGUWV\n";	/* mappings for white squares */
char bl[] = "smaljoZSMALJOHTXFGUWV\n";	/* mappings for black squares */

/*
 * Get a character c, if it's in the in[] array, then put a character
 * from wh[] or bl[], depending on the current square color, and flip
 * square color.  If c isn't in in[], then just echo it.
 */

main(){
	int c, i, square = BLACK;

	while ((c = getchar()) != EOF)
		putchar(
			((i = strchr(in, c)) == NULL) ?
			 c :
			 (
			  ((flip(square)) == BLACK) ?
			   bl :
			   wh
			 )[i - (int)in]
		       );
}

colonel@gloria.UUCP (Col. G. L. Sicherman) (04/06/85)

> Has anyone written a filter to convert human-readable
> board positions into input for the chess macros which came with 4bsd?
> It would take a board that looked like > 
> rnbqkbnr
> pppppppp
> ........
[etc.]
> 
> And transform it into
> 
> HTTTTTTTTX
> VrmblkansF
> VopopopopF
> V0Z0Z0Z0ZF
[etc.]
> 
A simple sed script could probably do that...
I have a simple Forsythe-to-troff converter.  It takes input like
8/1rn6/3B4/6Pp/2PP3k/1K6/1n5n/8.  Anybody who wants it, send mail.
-- 
Col. G. L. Sicherman
...{rocksvax|decvax}!sunybcs!colonel