summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2006-03-14 20:55:59 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2006-03-14 20:55:59 +0000
commit789e01bd069bc59b30d24534843090103e7df482 (patch)
tree02de519dc9f62b75700083d221c9a82949d3663d
parent258a693e95d81b0e149a3c9424c6c5c6aa8b2212 (diff)
downloadrockbox-789e01bd069bc59b30d24534843090103e7df482.tar.gz
rockbox-789e01bd069bc59b30d24534843090103e7df482.zip
latest update by Miguel Arevalo
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9037 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/chessbox/chessbox.c183
-rw-r--r--apps/plugins/chessbox/gnuchess.c16
-rw-r--r--apps/plugins/chessbox/gnuchess.h19
3 files changed, 181 insertions, 37 deletions
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c
index 2e863b957b..17b505001a 100644
--- a/apps/plugins/chessbox/chessbox.c
+++ b/apps/plugins/chessbox/chessbox.c
@@ -5,6 +5,7 @@
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/ 7* \/ \/ \/ \/ \/
8* $Id$
8* 9*
9* Copyright (C) 2006 Miguel A. Arévalo 10* Copyright (C) 2006 Miguel A. Arévalo
10* Color graphics from eboard 11* Color graphics from eboard
@@ -46,6 +47,7 @@ PLUGIN_HEADER
46#define CB_RIGHT BUTTON_RIGHT 47#define CB_RIGHT BUTTON_RIGHT
47#define CB_PLAY (BUTTON_SELECT | BUTTON_PLAY) 48#define CB_PLAY (BUTTON_SELECT | BUTTON_PLAY)
48#define CB_LEVEL (BUTTON_SELECT | BUTTON_RIGHT) 49#define CB_LEVEL (BUTTON_SELECT | BUTTON_RIGHT)
50#define CB_RESTART (BUTTON_SELECT | BUTTON_LEFT)
49#define CB_QUIT (BUTTON_SELECT | BUTTON_MENU) 51#define CB_QUIT (BUTTON_SELECT | BUTTON_MENU)
50 52
51#elif CONFIG_KEYPAD == IAUDIO_X5_PAD 53#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
@@ -56,6 +58,7 @@ PLUGIN_HEADER
56#define CB_RIGHT BUTTON_RIGHT 58#define CB_RIGHT BUTTON_RIGHT
57#define CB_PLAY BUTTON_PLAY 59#define CB_PLAY BUTTON_PLAY
58#define CB_LEVEL BUTTON_REC 60#define CB_LEVEL BUTTON_REC
61#define CB_RESTART BUTTON_SELECT
59#define CB_QUIT BUTTON_POWER 62#define CB_QUIT BUTTON_POWER
60 63
61#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) 64#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
@@ -66,6 +69,7 @@ PLUGIN_HEADER
66#define CB_RIGHT BUTTON_RIGHT 69#define CB_RIGHT BUTTON_RIGHT
67#define CB_PLAY BUTTON_ON 70#define CB_PLAY BUTTON_ON
68#define CB_LEVEL BUTTON_MODE 71#define CB_LEVEL BUTTON_MODE
72#define CB_RESTART BUTTON_REC
69#define CB_QUIT BUTTON_OFF 73#define CB_QUIT BUTTON_OFF
70 74
71#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD 75#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
@@ -138,14 +142,31 @@ PLUGIN_HEADER
138#define XOFS ((LCD_WIDTH-8*TILE_WIDTH)/2) 142#define XOFS ((LCD_WIDTH-8*TILE_WIDTH)/2)
139#define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2) 143#define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2)
140 144
145/* save files */
146#define SAVE_FILE PLUGIN_DIR "/chessbox.save"
147
141/* commands enum */ 148/* commands enum */
142#define COMMAND_NOP 0 149#define COMMAND_NOP 0
143#define COMMAND_MOVE 1 150#define COMMAND_MOVE 1
144#define COMMAND_PLAY 2 151#define COMMAND_PLAY 2
145#define COMMAND_LEVEL 3 152#define COMMAND_LEVEL 3
146/*#define COMMAND_RESTART 4*/ 153#ifdef CB_RESTART
154 #define COMMAND_RESTART 4
155#endif
147#define COMMAND_QUIT 5 156#define COMMAND_QUIT 5
148 157
158/* level+1's string */
159const char *level_string[] = { "Level 1: 60 moves / 5 min" ,
160 "Level 2: 60 moves / 15 min" ,
161 "Level 3: 60 moves / 30 min" ,
162 "Level 4: 40 moves / 30 min" ,
163 "Level 5: 40 moves / 60 min" ,
164 "Level 6: 40 moves / 120 min" ,
165 "Level 7: 40 moves / 240 min" ,
166 "Level 8: 1 move / 15 min" ,
167 "Level 9: 1 move / 60 min" ,
168 "Level 10: 1 move / 600 min" };
169
149/* "While thinking" command */ 170/* "While thinking" command */
150int wt_command = COMMAND_NOP; 171int wt_command = COMMAND_NOP;
151 172
@@ -262,69 +283,188 @@ void cb_wt_callback ( void ) {
262 } 283 }
263} 284}
264 285
265/* ---- increase playing level ---- */ 286/* ---- set playing parameters depending on level ---- */
266void cb_levelup ( void ) { 287void cb_setlevel ( int lev ) {
267 Level ++; 288 Level = (lev > 7) ? 7 : ( (lev < 1) ? 1 : lev ) ;
268 if ( Level == 8 ) Level = 1;
269 switch (Level) { 289 switch (Level) {
270 case 1 : 290 case 1 :
271 TCmoves = 60; 291 TCmoves = 60;
272 TCminutes = 5; 292 TCminutes = 5;
273 rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" );
274 break; 293 break;
275 case 2 : 294 case 2 :
276 TCmoves = 60; 295 TCmoves = 60;
277 TCminutes = 15; 296 TCminutes = 15;
278 rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" );
279 break; 297 break;
280 case 3 : 298 case 3 :
281 TCmoves = 60; 299 TCmoves = 60;
282 TCminutes = 30; 300 TCminutes = 30;
283 rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" );
284 break; 301 break;
285 case 4 : 302 case 4 :
286 TCmoves = 40; 303 TCmoves = 40;
287 TCminutes = 30; 304 TCminutes = 30;
288 rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" );
289 break; 305 break;
290 case 5 : 306 case 5 :
291 TCmoves = 40; 307 TCmoves = 40;
292 TCminutes = 60; 308 TCminutes = 60;
293 rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" );
294 break; 309 break;
295 case 6 : 310 case 6 :
296 TCmoves = 40; 311 TCmoves = 40;
297 TCminutes = 120; 312 TCminutes = 120;
298 rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" );
299 break; 313 break;
300 case 7 : 314 case 7 :
301 TCmoves = 40; 315 TCmoves = 40;
302 TCminutes = 240; 316 TCminutes = 240;
303 rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" );
304 break; 317 break;
305 case 8 : 318 case 8 :
306 TCmoves = 1; 319 TCmoves = 1;
307 TCminutes = 15; 320 TCminutes = 15;
308 rb->splash ( 50 , true , "Level 8: 1 move / 15 min" );
309 break; 321 break;
310 case 9 : 322 case 9 :
311 TCmoves = 1; 323 TCmoves = 1;
312 TCminutes = 60; 324 TCminutes = 60;
313 rb->splash ( 50 , true , "Level 9: 1 move / 60 min" );
314 break; 325 break;
315 case 10 : 326 case 10 :
316 TCmoves = 1; 327 TCmoves = 1;
317 TCminutes = 600; 328 TCminutes = 600;
318 rb->splash ( 50 , true , "Level 10: 1 move / 600 min" );
319 break; 329 break;
320 } 330 }
321 TCflag = (TCmoves > 1); 331 TCflag = (TCmoves > 1);
322 SetTimeControl(); 332 SetTimeControl();
333}
334
335/* ---- increase playing level ---- */
336void cb_levelup ( void ) {
337 if ( Level == 7 )
338 cb_setlevel ( 1 );
339 else
340 cb_setlevel ( Level+1 );
341 rb->splash ( 50 , true , level_string[Level-1] );
323}; 342};
324 343
344/* ---- Save current position ---- */
345void cb_saveposition ( void ) {
346 int fd;
347 short sq,i,c;
348 unsigned short temp;
349
350 rb->splash ( 0 , true , "Saving position" );
351
352 fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
353
354 computer++; rb->write(fd, &(computer), sizeof(computer)); computer--;
355 opponent++; rb->write(fd, &(opponent), sizeof(opponent)); opponent--;
356 rb->write(fd, &(Game50), sizeof(Game50));
357
358 rb->write(fd, &(castld[white]), sizeof(castld[white]));
359 rb->write(fd, &(castld[black]), sizeof(castld[black]));
360 rb->write(fd, &(kingmoved[white]), sizeof(kingmoved[white]));
361 rb->write(fd, &(kingmoved[black]), sizeof(kingmoved[black]));
362
363 rb->write(fd, &(Level), sizeof(Level));
364 rb->write(fd, &(TCflag), sizeof(TCflag));
365 rb->write(fd, &(OperatorTime), sizeof(OperatorTime));
366
367 rb->write(fd, &(TimeControl.clock[white]),
368 sizeof(TimeControl.clock[white]) );
369 rb->write(fd, &(TimeControl.clock[black]),
370 sizeof(TimeControl.clock[black]) );
371 rb->write(fd, &(TimeControl.moves[white]),
372 sizeof(TimeControl.moves[white]) );
373 rb->write(fd, &(TimeControl.moves[black]),
374 sizeof(TimeControl.moves[black]) );
375 for (sq = 0; sq < 64; sq++) {
376 if (color[sq] == neutral) c = 0; else c = color[sq]+1;
377 temp = 256*board[sq] + c ;
378 rb->write(fd, &(temp), sizeof(temp));
379 }
380 for (i = 0; i <= GameCnt; i++) {
381 if (GameList[i].color == neutral)
382 c = 0;
383 else
384 c = GameList[i].color + 1;
385 rb->write(fd, &(GameList[i].gmove), sizeof(GameList[i].gmove));
386 rb->write(fd, &(GameList[i].score), sizeof(GameList[i].score));
387 rb->write(fd, &(GameList[i].depth), sizeof(GameList[i].depth));
388 rb->write(fd, &(GameList[i].nodes), sizeof(GameList[i].nodes));
389 rb->write(fd, &(GameList[i].time), sizeof(GameList[i].time));
390 rb->write(fd, &(GameList[i].piece), sizeof(GameList[i].piece));
391 rb->write(fd, &(c), sizeof(c));
392 }
393 rb->close(fd);
394}
395
396/* ---- Restore saved position ---- */
397void cb_restoreposition ( void ) {
398 int fd;
399 int c;
400 short sq;
401 unsigned short m;
402
403 if ( (fd = rb->open(SAVE_FILE, O_RDONLY)) >= 0 ) {
404 rb->splash ( 0 , true , "Loading position" );
405 rb->read(fd, &(computer), sizeof(computer));
406 rb->read(fd, &(opponent), sizeof(opponent));
407 rb->read(fd, &(Game50), sizeof(Game50));
408
409 rb->read(fd, &(castld[white]), sizeof(castld[white]));
410 rb->read(fd, &(castld[black]), sizeof(castld[black]));
411 rb->read(fd, &(kingmoved[white]), sizeof(kingmoved[white]));
412 rb->read(fd, &(kingmoved[black]), sizeof(kingmoved[black]));
413
414 rb->read(fd, &(Level), sizeof(Level));
415 rb->read(fd, &(TCflag), sizeof(TCflag));
416 rb->read(fd, &(OperatorTime), sizeof(OperatorTime));
417
418 rb->read(fd, &(TimeControl.clock[white]),
419 sizeof(TimeControl.clock[white]));
420 rb->read(fd, &(TimeControl.clock[black]),
421 sizeof(TimeControl.clock[black]));
422 rb->read(fd, &(TimeControl.moves[white]),
423 sizeof(TimeControl.moves[white]));
424 rb->read(fd, &(TimeControl.moves[black]),
425 sizeof(TimeControl.moves[black]));
426 for (sq = 0; sq < 64; sq++) {
427 rb->read(fd, &(m), sizeof(m));
428 board[sq] = (m >> 8); color[sq] = (m & 0xFF);
429 if (color[sq] == 0)
430 color[sq] = neutral;
431 else
432 --color[sq];
433 }
434 GameCnt = -1; c = '?';
435 while (rb->read(fd, &(GameList[++GameCnt].gmove),
436 sizeof(GameList[GameCnt].gmove)) > 0) {
437 rb->read(fd, &(GameList[GameCnt].score),
438 sizeof(GameList[GameCnt].score));
439 rb->read(fd, &(GameList[GameCnt].depth),
440 sizeof(GameList[GameCnt].depth));
441 rb->read(fd, &(GameList[GameCnt].nodes),
442 sizeof(GameList[GameCnt].nodes));
443 rb->read(fd, &(GameList[GameCnt].time),
444 sizeof(GameList[GameCnt].time));
445 rb->read(fd, &(GameList[GameCnt].piece),
446 sizeof(GameList[GameCnt].piece));
447 rb->read(fd, &(GameList[GameCnt].color),
448 sizeof(GameList[GameCnt].color));
449 if (GameList[GameCnt].color == 0)
450 GameList[GameCnt].color = neutral;
451 else
452 --GameList[GameCnt].color;
453 }
454 GameCnt--;
455 if (TimeControl.clock[white] > 0)
456 TCflag = true;
457 computer--; opponent--;
458 }
459 rb->close(fd);
460 cb_setlevel(Level);
461 InitializeStats();
462 Sdepth = 0;
463}
464
325/* ---- main user loop ---- */ 465/* ---- main user loop ---- */
326struct cb_command cb_getcommand (void) { 466struct cb_command cb_getcommand (void) {
327 static short x = 4 , y = 4 ; 467 static short x = 4 , y = 3 ;
328 short c , r , l; 468 short c , r , l;
329 int button, lastbutton = BUTTON_NONE; 469 int button, lastbutton = BUTTON_NONE;
330 int marked = false , from_marked = false ; 470 int marked = false , from_marked = false ;
@@ -339,7 +479,7 @@ struct cb_command cb_getcommand (void) {
339 case CB_QUIT: 479 case CB_QUIT:
340 result.type = COMMAND_QUIT; 480 result.type = COMMAND_QUIT;
341 return result; 481 return result;
342#if 0 482#ifdef CB_RESTART
343 case CB_RESTART: 483 case CB_RESTART:
344 result.type = COMMAND_RESTART; 484 result.type = COMMAND_RESTART;
345 return result; 485 return result;
@@ -470,6 +610,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
470 /* init board */ 610 /* init board */
471 GNUChess_Initialize(); 611 GNUChess_Initialize();
472 612
613 /* restore saved position, if saved */
614 cb_restoreposition();
615
473 /* draw the board */ 616 /* draw the board */
474 /* I don't like configscreens, start game inmediatly */ 617 /* I don't like configscreens, start game inmediatly */
475 cb_drawboard(); 618 cb_drawboard();
@@ -504,7 +647,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
504 cb_drawboard(); 647 cb_drawboard();
505 } 648 }
506 break; 649 break;
507#if 0 650#ifdef COMMAND_RESTART
508 case COMMAND_RESTART: 651 case COMMAND_RESTART:
509 GNUChess_Initialize(); 652 GNUChess_Initialize();
510 cb_drawboard(); 653 cb_drawboard();
@@ -531,12 +674,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
531 cb_drawboard(); 674 cb_drawboard();
532 break; 675 break;
533 case COMMAND_QUIT: 676 case COMMAND_QUIT:
534 /*cb_saveposition();*/
535 exit = true; 677 exit = true;
536 break; 678 break;
537 } 679 }
538 } 680 }
539 681
682 cb_saveposition();
540 rb->lcd_setfont(FONT_UI); 683 rb->lcd_setfont(FONT_UI);
541 return PLUGIN_OK; 684 return PLUGIN_OK;
542} 685}
diff --git a/apps/plugins/chessbox/gnuchess.c b/apps/plugins/chessbox/gnuchess.c
index 9bd07c8eee..6ca579378f 100644
--- a/apps/plugins/chessbox/gnuchess.c
+++ b/apps/plugins/chessbox/gnuchess.c
@@ -32,9 +32,6 @@
32 32
33#define ttblsz 4096 33#define ttblsz 4096
34 34
35/*#define ttblsz 16384*/
36#define huge
37
38#define ctlP 0x4000 35#define ctlP 0x4000
39#define ctlN 0x2800 36#define ctlN 0x2800
40#define ctlB 0x1800 37#define ctlB 0x1800
@@ -74,17 +71,6 @@ struct leaf
74 short f,t,score,reply; 71 short f,t,score,reply;
75 unsigned short flags; 72 unsigned short flags;
76 }; 73 };
77struct GameRec
78 {
79 unsigned short gmove;
80 short score,depth,time,piece,color;
81 long nodes;
82 };
83struct TimeControlRec
84 {
85 short moves[2];
86 long clock[2];
87 };
88struct BookEntry 74struct BookEntry
89 { 75 {
90 struct BookEntry *next; 76 struct BookEntry *next;
@@ -182,7 +168,7 @@ unsigned short hashkey;
182unsigned long hashbd; 168unsigned long hashbd;
183struct hashval hashcode[2][7][64]; 169struct hashval hashcode[2][7][64];
184struct hashentry ttable[ttblsz]; 170struct hashentry ttable[ttblsz];
185struct hashentry huge *ptbl; 171struct hashentry *ptbl;
186unsigned char history[8192]; 172unsigned char history[8192];
187 173
188short Mwpawn[64],Mbpawn[64],Mknight[2][64],Mbishop[2][64]; 174short Mwpawn[64],Mbpawn[64],Mknight[2][64],Mbishop[2][64];
diff --git a/apps/plugins/chessbox/gnuchess.h b/apps/plugins/chessbox/gnuchess.h
index e94748919a..6be88aecfa 100644
--- a/apps/plugins/chessbox/gnuchess.h
+++ b/apps/plugins/chessbox/gnuchess.h
@@ -19,14 +19,28 @@
19#define valueQ 1100 19#define valueQ 1100
20#define valueK 1200 20#define valueK 1200
21 21
22/* ---- chess system global variables ---- */ 22/* ---- chess engine global types ---- */
23extern short mate,opponent,computer; 23struct GameRec {
24 unsigned short gmove;
25 short score,depth,time,piece,color;
26 long nodes;
27};
28struct TimeControlRec {
29 short moves[2];
30 long clock[2];
31};
32
33/* ---- chess engine global variables ---- */
34extern short mate,opponent,computer,Sdepth;
24extern short locn[8][8]; 35extern short locn[8][8];
25extern short board[64]; 36extern short board[64];
26extern short color[64]; 37extern short color[64];
27extern long Level; 38extern long Level;
28extern short TCflag,TCmoves,TCminutes; 39extern short TCflag,TCmoves,TCminutes;
29extern short timeout; 40extern short timeout;
41extern short GameCnt,Game50,castld[2],kingmoved[2],OperatorTime;
42extern struct TimeControlRec TimeControl;
43extern struct GameRec GameList[240];
30 44
31/* ---- RockBox integration ---- */ 45/* ---- RockBox integration ---- */
32extern struct plugin_api* rb; 46extern struct plugin_api* rb;
@@ -36,5 +50,6 @@ void SetTimeControl(void);
36void GNUChess_Initialize(void); 50void GNUChess_Initialize(void);
37int VerifyMove(char s[],short iop,unsigned short *mv); 51int VerifyMove(char s[],short iop,unsigned short *mv);
38int SelectMove ( short side, short iop , void (*callback)(void) ); 52int SelectMove ( short side, short iop , void (*callback)(void) );
53void InitializeStats ( void );
39 54
40#endif 55#endif