Path: uunet!tektronix!tekgen!tekred!games
From: games@tekred.TEK.COM
Newsgroups: comp.sources.games
Subject: v05i001: chess-bd - TeX chess position drawing program
Message-ID: <2767@tekred.TEK.COM>
Date: 5 Jul 88 23:04:06 GMT
Sender: billr@tekred.TEK.COM
Lines: 104
Approved: billr@saab.CNA.TEK.COM
Submitted by: Charles Blair
Comp.sources.games: Volume 5, Issue 1
Archive-name: chess-bd
[I don't have a TeX system, so you're on your own. -br]
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh chess_bd.tex <<'END_OF_chess_bd.tex'
X%
X% This is a set of macros to be used with plain TeX to print out
X% a diagram of a chess position. The control sequence \bone
X% takes as input the Forsyth notation for a position, followed by
X% EEZ as a terminator. Forsyth notation describes the position
X% one row at a time, with capital letters for white pieces, small
X% letters for black pieces, and uses numbers for empty squares.
X% For example, to print the diagram after Black's third move in Ruy:
X%
X% \bone r1bqkbnr 1ppp1ppp p1n5 1B2p3 4P3 5N2 PPPP1PPP RNBQK2R EEZ
X%
X% Similarly, \btwo can be used to print two adjacent diagrams---
X% you give the Forsyth for one position, then EEZ, then the Forsyth
X% for the other followed by a second EEZ.
X%
X% To run these macros on your system you may have to modify the
X% \font instruction indicated below.
X%
X% The bad thing is that this program seems to be a memory hog. If
X% I try to print more than three or four diagrams in a letter, I
X% start getting "memory capacity exceeded" messages. I'm using
X% PCTEX and have gotten around the problem by using the /m=65000
X% option described on pages I-18 and I-19 of the installation guide.
X%
X% Improvements for the memory problem or the appearance of the
X% diagrams are welcome.
X%
X% As a bonus, the macro \VAR can be used to number the moves of
X% a variation. Suppose, for example, you want to list moves from
X% the Schliemann defence to the Ruy, starting with move 3. Type
X%
X% \VAR 3 B--N5 P--B4 N-B3! N-B3 PxP B-B4 O-O O-O Z [Z=terminator]
X%
X% and you get 3 B-N5 P-B4 4 N-B3! N-B3 and so forth. [also works
X% with algebraic notation. Sequence of moves from Fine's Practical
X% Chess Openings.] Unfortunately, this also has memory problems---
X% my machine complains if the variation is longer than ten moves.
X%
X% ---Charles Blair [BITNET:CEBLAIR@UIUCVMD]
X\magnification=1200
X\newcount\empty \newcount\color% empty keeps track of number of empty
X %squares, color tells if shading needed
X\def\ver{\vrule height 15pt} \font\eightrm=amr8
X% IF YOU ARE NOT USING PCTEX, YOU WILL PROBABLY HAVE TO MODIFY
X% THE \font INSTRUCTION ABOVE TO WHATEVER PRODUCES EIGHT-POINT
X% ROMAN ON YOUR SYSTEM
X\def\hv{\hfil\ver} \def\shade{\hbox to 15pt{\hv\hv\hv\hfil}}
X%shade is a dark square with no piece on it, pshad (below) with piece
X\def\hmv{\hfil\vbox to 15pt{\hrule height 2.6pt width 0.4pt\vfil
X\hrule height 3.0pt width 0.4pt}}
X\def\pshad{\hbox to 15pt{\hmv\hmv\hv\hfil}}
X\def\lett#1{\if #1p{\vbox to 15pt{\vfil\hbox{\eightrm p}\vfil}}%
X\else{\vbox to 15pt{\vfil \hbox{#1} \vfil}}\fi}
X\def\lbt{\ifodd\number\color\hbox to 15pt{\hfil\ver}%
X\else{\rlap{\shade}\hbox to 15pt{\hfil\ver}}\fi}
X\def\lettl#1{\hbox to 15pt{\hfil\lett{#1}\hfil\ver}}
X\def\llt#1{\ifodd\number\color {\lettl#1}\else {\rlap%
X{\pshad}\lettl#1}\fi\advance\color by 1}
X\def\lsr#1#2E{\ifcat 8#1\if 0#1\lsr#2DE\else{\empty=#1
X\advance\empty by -1
X\hbox{\lbt\advance\color by1\lsr{\number\empty}#2E}}\fi%
X\else\if #1D{}\else{\hbox{\llt#1\lsr#2E}}\fi\fi}
X\def\board#1#2Z{\if E#1{{}}\else{\bord#1#2Z}\fi}
X\def\bord#1 #2Z{\vbox{{\hbox{\ver\lsr #1DE}}%
X\hrule width 120.4pt\advance\color by 1\board#2Z}}
X\def\bone#1Z{\color=1\medskip\hbox to \hsize{\hfil\vbox%
X{\hrule width 120.4pt\board#1Z}\hfil}\medskip\color=0}
X\def\btwo#1Z#2Z{\color=1\medskip\hbox to \hsize%
X{\hfil\vbox{\hrule width 120.4pt\board#1Z}\count2=1\hfil\vbox%
X{\hrule width 120.4pt\board#2Z}\hfil}\medskip\count2=0}
X\newcount\move \def\wump#1 #2U{{\number\move}~#1~#2\ }
X\def\VR#1 #2 #3Z{\wump#1 #2U\advance\move by 1\VFIN#3Z}
X\def\VFIN#1#2Z{\if W#1 \move=0 \else \VR#1#2Z\fi}
X\def\VAR#1 #2Z{\move=#1 \VR#2 W W Z}
X
END_OF_chess_bd.tex
if test 3646 -ne `wc -c