-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrawing.ps
More file actions
executable file
·265 lines (187 loc) · 5.63 KB
/
drawing.ps
File metadata and controls
executable file
·265 lines (187 loc) · 5.63 KB
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
258
259
260
261
262
263
264
265
% Nicolas Seriot
% 2024-03-23
% https://github.com/nst/PSChess
% https://seriot.ch/projects/pschess.html
(logic_chess.ps) run
/SQUARE_SIZE 20 def
/PiecesPathsDict
<<
/m { moveto } bind def
/l { lineto } bind def
/p { newpath SQUARE_SIZE 2 div SQUARE_SIZE 2 div 4 0 360 arc closepath }
/r { newpath 5 15 m 7 15 l 7 13 l 9 13 l 9 15 l 11 15 l 11 13 l 13 13 l
13 15 l 15 15 l 15 11 l 13 10 l 13 3 l 7 3 l 7 10 l 5 11 l 5 15 l
closepath }
/n { newpath 12 15 m 14 3 l 6 3 l 10 9 l 6 9 l closepath }
/b { newpath 14 3 m 12 10 l 10 12 3 -30 30 arc
10 12 l 10 12 3 80 210 arc 8 10 l 6 3 l closepath }
/q { newpath 4 12 m 8 10 l 10 15 l 12 10 l 16 12 l 12 3 l 8 3 l closepath }
/k { newpath 8 3 m 5 9 l 9 9 l 9 11 l 7 11 l 7 13 l 9 13 l 9 15 l 11 15 l
11 13 l 13 13 l 13 11 l 11 11 l 11 9 l 15 9 l 12 3 l closepath }
/. {}
>> def
/_piece_Draw {
(/_piece_Draw) CS_PUT
3 dict begin
/x exch def
%x AssertTypeString
% lowercase letters mean white pieces, except '.' for empty
/xLowS { x _p_DupLowerCase_p_ } def
PiecesPathsDict xLowS get exec
/isWhite { x (.) ne x _piece_IsWhite_b_ and } def
gsave
isWhite {1.0}{0.0} ifelse setgray
fill
grestore
0 setgray
stroke
end
CS_POP
} def
/_pieces_DrawCapturedPieces {
(/_pieces_DrawCapturedPieces) CS_PUT
3 dict begin
/pieces exch def
gsave
0 1 pieces length 1 sub {
/i exch def
/c pieces i 1 getinterval def
c (.) eq { exit } if
%c show
c _piece_Draw
12 0 translate
i 7 eq { 12 -8 mul -15 translate } if
} for
grestore
end
CS_POP
} def
/_hR_hG_hB_piece_isHatched_DrawSquare {
(/_hR_hG_hB_piece_isHatched_DrawSquare) CS_PUT
10 dict begin
/isHatchedSquare exch def
/p exch def
/hB exch def
/hG exch def
/hR exch def
%isBlackSquare AssertTypeBool
%p AssertTypeString
isHatchedSquare {0.7}{1.0} ifelse setgray
hR null ne
hG null ne and
hB null ne and {
hR hG hB setrgbcolor
} if
gsave
0 0 SQUARE_SIZE SQUARE_SIZE rectfill
0.0 setgray
0 0 SQUARE_SIZE SQUARE_SIZE rectstroke
grestore
p _piece_Draw
end
CS_POP
} def
/_highlightIndices_board_DrawBoard {
(/_highlightIndices_board_DrawBoard) CS_PUT
2 2 scale
20 dict begin
/b exch def
/hs exch def % indices to highlight
%hs AssertTypeArray
hs length 64 ne { (-- ERROR: hs length:) ==only hs length == quit } if
% iterate board, draw squares and pieces
gsave
% clear page, required with flushpage in ghostview
gsave
1 setgray
-20 -20 400 300 rectfill
grestore
SQUARE_SIZE 0 mul SQUARE_SIZE 7 mul translate
0 0 moveto
0 1 b length 1 sub {
/i exch def
i 0 ne i 8 mod 0 eq and {
SQUARE_SIZE -8 mul SQUARE_SIZE -1 mul translate
} if
/p { b i 1 getinterval } def
/isBlackSquare { i 8 idiv i add 2 mod 0 ne } def
/hR null def
/hG null def
/hB null def
% move type ALLOWED
hs i get 1 eq {
/hR 1 def
/hG 1 def
/hB 0 def
} if
% move type NOT_ALLOWED
hs i get 2 eq {
/hR 1 def
/hG 0 def
/hB 0 def
} if
% move type FROM
hs i get 3 eq {
/hR 0 def
/hG 1 def
/hB 0 def
} if
hR hG hB p isBlackSquare _hR_hG_hB_piece_isHatched_DrawSquare
% show square numbers
%gsave
%/Courier findfont 7 scalefont setfont
%0 0 moveto
%i 2 string cvs show
%grestore
SQUARE_SIZE 0 translate
} for
grestore
% show coordinates
gsave
1 1 8 {
/i exch def
% row numbers
-13 i 1 sub SQUARE_SIZE mul 6 add moveto
i ( ) cvs show
% col letters
i SQUARE_SIZE mul 14 sub -12 moveto
/n ( ) def
n 0 i 96 add put
n show
} for
grestore
end
CS_POP
} def
/_highlights_DrawBoard {
(/_highlights_DrawBoard) CS_PUT
5 dict begin
/highlights exch def
gsave
50 50 translate
highlights GameState (BOARD) get _highlightIndices_board_DrawBoard
%GameState (LAST_MESSAGE) msg put
%GameState (CAPTURED_BY_BLACK) (ppppppppbbbbbbbb) put
%GameState (CAPTURED_BY_WHITE) (PPPPPPPPKKKKKKKK) put
170 0 translate
0 150 moveto
GameState (LAST_MOVE) get show
0 135 moveto
GameState (BOARD) get _b_Eval_score_ 10 string cvs show
0 105 moveto
GameState (LAST_MESSAGE) get show
0 90 moveto
GameState (PLAYER_TURN_MESSAGE) get show
grestore
% --
gsave
2 2 scale
185 80 translate
0 0 moveto
GameState (CAPTURED_BY_BLACK) get _pieces_DrawCapturedPieces
0 -40 translate
GameState (CAPTURED_BY_WHITE) get _pieces_DrawCapturedPieces
grestore
end
CS_POP
} def