summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/cchess/cchessboard.tex
blob: 539fc2e923202fa781fabb03888fa0cc61c158aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
\documentstyle{article}
% cchessboard.tex
%
% papier 8.5in x 11in = 21.59cm x 27.94cm
% dessin 17.6cm x 19.8cm
%\hoffset=-0.545cm% devrait etre la bonne valeur, mais...!??
\hoffset=-1.545cm

\setlength{\textwidth}{20cm}\setlength{\textheight}{22cm}
\setlength{\oddsidemargin}{0cm}\setlength{\evensidemargin}{0cm}
\setlength{\topmargin}{0cm}\setlength{\headheight}{0cm}

% If the font size is changed, the macro  WhiteMask  must also be changed
\newfont{\EchecsChinois}{cchess46}
\newcounter{piecex}\newcounter{piecey}

\special{! /WhiteMask
 { 
  gsave 
  [] 0 setdash 0 setlinejoin 0 setlinecap 
% the gray level could be changed to 0.95, for light gray pieces that stand out
% better on a white board.  Here, it is set to full white (0.0 is full black).
  1.0 setgray 
% Here, the 102 was determined by trial and error.  Must find an algebraic way to fix it!
% that's the radius of the masking circle.
  102 dup scale 
  currentpoint translate newpath 0. 0. 1. 0. 360. arc closepath fill
  grestore
 } def }

\newcommand{\piece}[3]{%   macro pour afficher une piece
\setcounter{piecex}{#1}\addtocounter{piecex}{-1}%
\setcounter{piecey}{#2}\addtocounter{piecey}{-1}%
\put(\value{piecex},\value{piecey}){\special{" grestore WhiteMask gsave}}%
\put(\value{piecex},\value{piecey})%
{\setbox0=\hbox{\EchecsChinois #3}\kern-0.5\wd0\box0}%
}

\begin{document}
\thispagestyle{empty}
\begin{center}
\setlength{\unitlength}{2.2cm}%
\begin{picture}(8.1,9.1)%
\put(0,0){\framebox(8,9){}}%
\put(-0.05,-0.05){\framebox(8.1,9.1){}}%
%
\newsavebox{\Something}%
\savebox{\Something}(8,1)[bl]{%
\multiput(0,0)(1,0){8}{\framebox(1,1){}}}%
%
\multiput(0,0)(0,1){4}{\usebox{\Something}}%
\multiput(0,5)(0,1){4}{\usebox{\Something}}%
%
\newsavebox{\SW}\newsavebox{\SE}\newsavebox{\NE}\newsavebox{\NW}%
\savebox{\SW}(1,1)[bl]{%
\put(0.1,0.1){\line(1,0){0.2}}\put(0.1,0.1){\line(0,1){0.2}}}%
\savebox{\SE}(1,1)[bl]{%
\put(0.9,0.1){\line(-1,0){0.2}}\put(0.9,0.1){\line(0,1){0.2}}}%
\savebox{\NE}(1,1)[bl]{%
\put(0.9,0.9){\line(-1,0){0.2}}\put(0.9,0.9){\line(0,-1){0.2}}}%
\savebox{\NW}(1,1)[bl]{%
\put(0.1,0.9){\line(1,0){0.2}}\put(0.1,0.9){\line(0,-1){0.2}}}%
% On va commencer par faire les "croix" completes
\savebox{\Something}(2,2)[bl]{%
\put(0,0){\usebox{\NE}}\put(1,0){\usebox{\NW}}\put(1,1){\usebox{\SW}}\put(0,1){\usebox{\SE}}}%
%
\put(0,1){\usebox{\Something}}%
\put(6,1){\usebox{\Something}}%
\put(1,2){\usebox{\Something}}%
\put(3,2){\usebox{\Something}}%
\put(5,2){\usebox{\Something}}%
%
\put(0,6){\usebox{\Something}}%
\put(6,6){\usebox{\Something}}%
\put(1,5){\usebox{\Something}}%
\put(3,5){\usebox{\Something}}%
\put(5,5){\usebox{\Something}}%
% Maintenant les demi-croix gauches
\savebox{\Something}(1,2)[bl]{%
\put(0,0){\usebox{\NW}}\put(0,1){\usebox{\SW}}}%
\put(0,2){\usebox{\Something}}%
\put(0,5){\usebox{\Something}}%
% ...les demi-croix droites
\savebox{\Something}(1,2)[bl]{%
\put(0,0){\usebox{\NE}}\put(0,1){\usebox{\SE}}}%
\put(7,2){\usebox{\Something}}%
\put(7,5){\usebox{\Something}}%
%
% et pour finir, les camps des generaux:
\savebox{\Something}(2,2)[bl]{%
\put(0,0){\line(1,1){2}}% La "longueur" a fournir est celle de la projection horizontale
\put(2,0){\line(-1,1){2}}}%
\put(3,0){\usebox{\Something}}%
\put(3,7){\usebox{\Something}}%
%
\piece{1}{1}{r}\piece{9}{1}{r}%
\piece{2}{1}{n}\piece{8}{1}{n}%
\piece{3}{1}{b}\piece{7}{1}{b}%
\piece{4}{1}{g}\piece{6}{1}{g}%
\piece{2}{3}{c}\piece{8}{3}{c}%
\piece{1}{4}{p}\piece{3}{4}{p}\piece{5}{4}{p}\piece{7}{4}{p}\piece{9}{4}{p}%
\piece{5}{1}{k}%
\piece{1}{10}{R}\piece{9}{10}{R}%
\piece{2}{10}{N}\piece{8}{10}{N}%
\piece{3}{10}{B}\piece{7}{10}{B}%
\piece{4}{10}{G}\piece{6}{10}{G}%
\piece{2}{8}{C}\piece{8}{8}{C}%
\piece{1}{7}{P}\piece{3}{7}{P}\piece{5}{7}{P}\piece{7}{7}{P}\piece{9}{7}{P}%
\piece{5}{10}{K}%
%\piece{4}{5}{0}\put(3.3,4.4){\large Masque}%
\end{picture}
\end{center}
\end{document}
cut here------8<---- cchess46.mf ----8<----------------------- 
cut here------8<-----ccpieces.mf-----8<----------------------- 
cut here------8<----------------------8<-----------------------
Over the last few months, I have spent several nights coding a Chinese 
chess (xiangqi) font.  I had a cheap chess set I bought in Montreal's 
Chinatown a long time ago; 
in spite of the fact that I only paid 1US$ for it, its pieces have a 
nice pleasing look.  So I have undertaken to reproduce it as faithfully as I 
could.  The set was made in (communist) China, and bears no copyright 
mark of any kind; in the true communist spirit, I now distribute this font 
to you, and hope no one will try to sue me for it!  

I tried to be true to the original design, although no two pieces of the same
kind really looked the same under close examination.  I had to guess the
intent of the designer.  The model pieces were made of pale wood, about 3/4"
in diameter, with etched characters painted red and dark green.

This was my first serious METAFONT experience, and my lack of 
experience can be seen transpiring throughout the code.  The style of my 
coding evolved slightly as I progressed but I could not afford to redo the 
first pieces; so the code suffers from some inconsistency in style.  I also 
got a little tired in the end, and decided to cut short some 
descriptions; for example, all corners of the earlier pieces are rounded to 
various degrees.  This was intentional: I wanted the font to look like 
painted characters (on the real pieces, paint always produced rounded 
corners, in spite of the etching).  In the last pieces I coded, I used a few 
overlapping paths, which produce sharper corners at intersection points.  I 
kept those to a minimum, using them only for brush strokes that are 
clearly intersecting ones.

I called the pieces RED and BLACK.  The red pieces are generated as black 
on a white background, inside a thin black circle.  The black pieces are 
generated as white on a black circular background, with a thin white 
circle near the edge; these look like negatives of the original green pieces.

For those who might prefer the look of pieces painted on a white 
background (like in the original set), I added a modified copy of the black 
pieces, in which they are generated as black on a white background, 
surrounded by TWO circles;  this gives the edge a much darker look, and 
makes clear the distinction between black and red.  These could be used to 
produce colored pieces on a white background, and still be recognizable if 
printed only in black and white.  I recommend printing the whole font with 
one of the =fonttable.tex= utilities.

I also added two filled pieces that might be useful as masks.

The encoding is a simple and natural one for the regular pieces,
using capital letters for BLACK, lowercase for RED; for the third set of 
pieces (let's call it "alternate-black"), I had to use the remaining letters 
of the alphabet; I opted for consecutive ones.  Here they are, with some of 
their common names:


   K,k,S : king, general,
   G,g,T : guard, assistant
   B,b,U : bishop, elephant
   N,n,V : knight,horse
   R,r,W : rook, chariot, car
   C,c,X : cannon, gun, gunner
   P,p,Y : pawn, foot-soldier

   [J,0: masks  (not part of the game)]



BOARD DRAWING CODE:

If used as ordinary letters in text, the circular pieces will be nearly 
tangent to the baseline.  I defined a macro to place them CENTERED at the 
current point in a picture environment.  With the unit length properly 
chosen, one can then easily draw a Chinese chess board, and place any 
piece at any  board position by simply =\putting= the piece letter  (the 
macro will change the font) at the desired (x,y) integer valued coordinates 
(x=1..9, y=1..10)  (it should be easy to change this to the usual 
numerical/alphabetical notation).

  Example:   \piece{8}{10}{N}    places a black knight in  file 8, rank 10.

I have included a LaTeX file to draw such a board, with each piece in its 
starting position.  Only the last lines need changing (in an obvious way) to 
draw an arbitrary game situation (the board could do with a little decoration
in the river!).

Printer fonts normally behave like dark characters on a ***transparent*** 
background.  When placing a piece on the chessboard, one has to ERASE ANY 
UNDERLYING LINES FIRST. I could not think of a way of doing  this using only 
TeX and/or METAFONT.  So my piece placing macro uses a little bit of 
PostScript code to do this.  For that reason, it will only work with DVI -> 
PS converters that support  dvips=s raw-PS code insertion command 
(\special{! ...} and \special{! ...}).

Unfortunately, the font size (46pt) is presently hardcoded into this LaTeX
file.  To print smaller boards, one would have to change a small number of
dimension parameters (margins, picture unitlength, PS mask size) as well as
the font size.  I have not had time to implement and test automatic scaling
relations at the LaTeX level.

I have set the font normal and quad spaces to the diameter of the pieces,
and the font x height to half that diameter.  These can be used for kerning,
instead of using the width/height/depth of character boxes.  All characters
have the same box dimensions.


THE PACKAGE:

It consists in 3 files, appended at the end of this text, in this order
(look for the "cut here" lines):

1) the LaTeX file  cchessboard.tex  for drawing a starting board 
   (or any other game position)

2) the METAFONT driver file   cchess46.mf   for generating the  46pt cchess 
   font used by  cchessboard.tex

3) the main METAFONT character definition file,  ccpieces.mf

Some comments are in English, some are in French (I like to believe that
my native and favorite language is not dead yet). They are not important
since the whole thing is very simple.

Before I end, I would like to thank Barry Smith, of Blue Sky Research, for 
helping me during my early attempts at generating fonts on a Macintosh 
(MacPlus!), using their METAFONT implementation.


  Jacques Richer, Ph.D.  (Physics)               
  Centre de Recherche en Calcul Applique 
  5160, boul. Decarie, bureau 434,       
  Montreal, PQ, CANADA  H3X 2H9

  TEL: (514) 369-5234
  FAX: (514) 343-3880
  INTERNET: richer@cerca.umontreal.ca

(my address at work could change very soon)

 Home address:
  7029, rue Marquette
  Montreal, Quebec,
  CANADA  H2E 2C6


cut here------8<------- cchessboard.tex ------8<------------------