diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/chessbox/chessbox.c | 634 | ||||
-rw-r--r-- | apps/plugins/chessbox/gnuchess.c | 27 | ||||
-rw-r--r-- | apps/plugins/chessbox/gnuchess.h | 6 |
3 files changed, 350 insertions, 317 deletions
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c index 161de45e90..2e863b957b 100644 --- a/apps/plugins/chessbox/chessbox.c +++ b/apps/plugins/chessbox/chessbox.c | |||
@@ -26,9 +26,9 @@ | |||
26 | 26 | ||
27 | /* type definitions */ | 27 | /* type definitions */ |
28 | struct cb_command { | 28 | struct cb_command { |
29 | int type; | 29 | int type; |
30 | char mv_s[5]; | 30 | char mv_s[5]; |
31 | unsigned short mv; | 31 | unsigned short mv; |
32 | }; | 32 | }; |
33 | 33 | ||
34 | /* External bitmaps */ | 34 | /* External bitmaps */ |
@@ -131,7 +131,7 @@ PLUGIN_HEADER | |||
131 | #define TILE_WIDTH 8 | 131 | #define TILE_WIDTH 8 |
132 | #define TILE_HEIGHT 8 | 132 | #define TILE_HEIGHT 8 |
133 | #else | 133 | #else |
134 | #error BEJEWELED: Unsupported LCD | 134 | #error CHESSBOX: Unsupported LCD |
135 | #endif | 135 | #endif |
136 | 136 | ||
137 | /* Calculate Offsets */ | 137 | /* Calculate Offsets */ |
@@ -139,11 +139,15 @@ PLUGIN_HEADER | |||
139 | #define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2) | 139 | #define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2) |
140 | 140 | ||
141 | /* commands enum */ | 141 | /* commands enum */ |
142 | #define COMMAND_MOVE 1 | 142 | #define COMMAND_NOP 0 |
143 | #define COMMAND_PLAY 2 | 143 | #define COMMAND_MOVE 1 |
144 | #define COMMAND_LEVEL 3 | 144 | #define COMMAND_PLAY 2 |
145 | /*#define COMMAND_RESTART 4*/ | 145 | #define COMMAND_LEVEL 3 |
146 | #define COMMAND_QUIT 5 | 146 | /*#define COMMAND_RESTART 4*/ |
147 | #define COMMAND_QUIT 5 | ||
148 | |||
149 | /* "While thinking" command */ | ||
150 | int wt_command = COMMAND_NOP; | ||
147 | 151 | ||
148 | /* GCC wants this to be present for some targets */ | 152 | /* GCC wants this to be present for some targets */ |
149 | void* memcpy(void* dst, const void* src, size_t size) | 153 | void* memcpy(void* dst, const void* src, size_t size) |
@@ -153,278 +157,298 @@ void* memcpy(void* dst, const void* src, size_t size) | |||
153 | 157 | ||
154 | /* ---- Get the board column and row (e2 f.e.) for a physical x y ---- */ | 158 | /* ---- Get the board column and row (e2 f.e.) for a physical x y ---- */ |
155 | void xy2cr ( short x, short y, short *c, short *r ) { | 159 | void xy2cr ( short x, short y, short *c, short *r ) { |
156 | if (computer == black ) { | 160 | if (computer == black ) { |
157 | *c = x ; | 161 | *c = x ; |
158 | *r = y ; | 162 | *r = y ; |
159 | } else { | 163 | } else { |
160 | *c = 7 - x ; | 164 | *c = 7 - x ; |
161 | *r = 7 - y ; | 165 | *r = 7 - y ; |
162 | } | 166 | } |
163 | } | 167 | } |
164 | 168 | ||
165 | /* ---- get physical x y for a board column and row (e2 f.e.) ---- */ | 169 | /* ---- get physical x y for a board column and row (e2 f.e.) ---- */ |
166 | void cr2xy ( short c, short r, short *x, short *y ) { | 170 | void cr2xy ( short c, short r, short *x, short *y ) { |
167 | if ( computer == black ) { | 171 | if ( computer == black ) { |
168 | *x = c ; | 172 | *x = c ; |
169 | *y = r ; | 173 | *y = r ; |
170 | } else { | 174 | } else { |
171 | *x = 7 - c ; | 175 | *x = 7 - c ; |
172 | *y = 7 - r ; | 176 | *y = 7 - r ; |
173 | } | 177 | } |
174 | } | 178 | } |
175 | 179 | ||
176 | /* ---- Draw a complete board ---- */ | 180 | /* ---- Draw a complete board ---- */ |
177 | static void cb_drawboard (void) { | 181 | static void cb_drawboard (void) { |
178 | short r , c , x , y ; | 182 | short r , c , x , y ; |
179 | short l , piece , p_color ; | 183 | short l , piece , p_color ; |
180 | int b_color=1; | 184 | int b_color=1; |
181 | 185 | ||
182 | rb->lcd_clear_display(); | 186 | rb->lcd_clear_display(); |
183 | 187 | ||
184 | for (r = 0; r < 8; r++) { | 188 | for (r = 0; r < 8; r++) { |
185 | for (c = 0; c < 8; c++) { | 189 | for (c = 0; c < 8; c++) { |
186 | l = locn[r][c]; | 190 | l = locn[r][c]; |
187 | piece = board[l] ; | 191 | piece = board[l] ; |
188 | p_color = color[l] ; | 192 | p_color = color[l] ; |
189 | cr2xy ( c , r , &x , &y ); | 193 | cr2xy ( c , r , &x , &y ); |
190 | if ( piece == no_piece ) { | 194 | if ( piece == no_piece ) { |
191 | rb->lcd_bitmap_part ( chessbox_pieces , 0 , | 195 | rb->lcd_bitmap_part ( chessbox_pieces , 0 , |
192 | TILE_HEIGHT * b_color , | 196 | TILE_HEIGHT * b_color , |
193 | TILE_WIDTH , | 197 | TILE_WIDTH , |
194 | XOFS + x*TILE_WIDTH , | 198 | XOFS + x*TILE_WIDTH , |
195 | YOFS + ( 7 - y )*TILE_HEIGHT , | 199 | YOFS + ( 7 - y )*TILE_HEIGHT , |
196 | TILE_WIDTH , | 200 | TILE_WIDTH , |
197 | TILE_HEIGHT ); | 201 | TILE_HEIGHT ); |
198 | } else { | 202 | } else { |
199 | rb->lcd_bitmap_part ( chessbox_pieces , | 203 | rb->lcd_bitmap_part ( chessbox_pieces , |
200 | 0 , | 204 | 0 , |
201 | 2 * TILE_HEIGHT + | 205 | 2 * TILE_HEIGHT + |
202 | 4 * TILE_HEIGHT * ( piece - 1 ) + | 206 | 4 * TILE_HEIGHT * ( piece - 1 ) + |
203 | 2 * TILE_HEIGHT * p_color + | 207 | 2 * TILE_HEIGHT * p_color + |
204 | TILE_HEIGHT * b_color , | 208 | TILE_HEIGHT * b_color , |
205 | TILE_WIDTH , | 209 | TILE_WIDTH , |
206 | XOFS + x*TILE_WIDTH , | 210 | XOFS + x*TILE_WIDTH , |
207 | YOFS + (7 - y)*TILE_HEIGHT , | 211 | YOFS + (7 - y)*TILE_HEIGHT , |
208 | TILE_WIDTH , | 212 | TILE_WIDTH , |
209 | TILE_HEIGHT ); | 213 | TILE_HEIGHT ); |
210 | } | 214 | } |
211 | b_color = (b_color == 1) ? 0 : 1 ; | 215 | b_color = (b_color == 1) ? 0 : 1 ; |
212 | } | 216 | } |
213 | b_color = (b_color == 1) ? 0 : 1 ; | 217 | b_color = (b_color == 1) ? 0 : 1 ; |
218 | } | ||
219 | |||
220 | /* draw board limits */ | ||
221 | if ( LCD_WIDTH > TILE_WIDTH*8 ) { | ||
222 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
223 | rb->lcd_drawline ( XOFS - 1 , YOFS , | ||
224 | XOFS - 1 , YOFS + TILE_HEIGHT*8 ); | ||
225 | rb->lcd_drawline ( XOFS + 8*TILE_WIDTH , YOFS , | ||
226 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
227 | } | ||
228 | if ( LCD_HEIGHT > TILE_HEIGHT*8 ) { | ||
229 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
230 | rb->lcd_drawline ( XOFS , YOFS - 1 , | ||
231 | XOFS + TILE_WIDTH*8 , YOFS - 1 ); | ||
232 | rb->lcd_drawline ( XOFS , YOFS + TILE_HEIGHT*8 , | ||
233 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
214 | } | 234 | } |
215 | 235 | rb->lcd_update(); | |
216 | /* draw board limits */ | ||
217 | if ( LCD_WIDTH > TILE_WIDTH*8 ) { | ||
218 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
219 | rb->lcd_drawline ( XOFS - 1 , YOFS , | ||
220 | XOFS - 1 , YOFS + TILE_HEIGHT*8 ); | ||
221 | rb->lcd_drawline ( XOFS + 8*TILE_WIDTH , YOFS , | ||
222 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
223 | } | ||
224 | if ( LCD_HEIGHT > TILE_HEIGHT*8 ) { | ||
225 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
226 | rb->lcd_drawline ( XOFS , YOFS - 1 , | ||
227 | XOFS + TILE_WIDTH*8 , YOFS - 1 ); | ||
228 | rb->lcd_drawline ( XOFS , YOFS + TILE_HEIGHT*8 , | ||
229 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
230 | } | ||
231 | rb->lcd_update(); | ||
232 | } | 236 | } |
233 | 237 | ||
234 | /* ---- Switch mark on board ---- */ | 238 | /* ---- Switch mark on board ---- */ |
235 | void cb_switch ( short x , short y ) { | 239 | void cb_switch ( short x , short y ) { |
236 | rb->lcd_set_drawmode ( DRMODE_COMPLEMENT ); | 240 | rb->lcd_set_drawmode ( DRMODE_COMPLEMENT ); |
237 | rb->lcd_drawrect ( XOFS + x*TILE_WIDTH + 1 , | 241 | rb->lcd_drawrect ( XOFS + x*TILE_WIDTH + 1 , |
238 | YOFS + ( 7 - y )*TILE_HEIGHT +1 , | 242 | YOFS + ( 7 - y )*TILE_HEIGHT +1 , |
239 | TILE_WIDTH-2 , TILE_HEIGHT-2 ); | 243 | TILE_WIDTH-2 , TILE_HEIGHT-2 ); |
240 | rb->lcd_update(); | 244 | rb->lcd_update(); |
245 | } | ||
246 | |||
247 | /* ---- callback for capturing interaction while thinking ---- */ | ||
248 | void cb_wt_callback ( void ) { | ||
249 | int button = BUTTON_NONE; | ||
250 | |||
251 | wt_command = COMMAND_NOP; | ||
252 | button = rb->button_get(false); | ||
253 | switch (button) { | ||
254 | case CB_QUIT: | ||
255 | wt_command = COMMAND_QUIT; | ||
256 | timeout = true; | ||
257 | break; | ||
258 | case CB_PLAY: | ||
259 | wt_command = COMMAND_PLAY; | ||
260 | timeout = true; | ||
261 | break; | ||
262 | } | ||
241 | } | 263 | } |
242 | 264 | ||
243 | /* ---- increase playing level ---- */ | 265 | /* ---- increase playing level ---- */ |
244 | void cb_levelup ( void ) { | 266 | void cb_levelup ( void ) { |
245 | Level ++; | 267 | Level ++; |
246 | if ( Level == 8 ) Level = 1; | 268 | if ( Level == 8 ) Level = 1; |
247 | switch (Level) { | 269 | switch (Level) { |
248 | case 1 : | 270 | case 1 : |
249 | TCmoves = 60; | 271 | TCmoves = 60; |
250 | TCminutes = 5; | 272 | TCminutes = 5; |
251 | rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" ); | 273 | rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" ); |
252 | break; | 274 | break; |
253 | case 2 : | 275 | case 2 : |
254 | TCmoves = 60; | 276 | TCmoves = 60; |
255 | TCminutes = 15; | 277 | TCminutes = 15; |
256 | rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" ); | 278 | rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" ); |
257 | break; | 279 | break; |
258 | case 3 : | 280 | case 3 : |
259 | TCmoves = 60; | 281 | TCmoves = 60; |
260 | TCminutes = 30; | 282 | TCminutes = 30; |
261 | rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" ); | 283 | rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" ); |
262 | break; | 284 | break; |
263 | case 4 : | 285 | case 4 : |
264 | TCmoves = 40; | 286 | TCmoves = 40; |
265 | TCminutes = 30; | 287 | TCminutes = 30; |
266 | rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" ); | 288 | rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" ); |
267 | break; | 289 | break; |
268 | case 5 : | 290 | case 5 : |
269 | TCmoves = 40; | 291 | TCmoves = 40; |
270 | TCminutes = 60; | 292 | TCminutes = 60; |
271 | rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" ); | 293 | rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" ); |
272 | break; | 294 | break; |
273 | case 6 : | 295 | case 6 : |
274 | TCmoves = 40; | 296 | TCmoves = 40; |
275 | TCminutes = 120; | 297 | TCminutes = 120; |
276 | rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" ); | 298 | rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" ); |
277 | break; | 299 | break; |
278 | case 7 : | 300 | case 7 : |
279 | TCmoves = 40; | 301 | TCmoves = 40; |
280 | TCminutes = 240; | 302 | TCminutes = 240; |
281 | rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" ); | 303 | rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" ); |
282 | break; | 304 | break; |
283 | case 8 : | 305 | case 8 : |
284 | TCmoves = 1; | 306 | TCmoves = 1; |
285 | TCminutes = 15; | 307 | TCminutes = 15; |
286 | rb->splash ( 50 , true , "Level 8: 1 move / 15 min" ); | 308 | rb->splash ( 50 , true , "Level 8: 1 move / 15 min" ); |
287 | break; | 309 | break; |
288 | case 9 : | 310 | case 9 : |
289 | TCmoves = 1; | 311 | TCmoves = 1; |
290 | TCminutes = 60; | 312 | TCminutes = 60; |
291 | rb->splash ( 50 , true , "Level 9: 1 move / 60 min" ); | 313 | rb->splash ( 50 , true , "Level 9: 1 move / 60 min" ); |
292 | break; | 314 | break; |
293 | case 10 : | 315 | case 10 : |
294 | TCmoves = 1; | 316 | TCmoves = 1; |
295 | TCminutes = 600; | 317 | TCminutes = 600; |
296 | rb->splash ( 50 , true , "Level 10: 1 move / 600 min" ); | 318 | rb->splash ( 50 , true , "Level 10: 1 move / 600 min" ); |
297 | break; | 319 | break; |
298 | } | 320 | } |
299 | TCflag = (TCmoves > 1); | 321 | TCflag = (TCmoves > 1); |
300 | SetTimeControl(); | 322 | SetTimeControl(); |
301 | }; | 323 | }; |
302 | 324 | ||
303 | /* ---- main user loop ---- */ | 325 | /* ---- main user loop ---- */ |
304 | struct cb_command cb_getcommand (void) { | 326 | struct cb_command cb_getcommand (void) { |
305 | static short x = 4 , y = 4 ; | 327 | static short x = 4 , y = 4 ; |
306 | short c , r , l; | 328 | short c , r , l; |
307 | int button, lastbutton = BUTTON_NONE; | 329 | int button, lastbutton = BUTTON_NONE; |
308 | int marked = false , from_marked = false ; | 330 | int marked = false , from_marked = false ; |
309 | short marked_x = 0 , marked_y = 0 ; | 331 | short marked_x = 0 , marked_y = 0 ; |
310 | struct cb_command result = { 0, {0,0,0,0,0}, 0 }; | 332 | struct cb_command result = { 0, {0,0,0,0,0}, 0 }; |
311 | 333 | ||
312 | cb_switch ( x , y ); | 334 | cb_switch ( x , y ); |
313 | /* main loop */ | 335 | /* main loop */ |
314 | while ( true ) { | 336 | while ( true ) { |
315 | button = rb->button_get(true); | 337 | button = rb->button_get(true); |
316 | switch (button) { | 338 | switch (button) { |
317 | case CB_QUIT: | 339 | case CB_QUIT: |
318 | result.type = COMMAND_QUIT; | 340 | result.type = COMMAND_QUIT; |
319 | return result; | 341 | return result; |
320 | /* case CB_RESTART: | 342 | #if 0 |
321 | result.type = COMMAND_RESTART; | 343 | case CB_RESTART: |
322 | return result;*/ | 344 | result.type = COMMAND_RESTART; |
323 | case CB_LEVEL: | 345 | return result; |
324 | result.type = COMMAND_LEVEL; | 346 | #endif |
325 | return result; | 347 | case CB_LEVEL: |
326 | case CB_PLAY: | 348 | result.type = COMMAND_LEVEL; |
349 | return result; | ||
350 | case CB_PLAY: | ||
327 | #ifdef CB_PLAY_PRE | 351 | #ifdef CB_PLAY_PRE |
328 | if (lastbutton != CB_PLAY_PRE) | 352 | if (lastbutton != CB_PLAY_PRE) |
329 | break; | 353 | break; |
330 | #endif | 354 | #endif |
331 | result.type = COMMAND_PLAY; | 355 | result.type = COMMAND_PLAY; |
332 | return result; | 356 | return result; |
333 | case CB_UP: | 357 | case CB_UP: |
334 | if ( !from_marked ) cb_switch ( x , y ); | 358 | if ( !from_marked ) cb_switch ( x , y ); |
335 | y++; | 359 | y++; |
336 | if ( y == 8 ) { | 360 | if ( y == 8 ) { |
337 | y = 0; | 361 | y = 0; |
338 | x--; | 362 | x--; |
339 | if ( x < 0 ) x = 7; | 363 | if ( x < 0 ) x = 7; |
340 | } | 364 | } |
341 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 365 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
342 | from_marked = true ; | 366 | from_marked = true ; |
343 | } else { | 367 | } else { |
344 | from_marked = false ; | 368 | from_marked = false ; |
345 | cb_switch ( x , y ); | 369 | cb_switch ( x , y ); |
346 | } | 370 | } |
347 | break; | 371 | break; |
348 | case CB_DOWN: | 372 | case CB_DOWN: |
349 | if ( !from_marked ) cb_switch ( x , y ); | 373 | if ( !from_marked ) cb_switch ( x , y ); |
350 | y--; | 374 | y--; |
351 | if ( y < 0 ) { | 375 | if ( y < 0 ) { |
352 | y = 7; | 376 | y = 7; |
353 | x++; | 377 | x++; |
354 | if ( x == 8 ) x = 0; | 378 | if ( x == 8 ) x = 0; |
355 | } | 379 | } |
356 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 380 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
357 | from_marked = true ; | 381 | from_marked = true ; |
358 | } else { | 382 | } else { |
359 | from_marked = false ; | 383 | from_marked = false ; |
360 | cb_switch ( x , y ); | 384 | cb_switch ( x , y ); |
361 | } | 385 | } |
362 | break; | 386 | break; |
363 | case CB_LEFT: | 387 | case CB_LEFT: |
364 | if ( !from_marked ) cb_switch ( x , y ); | 388 | if ( !from_marked ) cb_switch ( x , y ); |
365 | x--; | 389 | x--; |
366 | if ( x < 0 ) { | 390 | if ( x < 0 ) { |
367 | x = 7; | 391 | x = 7; |
368 | y++; | 392 | y++; |
369 | if ( y == 8 ) y = 0; | 393 | if ( y == 8 ) y = 0; |
370 | } | 394 | } |
371 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 395 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
372 | from_marked = true ; | 396 | from_marked = true ; |
373 | } else { | 397 | } else { |
374 | from_marked = false ; | 398 | from_marked = false ; |
375 | cb_switch ( x , y ); | 399 | cb_switch ( x , y ); |
376 | } | 400 | } |
377 | break; | 401 | break; |
378 | case CB_RIGHT: | 402 | case CB_RIGHT: |
379 | if ( !from_marked ) cb_switch ( x , y ); | 403 | if ( !from_marked ) cb_switch ( x , y ); |
380 | x++; | 404 | x++; |
381 | if ( x == 8 ) { | 405 | if ( x == 8 ) { |
382 | x = 0; | 406 | x = 0; |
383 | y--; | 407 | y--; |
384 | if ( y < 0 ) y = 7; | 408 | if ( y < 0 ) y = 7; |
385 | } | 409 | } |
386 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 410 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
387 | from_marked = true ; | 411 | from_marked = true ; |
388 | } else { | 412 | } else { |
389 | from_marked = false ; | 413 | from_marked = false ; |
390 | cb_switch ( x , y ); | 414 | cb_switch ( x , y ); |
391 | } | 415 | } |
392 | break; | 416 | break; |
393 | case CB_SELECT: | 417 | case CB_SELECT: |
394 | #ifdef CB_SELECT_PRE | 418 | #ifdef CB_SELECT_PRE |
395 | if (lastbutton != CB_SELECT_PRE) | 419 | if (lastbutton != CB_SELECT_PRE) |
396 | break; | 420 | break; |
397 | #endif | 421 | #endif |
398 | if ( !marked ) { | 422 | if ( !marked ) { |
399 | xy2cr ( x , y , &c , &r ); | 423 | xy2cr ( x , y , &c , &r ); |
400 | l = locn[r][c]; | 424 | l = locn[r][c]; |
401 | if ( ( color[l]!=computer ) && ( board[l]!=no_piece ) ) { | 425 | if ( ( color[l]!=computer ) && ( board[l]!=no_piece ) ) { |
402 | marked = true; | 426 | marked = true; |
403 | from_marked = true ; | 427 | from_marked = true ; |
404 | marked_x = x; | 428 | marked_x = x; |
405 | marked_y = y; | 429 | marked_y = y; |
406 | } | 430 | } |
407 | } else { | 431 | } else { |
408 | if ( ( marked_x == x ) && ( marked_y == y ) ) { | 432 | if ( ( marked_x == x ) && ( marked_y == y ) ) { |
409 | marked = false; | 433 | marked = false; |
410 | from_marked = false; | 434 | from_marked = false; |
411 | } else { | 435 | } else { |
412 | xy2cr ( marked_x , marked_y , &c , &r ); | 436 | xy2cr ( marked_x , marked_y , &c , &r ); |
413 | result.mv_s[0] = 'a' + c; | 437 | result.mv_s[0] = 'a' + c; |
414 | result.mv_s[1] = '1' + r; | 438 | result.mv_s[1] = '1' + r; |
415 | xy2cr ( x , y , &c , &r ); | 439 | xy2cr ( x , y , &c , &r ); |
416 | result.mv_s[2] = 'a' + c; | 440 | result.mv_s[2] = 'a' + c; |
417 | result.mv_s[3] = '1' + r; | 441 | result.mv_s[3] = '1' + r; |
418 | result.mv_s[4] = '\00'; | 442 | result.mv_s[4] = '\00'; |
419 | result.type = COMMAND_MOVE; | 443 | result.type = COMMAND_MOVE; |
420 | return result; | 444 | return result; |
421 | } | 445 | } |
422 | } | 446 | } |
423 | break; | 447 | break; |
424 | } | 448 | } |
425 | if (button != BUTTON_NONE) | 449 | if (button != BUTTON_NONE) |
426 | lastbutton = button; | 450 | lastbutton = button; |
427 | } | 451 | } |
428 | 452 | ||
429 | } | 453 | } |
430 | 454 | ||
@@ -432,77 +456,87 @@ struct cb_command cb_getcommand (void) { | |||
432 | * plugin entry point. | 456 | * plugin entry point. |
433 | ******************************************************************************/ | 457 | ******************************************************************************/ |
434 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { | 458 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { |
435 | struct cb_command command; | 459 | struct cb_command command; |
436 | /* init status */ | 460 | /* init status */ |
437 | bool exit = false; | 461 | bool exit = false; |
438 | 462 | ||
439 | /* plugin init */ | 463 | /* plugin init */ |
440 | (void)parameter; | 464 | (void)parameter; |
441 | rb = api; | 465 | rb = api; |
442 | /* end of plugin init */ | 466 | /* end of plugin init */ |
443 | 467 | ||
444 | /* load opening book, soon */ | 468 | /* load opening book, soon */ |
445 | 469 | ||
446 | /* init board */ | 470 | /* init board */ |
447 | GNUChess_Initialize(); | 471 | GNUChess_Initialize(); |
448 | 472 | ||
449 | /* draw the board */ | 473 | /* draw the board */ |
450 | /* I don't like configscreens, start game inmediatly */ | 474 | /* I don't like configscreens, start game inmediatly */ |
451 | cb_drawboard(); | 475 | cb_drawboard(); |
452 | 476 | ||
453 | while (!exit) { | 477 | while (!exit) { |
454 | if ( mate ) { | 478 | if ( mate ) { |
455 | rb->splash ( 500 , true , "Checkmate!" ); | 479 | rb->splash ( 500 , true , "Checkmate!" ); |
456 | rb->button_get(true); | 480 | rb->button_get(true); |
457 | GNUChess_Initialize(); | 481 | GNUChess_Initialize(); |
458 | cb_drawboard(); | 482 | cb_drawboard(); |
459 | } | 483 | } |
460 | command = cb_getcommand (); | 484 | command = cb_getcommand (); |
461 | switch (command.type) { | 485 | switch (command.type) { |
462 | case COMMAND_MOVE: | 486 | case COMMAND_MOVE: |
463 | if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) { | 487 | if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) { |
464 | rb->splash ( 50 , true , "Illegal move!" ); | 488 | rb->splash ( 50 , true , "Illegal move!" ); |
465 | cb_drawboard(); | 489 | cb_drawboard(); |
466 | } else { | 490 | } else { |
467 | cb_drawboard(); | 491 | cb_drawboard(); |
468 | rb->splash ( 0 , true , "Thinking..." ); | 492 | rb->splash ( 0 , true , "Thinking..." ); |
469 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 493 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
470 | rb->cpu_boost ( true ); | 494 | rb->cpu_boost ( true ); |
471 | #endif | 495 | #endif |
472 | SelectMove ( computer , 0 ); | 496 | SelectMove ( computer , 0 , cb_wt_callback ); |
473 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 497 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
474 | rb->cpu_boost ( false ); | 498 | rb->cpu_boost ( false ); |
475 | #endif | 499 | #endif |
476 | cb_drawboard(); | 500 | if ( wt_command == COMMAND_QUIT ) { |
477 | } | 501 | exit = true; |
478 | break; | 502 | break; |
479 | /* case COMMAND_RESTART: | 503 | } |
480 | GNUChess_Initialize(); | 504 | cb_drawboard(); |
481 | cb_drawboard(); | 505 | } |
482 | break;*/ | 506 | break; |
483 | case COMMAND_PLAY: | 507 | #if 0 |
484 | opponent = !opponent; computer = !computer; | 508 | case COMMAND_RESTART: |
485 | rb->splash ( 0 , true , "Thinking..." ); | 509 | GNUChess_Initialize(); |
510 | cb_drawboard(); | ||
511 | break; | ||
512 | #endif | ||
513 | case COMMAND_PLAY: | ||
514 | opponent = !opponent; computer = !computer; | ||
515 | rb->splash ( 0 , true , "Thinking..." ); | ||
486 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 516 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
487 | rb->cpu_boost ( true ); | 517 | rb->cpu_boost ( true ); |
488 | #endif | 518 | #endif |
489 | SelectMove ( computer , 0 ); | 519 | SelectMove ( computer , 0 , cb_wt_callback ); |
490 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 520 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
491 | rb->cpu_boost ( false ); | 521 | rb->cpu_boost ( false ); |
492 | #endif | 522 | #endif |
493 | cb_drawboard(); | 523 | if ( wt_command == COMMAND_QUIT ) { |
494 | break; | 524 | exit = true; |
495 | case COMMAND_LEVEL: | 525 | break; |
496 | cb_levelup ( ); | 526 | } |
497 | cb_drawboard(); | 527 | cb_drawboard(); |
498 | break; | 528 | break; |
499 | case COMMAND_QUIT: | 529 | case COMMAND_LEVEL: |
500 | /*cb_saveposition();*/ | 530 | cb_levelup ( ); |
501 | exit = true; | 531 | cb_drawboard(); |
502 | break; | 532 | break; |
503 | } | 533 | case COMMAND_QUIT: |
504 | } | 534 | /*cb_saveposition();*/ |
505 | 535 | exit = true; | |
536 | break; | ||
537 | } | ||
538 | } | ||
539 | |||
506 | rb->lcd_setfont(FONT_UI); | 540 | rb->lcd_setfont(FONT_UI); |
507 | return PLUGIN_OK; | 541 | return PLUGIN_OK; |
508 | } | 542 | } |
diff --git a/apps/plugins/chessbox/gnuchess.c b/apps/plugins/chessbox/gnuchess.c index 879c083ce7..9bd07c8eee 100644 --- a/apps/plugins/chessbox/gnuchess.c +++ b/apps/plugins/chessbox/gnuchess.c | |||
@@ -279,7 +279,8 @@ void CopyBoard( short a[64] , short b[64] ); | |||
279 | void OpeningBook ( void ); | 279 | void OpeningBook ( void ); |
280 | int search ( short side, short ply, short depth, | 280 | int search ( short side, short ply, short depth, |
281 | short alpha, short beta, | 281 | short alpha, short beta, |
282 | unsigned short bstline[], short *rpt ); | 282 | unsigned short bstline[], short *rpt, |
283 | void (*callback)(void) ); | ||
283 | int evaluate ( short side, short xside, short ply, short depth, | 284 | int evaluate ( short side, short xside, short ply, short depth, |
284 | short alpha, short beta ); | 285 | short alpha, short beta ); |
285 | int ProbeTTable ( short side, short depth, | 286 | int ProbeTTable ( short side, short depth, |
@@ -333,9 +334,6 @@ short pscore[3]; | |||
333 | xside = otherside[side]; | 334 | xside = otherside[side]; |
334 | pscore[white] = pscore[black] = 0; | 335 | pscore[white] = pscore[black] = 0; |
335 | 336 | ||
336 | /* ok, I will yield here for lower levels */ | ||
337 | rb->yield(); | ||
338 | |||
339 | for (c1 = white; c1 <= black; c1++) | 337 | for (c1 = white; c1 <= black; c1++) |
340 | { | 338 | { |
341 | c2 = otherside[c1]; | 339 | c2 = otherside[c1]; |
@@ -1018,8 +1016,7 @@ register int sq; | |||
1018 | /* ............ MOVE GENERATION & SEARCH ROUTINES .............. */ | 1016 | /* ............ MOVE GENERATION & SEARCH ROUTINES .............. */ |
1019 | 1017 | ||
1020 | 1018 | ||
1021 | int SelectMove(side,iop) | 1019 | int SelectMove( short side, short iop , void (*callback)(void)) |
1022 | short side,iop; | ||
1023 | 1020 | ||
1024 | /* | 1021 | /* |
1025 | Select a move by calling function search() at progressively deeper | 1022 | Select a move by calling function search() at progressively deeper |
@@ -1078,21 +1075,21 @@ static short i,alpha,beta,score,tempb,tempc,tempsf,tempst,xside,rpt; | |||
1078 | { | 1075 | { |
1079 | Sdepth++; | 1076 | Sdepth++; |
1080 | /*ShowDepth(' ');*/ | 1077 | /*ShowDepth(' ');*/ |
1081 | score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt); | 1078 | score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt,callback); |
1082 | for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i]; | 1079 | for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i]; |
1083 | if (score < alpha && !timeout) | 1080 | if (score < alpha && !timeout) |
1084 | { | 1081 | { |
1085 | /*ShowDepth('-');*/ | 1082 | /*ShowDepth('-');*/ |
1086 | ExtraTime = 10*ResponseTime; | 1083 | ExtraTime = 10*ResponseTime; |
1087 | ZeroTTable(); | 1084 | ZeroTTable(); |
1088 | score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt); | 1085 | score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt,callback); |
1089 | } | 1086 | } |
1090 | if (score > beta && !timeout && !(root->flags & exact)) | 1087 | if (score > beta && !timeout && !(root->flags & exact)) |
1091 | { | 1088 | { |
1092 | /*ShowDepth('+');*/ | 1089 | /*ShowDepth('+');*/ |
1093 | ExtraTime = 0; | 1090 | ExtraTime = 0; |
1094 | ZeroTTable(); | 1091 | ZeroTTable(); |
1095 | score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt); | 1092 | score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt,callback); |
1096 | } | 1093 | } |
1097 | score = root->score; | 1094 | score = root->score; |
1098 | if (!timeout) | 1095 | if (!timeout) |
@@ -1209,9 +1206,9 @@ struct BookEntry *p; | |||
1209 | }\ | 1206 | }\ |
1210 | } | 1207 | } |
1211 | 1208 | ||
1212 | int search(side,ply,depth,alpha,beta,bstline,rpt) | 1209 | int search( short side, short ply, short depth, |
1213 | short side,ply,depth,alpha,beta,*rpt; | 1210 | short alpha, short beta, unsigned short bstline[], short *rpt, |
1214 | unsigned short bstline[]; | 1211 | void (*callback)(void) ) |
1215 | 1212 | ||
1216 | /* | 1213 | /* |
1217 | Perform an alpha-beta search to determine the score for the current | 1214 | Perform an alpha-beta search to determine the score for the current |
@@ -1238,8 +1235,10 @@ short xside,pbst,d,e,cf,score,rcnt; | |||
1238 | unsigned short mv,nxtline[maxdepth]; | 1235 | unsigned short mv,nxtline[maxdepth]; |
1239 | struct leaf *node,tmp; | 1236 | struct leaf *node,tmp; |
1240 | 1237 | ||
1241 | /* ok, I will yield here for higher levels */ | 1238 | /* this is the only place we need to yield */ |
1242 | rb->yield(); | 1239 | rb->yield(); |
1240 | /* and check for user interaction */ | ||
1241 | callback(); | ||
1243 | 1242 | ||
1244 | NodeCnt++; | 1243 | NodeCnt++; |
1245 | xside = otherside[side]; | 1244 | xside = otherside[side]; |
@@ -1308,7 +1307,7 @@ struct leaf *node,tmp; | |||
1308 | PawnThreat[ply] = (node->flags & pwnthrt); | 1307 | PawnThreat[ply] = (node->flags & pwnthrt); |
1309 | Tscore[ply] = node->score; | 1308 | Tscore[ply] = node->score; |
1310 | node->score = -search(xside,ply+1,depth-1,-beta,-alpha, | 1309 | node->score = -search(xside,ply+1,depth-1,-beta,-alpha, |
1311 | nxtline,&rcnt); | 1310 | nxtline,&rcnt,callback); |
1312 | if (abs(node->score) > 9000) node->flags |= exact; | 1311 | if (abs(node->score) > 9000) node->flags |= exact; |
1313 | else if (rcnt == 1) node->score /= 2; | 1312 | else if (rcnt == 1) node->score /= 2; |
1314 | if (rcnt >= 2 || GameCnt-Game50 > 99 || | 1313 | if (rcnt >= 2 || GameCnt-Game50 > 99 || |
diff --git a/apps/plugins/chessbox/gnuchess.h b/apps/plugins/chessbox/gnuchess.h index 68ef9f9a81..e94748919a 100644 --- a/apps/plugins/chessbox/gnuchess.h +++ b/apps/plugins/chessbox/gnuchess.h | |||
@@ -26,6 +26,7 @@ extern short board[64]; | |||
26 | extern short color[64]; | 26 | extern short color[64]; |
27 | extern long Level; | 27 | extern long Level; |
28 | extern short TCflag,TCmoves,TCminutes; | 28 | extern short TCflag,TCmoves,TCminutes; |
29 | extern short timeout; | ||
29 | 30 | ||
30 | /* ---- RockBox integration ---- */ | 31 | /* ---- RockBox integration ---- */ |
31 | extern struct plugin_api* rb; | 32 | extern struct plugin_api* rb; |
@@ -33,8 +34,7 @@ extern struct plugin_api* rb; | |||
33 | /* ---- The beginning of a GNUChess v2 APIfication ---- */ | 34 | /* ---- The beginning of a GNUChess v2 APIfication ---- */ |
34 | void SetTimeControl(void); | 35 | void SetTimeControl(void); |
35 | void GNUChess_Initialize(void); | 36 | void GNUChess_Initialize(void); |
36 | int VerifyMove(char s[],short iop,unsigned short *mv); | 37 | int VerifyMove(char s[],short iop,unsigned short *mv); |
37 | int SelectMove ( short side, short iop); | 38 | int SelectMove ( short side, short iop , void (*callback)(void) ); |
38 | |||
39 | 39 | ||
40 | #endif | 40 | #endif |