run tidy over html files; added include for gnu pages
[xboard.git] / whats_new / rules / cwda.js
1 var initDone = 0;
2 var board;
3 var save;
4 var savx;
5 var savy;
6 var msg;
7 var down = 0;
8 var size = 10;
9 var bw = 0;
10
11 function set(x, y, n) {
12   sq = 'sq' + x + 'x' + y;
13   if(n > 0) {
14     board[x][y] = document.getElementById(sq).innerHTML;
15     if(n == 2)
16       document.getElementById(sq).innerHTML = '<img src="sym/cyan.png">';
17     else if(n == 3)
18       document.getElementById(sq).innerHTML = '<img src="sym/red.png">';
19     else if(n == 10)
20       document.getElementById(sq).innerHTML = '';
21     else if(n == 4 || n == 20)
22       document.getElementById(sq).innerHTML = '<img src="sym/green.png">';
23     else if(n == 5)
24       document.getElementById(sq).innerHTML = '<img src="sym/orange.png">';
25     else if(n == 11)
26       document.getElementById(sq).innerHTML = '<img src="sym/BlackPawn.png">';
27     else if(n == 15)
28       document.getElementById(sq).innerHTML = '<img src="sym/BlackRook.png">';
29     else if(n == 30)
30       document.getElementById(sq).innerHTML = '<img src="sym/WhiteCrownedBishop.png">';
31     else if(n == 50)
32       document.getElementById(sq).innerHTML = '<img src="sym/BlackKing.png">';
33     else if(n == 60)
34       document.getElementById(sq).innerHTML = '<img src="sym/WhiteKing.png">';
35     else
36       document.getElementById(sq).innerHTML = '<img src="sym/yellow.png">';
37   } else
38     document.getElementById(sq).innerHTML = board[x][y];
39 }
40
41 function text(s, t, n) {
42   if(t == '') t = ':<br>:<br>:';
43   if(n)
44     document.getElementById('piece').innerHTML = s + '<br>' + t;
45   else
46     document.getElementById('piece').innerHTML = ':<br>:<br>:<br>:';
47 }
48
49 function slide(x, y, vx, vy, d, n) {
50     xx = x + vx; yy = y + vy; c = d;
51     if(vx > 1 || vx < -1 || vy > 1 || vy < -1) n = 5*n;
52     while(d-- > 0 && xx >= bw && xx < size - bw && yy >= 0 && yy < size) {
53         set(xx, yy, n);
54         xx = xx + vx; yy = yy + vy;
55         if(c == 2 && n == 1) n = 5;
56     }
57 }
58
59 function slide_n(x, y, d, n) {
60     slide(x, y, 2, 1, d, n);
61     slide(x, y, 2,-1, d, n);
62     slide(x, y,-2, 1, d, n);
63     slide(x, y,-2,-1, d, n);
64     slide(x, y, 1, 2, d, n);
65     slide(x, y, 1,-2, d, n);
66     slide(x, y,-1, 2, d, n);
67     slide(x, y,-1,-2, d, n);
68 }
69
70 function slide_f(x, y, d, n) {
71     slide(x, y, 0, 1, d, n);
72 }
73
74 function slide_b(x, y, d, n) {
75     slide(x, y, 0, -1, d, n);
76 }
77
78 function slide_v(x, y, d, n) {
79     slide_f(x, y, d, n);
80     slide_b(x, y, d, n);
81 }
82
83 function slide_s(x, y, d, n) {
84     slide(x, y, 1, 0, d, n);
85     slide(x, y,-1, 0, d, n);
86 }
87
88 function slide_fd(x, y, d, n) {
89     slide(x, y, 1, 1, d, n);
90     slide(x, y,-1, 1, d, n);
91 }
92
93 function slide_bd(x, y, d, n) {
94     slide(x, y, 1, -1, d, n);
95     slide(x, y,-1, -1, d, n);
96 }
97
98 function slide_diag(x, y, d, n) {
99     slide_fd(x, y, d, n);
100     slide_bd(x, y, d, n);
101 }
102
103 function slide_orth(x, y, d, n) {
104     slide_v(x, y, d, n);
105     slide_s(x, y, d, n);
106 }
107
108 function highlight(x, y, m, n) {
109    if(0) {
110    } else if(x == 1 && y == 9) { // castle
111       slide(x, y, 0, 0, 1, 10*n);
112       slide(x, y, 2, 0, 1, 10*n);
113       slide(x, y, 3, 0, 1, 3*n);
114       slide(x, y, 4, 0, 1, 2*n);
115       text('Castling', ': <i>King and corner piece swing around each other</i><br>:<br>:', n);
116    } else if(x == 8 && y == 9) { // castle
117       slide(x, y, 0, 0, 1, 10*n);
118       slide(x, y,-1, 0, 1, 50*n);
119       slide(x, y,-2, 0, 1, 3*n);
120       slide(x, y,-3, 0, 1, 2*n);
121       text('Castling', ': <i>King and corner piece swing around each other</i><br>:<br>:', n);
122    } else if(x == 5 && y == 9) { // castle
123       slide(x, y, 2, 0, 1, 4*n);
124       slide(x, y,-2, 0, 1, 4*n);
125       text('Castling', ': <i>Click on a corner piece to see how</i><br>:<br>:', n);
126    } else if(x == 1 && y == 0) { // castle
127       slide(x, y, 0, 0, 1, 10*n);
128       slide(x, y, 1, 0, 1, 60*n);
129       slide(x, y, 2, 0, 1, 6*n);
130       slide(x, y, 4, 0, 1, 2*n);
131       text('Castling', ': <i>King and corner piece swing around each other</i><br>' +
132                        ': <b>King goes to b1, to keep its partner on same color!</b><br>:', n);
133    } else if(x == 8 && y == 0) { // castle
134       slide(x, y, 0, 0, 1, 10*n);
135       slide(x, y,-1, 0, 1, 60*n);
136       slide(x, y,-2, 0, 1, 6*n);
137       slide(x, y,-3, 0, 1, 2*n);
138       text('Castling', ': <i>King and corner piece swing around each other</i><br>:<br>:', n);
139    } else if(x == 5 && y == 0) { // castle
140       slide(x, y, 2, 0, 1, 4*n);
141       slide(x, y,-3, 0, 1, 4*n);
142       text('Castling <b>with color-bound corner piece</b>', ': <i>Click on a corner piece to see how</i><br>:<br>:', n);
143    } else if(x == 1 && y == 3) { // FL
144       slide(x, y, 1, 0, 1, 10*n);
145       slide(x, y, 1,-1, 1, 11*n);
146       slide(x, y, 0, 0, 1, 10*n);
147       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);
148    } else if(x == 2 && y == 1) { // FL
149       slide_fd(x, y, 1, 3*n);
150       slide_f(x, y, 2, 4*n);
151       if(m == 2) text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>' +
152                               ': <i>Initial double-push non-capture can be blocked</i><br>' +
153                               ': <i>The black Pawn can e.p. capture to the skipped square', n);
154       else       text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>:<br>:', n);
155    } else if(x == 2 && y == 3) { // FL
156       slide_fd(x, y, 1, 3*n);
157       slide_f(x, y, 1, 4*n);
158       text('Pawn', ': <i>Different capture (red) and non-capture (green)</i><br>:<br>:', n);
159    } else if(x == 3 && y == 6) { // FL
160       slide_orth(x, y, size, n);
161       text('Rook', '', n);
162    } else if(x == 3 && y == 5) { // +V
163       slide_orth(x, y, 4, n);
164       text('Short Rook', ': <i>Slides upto 4 squares</i><br>:<br>:', n);
165    } else if(x == 3 && y == 4) { // +H
166       slide_orth(x, y, 1, n);
167       slide(x, y, 2, 2, 1, n);
168       slide(x, y,-2, 2, 1, n);
169       slide(x, y, 2,-2, 1, n);
170       slide(x, y,-2,-2, 1, n);
171       text('Elephant', '', n);
172    } else if(x == 3 && y == 3) { // fibnif
173       slide_diag(x, y, 1, n);
174       slide(x, y, 1, 2, 1, n);
175       slide(x, y,-1, 2, 1, n);
176       slide(x, y, 1,-2, 1, n);
177       slide(x, y,-1,-2, 1, n);
178       text('Horse', '', n);
179    } else if(x == 4 && y == 6) { // +A
180       slide_n(x, y, 1, n);
181       text('Knight', '', n);
182    } else if(x == 4 && y == 5) { // +D
183       slide_diag(x, y, 1, n);
184       slide(x, y, 2, 0, 1, n);
185       slide(x, y,-2, 0, 1, n);
186       slide(x, y, 0,-2, 1, n);
187       slide(x, y, 0, 2, 1, n);
188       slide(x, y, 3, 0, 1, n);
189       slide(x, y,-3, 0, 1, n);
190       slide(x, y, 0,-3, 1, n);
191       slide(x, y, 0, 3, 1, n);
192       text('Half-Duck', '', n);
193    } else if(x == 4 && y == 4) { // Lion
194       slide_diag(x, y, size, n);
195       slide(x, y, 2, 0, 1, n);
196       slide(x, y,-2, 0, 1, n);
197       slide(x, y, 0,-2, 1, n);
198       slide(x, y, 0, 2, 1, n);
199       text('Leaping Bishop', ': <i>Color bound</i><br>:<br>:', n);
200    } else if(x == 4 && y == 3) { // +L
201       slide(x, y, 1, 2, 1, n);
202       slide(x, y,-1, 2, 1, n);
203       slide(x, y, 2, 1, 1, n);
204       slide(x, y,-2, 1, 1, n);
205       slide_b(x, y, 1, n);
206       slide_s(x, y, 1, n);
207       slide_bd(x, y, 1, n);
208       text('Unicorn', '', n);
209    } else if(x == 5 && y == 6) { // +A
210       slide_orth(x, y, size, n);
211       slide_diag(x, y, size, n);
212       text('Queen', '', n);
213    } else if(x == 5 && y == 5) { // +H
214       slide_orth(x, y, size, n);
215       slide_n(x, y, 1, n);
216       text('Marshall', '', n);
217    } else if(x == 5 && y == 4) { // Q
218       slide_diag(x, y, size, n);
219       slide_n(x, y, 1, n);
220       text('Archbishop', '', n);
221    } else if(x == 5 && y == 3) {
222       slide(x, y, 1, 2, 1, n);
223       slide(x, y,-1, 2, 1, n);
224       slide(x, y, 2, 1, 1, n);
225       slide(x, y,-2, 1, 1, n);
226       slide_diag(x, y, 1, n);
227       slide_f(x, y, size, n);
228       slide_s(x, y, size, n);
229       slide_b(x, y, 1, n);
230       text('Colonel', '', n);
231    } else if(x == 6 && y == 6) { // B
232       slide_diag(x, y, size, n);
233       text('Bishop', '', n);
234    } else if(x == 6 && y == 5) { // dragon
235       slide_orth(x, y, 2, n);
236       text('Woody', '', n);
237    } else if(x == 6 && y == 4) { // horse
238       slide(x, y, 2, 0, 1, n);
239       slide(x, y,-2, 0, 1, n);
240       slide(x, y, 0,-2, 1, n);
241       slide(x, y, 0, 2, 1, n);
242       slide_diag(x, y, 2, n);
243       text('Clobberer', ': <i>Color bound</i><br>:<br>:', n);
244    } else if(x == 6 && y == 3) { // Ph
245       slide_b(x, y, 1, n);
246       slide_bd(x, y, 1, n);
247       slide_f(x, y, size, n);
248       slide_s(x, y, size, n);
249       text('Turret', '', n);
250    } else if(x == 7 && y == 6) { // Ph
251       slide_diag(x, y, 1, n);
252       slide_orth(x, y, 1, n);
253       text('King', '', n);
254    }
255 }
256
257 function down_click(x, y) {
258    if(!initDone) {
259       initDone = 1;
260       board = new Array();
261       for(i=0; i<12; i = i + 1) board[i] = new Array();
262       if(document.getElementById('sq0x0').innerHTML[1] == ' ') bw = 1;
263    }
264    if(down) return;
265    if(y < 0) {
266       y = -y; msg = 1;
267    } else msg = 0;
268    if(x < 0) {
269       x = -x; msg = msg + 2;
270    }
271    highlight(x, y, msg, 1);
272    savx = x; savy = y; down = 1;
273 //   save = document.getElementById(sq).innerHTML;
274 //   document.getElementById(sq).innerHTML = '<img src="sym/yellow.png">';
275 }
276
277 function up_click() {
278    highlight(savx, savy, msg, 0);
279    down = 0;
280 //   document.getElementById('sq' + x + 'x' + y).innerHTML = save;
281 }
282
283