11 function set(x, y, n) {
12 sq = 'sq' + x + 'x' + y;
14 board[x][y] = document.getElementById(sq).innerHTML;
16 document.getElementById(sq).innerHTML = '<img src="sym/cyan.png">';
17 else if(n == 3 || n == 25)
18 document.getElementById(sq).innerHTML = '<img src="sym/red.png">';
20 document.getElementById(sq).innerHTML = '';
21 else if(n == 4 || n == 20)
22 document.getElementById(sq).innerHTML = '<img src="sym/green.png">';
24 document.getElementById(sq).innerHTML = '<img src="sym/orange.png">';
26 document.getElementById(sq).innerHTML = '<img src="sym/open.png">';
28 document.getElementById(sq).innerHTML = '<img src="sym/WhitePawn.png">';
30 document.getElementById(sq).innerHTML = '<img src="sym/BlackPawn.png">';
32 document.getElementById(sq).innerHTML = '<img src="sym/BlackRook.png">';
33 else if(n == 9 || n == 45)
34 document.getElementById(sq).innerHTML = '<img src="sym/BlackKing.png">';
36 document.getElementById(sq).innerHTML = '<img src="sym/WhiteKnight.png">';
38 document.getElementById(sq).innerHTML = '<img src="sym/WhiteHawk.png">';
39 else if(n == 12 || n == 60)
40 document.getElementById(sq).innerHTML = '<img src="sym/BlackUnicorn.png">';
42 document.getElementById(sq).innerHTML = '<img src="sym/yellow.png">';
44 document.getElementById(sq).innerHTML = board[x][y];
47 function text(s, t, n) {
48 if(t == '') t = ':<br>:<br>:';
50 document.getElementById('piece').innerHTML = s + '<br>' + t;
52 document.getElementById('piece').innerHTML = ':<br>:<br>:<br>:';
55 function slide(x, y, vx, vy, d, n) {
56 xx = x + vx; yy = y + vy; c = d;
57 if(vx > 1 || vx < -1 || vy > 1 || vy < -1) n = 5*n;
58 while(d-- > 0 && xx >= bw && xx < size - bw && yy >= 0 && yy < size) {
60 xx = xx + vx; yy = yy + vy;
61 if(c == 2 && n == 1) n = 5;
65 function slide_n(x, y, d, n) {
66 slide(x, y, 2, 1, d, n);
67 slide(x, y, 2,-1, d, n);
68 slide(x, y,-2, 1, d, n);
69 slide(x, y,-2,-1, d, n);
70 slide(x, y, 1, 2, d, n);
71 slide(x, y, 1,-2, d, n);
72 slide(x, y,-1, 2, d, n);
73 slide(x, y,-1,-2, d, n);
76 function slide_f(x, y, d, n) {
77 slide(x, y, 0, 1, d, n);
80 function slide_b(x, y, d, n) {
81 slide(x, y, 0, -1, d, n);
84 function slide_v(x, y, d, n) {
89 function slide_s(x, y, d, n) {
90 slide(x, y, 1, 0, d, n);
91 slide(x, y,-1, 0, d, n);
94 function slide_fd(x, y, d, n) {
95 slide(x, y, 1, 1, d, n);
96 slide(x, y,-1, 1, d, n);
99 function slide_bd(x, y, d, n) {
100 slide(x, y, 1, -1, d, n);
101 slide(x, y,-1, -1, d, n);
104 function slide_diag(x, y, d, n) {
105 slide_fd(x, y, d, n);
106 slide_bd(x, y, d, n);
109 function slide_orth(x, y, d, n) {
114 function highlight(x, y, m, n) {
116 } else if(x < 4 && y == 9) { // O-O-O
117 if(x == 3) { x = 1; p = 12; } else p = (45-36*m); // Knightmate
118 if(x == 2) { x = 0; z = 1; } else z = x; // Janus
119 slide(x, y, 2 + m, 0, 1, 3*n);
120 slide(x, y, 1 + m, 0, 1, p*n);
121 slide(x, y, 5 - z, 0, 1, 2*n);
122 slide(x, y, 0, 0, 1, 10*n);
123 text('Castling', ': <i>King and Rook swing around each other</i><br>:<br>:', n);
124 } else if(x > 6 && y == 9) { // O-O
125 if(m == 2) { z = x + 1; m = 0; } else z = x; // King left
126 if(x == 7) { x = 8; p = 12; z = x; } else p = (45-36*m); // Knightmate
127 slide(x, y,-2 - m, 0, 1, 3*n);
128 slide(x, y,-1 - m, 0, 1, p*n);
129 slide(x, y, 5 - z, 0, 1, 2*n);
130 slide(x, y, 0, 0, 1, 10*n);
131 text('Castling', ': <i>King and Rook swing around each other</i><br>:<br>:', n);
132 } else if((x == 4 || x == 5) && y == 9) { // castle
133 if(m == 0) f = 15; else f = 3;
134 slide(x, y, 2 + m, 0, 1, 4*n);
136 slide(x, y,-2 - m, 0, 1, 4*n);
137 text('Castling', ': <i>Click on Rook to see how</i><br>:<br>:', n);
138 } else if(x == 1 && y == 3) { // FIDE e.p.
139 slide(x, y, 1, 0, 1, 10*n);
140 slide(x, y, 1,-1, 1, 11*n);
141 slide(x, y, 0, 0, 1, 10*n);
142 text('en-passant capture', ': <i>A Pawn that just made a double-push past you</i><br>: <i>is caught by its tail</i><br>:', n);
143 } else if((x == 2 || x == 4) && y == 8) { // Berolina double-push
144 slide_bd(x, y, 2, 4*n);
145 slide_b(x, y, 1, 3*n);
146 if(m == 1) text('Hoplit', ': <i>Different capture (red) and non-capture (green)</i><br>' +
147 ': <i>Initial double-push non-capture can jump!</i><br>:', n);
148 else text('Berlin Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>' +
149 ': <i>Initial double-push non-capture can be blocked</i><br>' +
150 ': <i>The white Pawn can e.p. capture to the skipped square in front of it', n);
151 } else if(x == 2 && y == 1) { // FIDE double-push
152 slide_fd(x, y, 1, 3*n);
153 slide_f(x, y, 2, 4*n);
154 if(m == 2) text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>' +
155 ': <i>Initial double-push non-capture can be blocked</i><br>' +
156 ': <i>The black Pawn can e.p. capture to the skipped square', n); else
157 if(m == 1) text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>' +
158 ': <i>Initial double-push non-capture can be blocked</i><br>:', n);
159 else text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>:<br>:', n);
160 } else if(x == 2 && y == 6) { // Berolina
161 slide_bd(x, y, 1, 4*n);
162 slide_b(x, y, 1, 3*n);
163 if(m == 1) text('Hoplit', ': <i>Different capture (red) and non-capture (green)</i><br>:<br>:', n);
164 else text('Berlin Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>:<br>:', n);
165 } else if(x == 2 && y == 3) { // FIDE Pawn
166 slide_fd(x, y, 1, 3*n);
167 slide_f(x, y, 1, 4*n);
168 text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>:<br>:', n);
169 } else if(x == 2 && y == 5) { // XQ passed Pawn
172 text('Pawn (across the River)', '', n);
173 } else if(x == 2 && y == 2) { // XQ Pawn
176 } else if(x == 3 && y == 6) { // Modern Elephant
177 if(m == 1) { // Berolina e.p.
178 slide(x, y, 0, 0, 1, 10*n);
179 slide(x, y,-1, 0, 1, 10*n);
180 slide(x, y, 0, 1, 1, 8*n);
181 text('en-passant capture', ': <i>A Pawn that just made a double-push</i><br>' +
182 ': <i>crossing your path is caught by its tail</i><br>' +
183 ': <i>(Note the other white Pawn can NOT capture it!)</i>', n);
186 slide_diag(x, y, 2, n);
187 if(m == 2) text('Modern Elephant', '', n); else {
188 slide_s(x, y, 1, 4*n);
189 text('Lieutenant', ': <i>Jumps directly to orange squares</i><br>' +
190 ': <i>Sideway step non-capture only</i><br>:', n);
192 } else if(x == 3 && y == 5) { // KAD
193 slide_orth(x, y, 2, n);
194 slide_diag(x, y, 2, n);
195 text('Great General', '', n);
196 } else if(x == 3 && y == 4) { // KN / NAD
198 slide_diag(x, y, 2 - m, n);
199 if(m == 1) { text('Veteran', '', n); slide_orth(x, y, 1, n); }
200 else text('High Priestess', '', n);
201 } else if(x == 3 && y == 3) { // FvN
202 slide_orth(x, y, size, n);
204 } else if(x == 4 && y == 6) { // Dragon
205 slide_diag(x, y, 1, n);
206 slide_orth(x, y, size, n);
207 text('General', '', n);
208 } else if(x == 4 && y == 5) { // F
209 slide_diag(x, y, 1, n);
210 if(m == 2) text('Advisor (aka Mandarin or Palace Guard)', ': <i>Cannot leave Palace</i><br>:<br>:', n); else
211 if(m == 1) text('Met (aka Ferz, General)', '', n);
212 else text('Ferz (aka General)', '', n);
213 } else if(x == 4 && y == 4) { // Amazon / NWD
215 slide_orth(x, y, 2 + m*size, n);
216 if(m == 1) { text('Amazon', '', n); slide_diag(x, y, size, n); }
217 else text('Minister', '', n);
218 } else if(x == 4 && y == 3) { // N
219 if(m == 2) { slide_orth(x, y, 1, 7*n); f = 6; } else f = 1;
220 slide_n(x, y, 1, f*n);
221 if(m == 2) text('Horse', ': <i>Moves can be blocked on the adjacent square</i><br>' +
222 ': <i>marked with open circle, to which it cannot move</i><br>:', n); else
223 if(m == 1) text('Royal Knight', ': <i>Royal piece that has to be checkmated</i><br>:<br>:', n);
224 else text('Knight', '', n);
225 } else if(x == 5 && (y == 6 || y == 10)) { // BN
226 if(y == 10) { text('Hawk', '', n); y = 6; } else
227 if(m == 3) text('Janus', '', n); else
228 if(m == 2) text('Princess', '', n); else
229 if(m == 1) text('Warlord', '', n);
230 else text('Archbishop', '', n);
231 slide_diag(x, y, size, n);
233 } else if(x == 5 && y == 5) { // Alfil / XQ Elephant
235 slide(x, y, 2, 2, 1, f);
236 slide(x, y,-2, 2, 1, f);
237 slide(x, y, 2,-2, 1, f);
238 slide(x, y,-2,-2, 1, f);
240 slide_diag(x, y, 1, 7*n);
241 text('Elephant', ': <i>Can be blocked on the nearest square marked</i><br>' +
242 ': <i>with open circle, to which it cannot move</i><br>' +
243 ': <i>It cannot cross the River separating board halves</i>', n);
245 text('Elephant (aka Alfil)', '', n);
246 } else if(x == 5 && y == 4) { // RN
247 slide_orth(x, y, size, n);
249 if(m == 3) text('Empress', '', n); else
250 if(m == 2) text('Elephant', '', n); else
251 if(m == 1) text('Marshall', '', n);
252 else text('Chancellor', '', n);
253 } else if(x == 5 && y == 3) { // Q
254 slide_orth(x, y, size, n);
255 slide_diag(x, y, size, n);
256 text('Queen', '', n);
257 } else if(x == 6 && y == 6) { // WD
258 slide_orth(x, y, 2, n);
259 if(m == 2) text('War Machine', '', n);
260 else text('Captain', ': <i>Jumps directly to orange squares</i><br>:<br>:', n);
261 } else if(x == 6 && y == 5) { // Wazir
262 slide_orth(x, y, 1, n);
263 if(m == 1) text('King (aka General)', ': <i>Royal piece that has to be checkmated</i><br>: <i>Cannot leave Palace</i><br>:', n);
264 else text('Wazir (aka Grandvizer)', '', n);
265 } else if(x == 6 && y == 4) { // NN
266 slide_n(x, y, size, 4*n);
267 text('Nightrider', '', n);
268 } else if(x == 6 && y == 3) { // B
269 slide_diag(x, y, size, n);
270 text('Bishop', '', n);
271 } else if(x == 6 && y == 2) { // Silver
272 slide_diag(x, y, 1, n);
274 text('Elephant', '', n);
275 } else if(x == 7 && y == 2) { // XQ Canon
276 slide_v(x, y, 3, 4*n);
277 slide_s(x, y, 4, 4*n);
278 slide(x, y, 0, 7, 1, 5*n);
279 slide(x, y,-6, 0, 1, 5*n);
280 text('Canon', ': <i>Slides non-capturing to first obstacle</i><br>' +
281 ': <i>and can capture first piece behind that</i><br>:', n);
282 } else if(x == 7 && y == 0) { // Gating
283 slide(x, y, 0, 0, 1, 50*n);
284 slide(x, y,-1, 2, 1, 8*n);
285 bw = 0; slide(x, y, 2, 0, 1, 2*n); bw = 1;
286 text('Gating:', ': <i>On the first move of a back-rank piece</i><br>' +
287 ': <i>your Hawk or Elephant can appear from under it</i><br>:', n);
288 } else if(x == 7 && (y == 3 || y == 6)) { // K
289 slide_orth(x, y, 1, n);
290 slide_diag(x, y, 1, n);
291 if(m == 2) text('Soldier', '', n); else
292 if(m == 1) text('Commoner (aka Man)', '', n);
293 else text('King', '', n);
297 function down_click(x, y) {
301 for(i=0; i<12; i = i + 1) board[i] = new Array();
302 if(document.getElementById('sq0x0').innerHTML[1] == ' ') bw = 1;
309 x = -x; msg = msg + 2;
311 highlight(x, y, msg, 1);
312 savx = x; savy = y; down = 1;
313 // save = document.getElementById(sq).innerHTML;
314 // document.getElementById(sq).innerHTML = '<img src="sym/yellow.png">';
317 function up_click() {
318 highlight(savx, savy, msg, 0);
320 // document.getElementById('sq' + x + 'x' + y).innerHTML = save;