summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/chessbox/chessbox.c634
-rw-r--r--apps/plugins/chessbox/gnuchess.c27
-rw-r--r--apps/plugins/chessbox/gnuchess.h6
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 @@
/* type definitions */
struct cb_command {
- int type;
- char mv_s[5];
- unsigned short mv;
+ int type;
+ char mv_s[5];
+ unsigned short mv;
};
/* External bitmaps */
@@ -131,7 +131,7 @@ PLUGIN_HEADER
#define TILE_WIDTH 8
#define TILE_HEIGHT 8
#else
- #error BEJEWELED: Unsupported LCD
+ #error CHESSBOX: Unsupported LCD
#endif
/* Calculate Offsets */
@@ -139,11 +139,15 @@ PLUGIN_HEADER
#define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2)
/* commands enum */
-#define COMMAND_MOVE 1
-#define COMMAND_PLAY 2
-#define COMMAND_LEVEL 3
-/*#define COMMAND_RESTART 4*/
-#define COMMAND_QUIT 5
+#define COMMAND_NOP 0
+#define COMMAND_MOVE 1
+#define COMMAND_PLAY 2
+#define COMMAND_LEVEL 3
+/*#define COMMAND_RESTART 4*/
+#define COMMAND_QUIT 5
+
+/* "While thinking" command */
+int wt_command = COMMAND_NOP;
/* GCC wants this to be present for some targets */
void* memcpy(void* dst, const void* src, size_t size)
@@ -153,278 +157,298 @@ void* memcpy(void* dst, const void* src, size_t size)
/* ---- Get the board column and row (e2 f.e.) for a physical x y ---- */
void xy2cr ( short x, short y, short *c, short *r ) {
- if (computer == black ) {
- *c = x ;
- *r = y ;
- } else {
- *c = 7 - x ;
- *r = 7 - y ;
- }
+ if (computer == black ) {
+ *c = x ;
+ *r = y ;
+ } else {
+ *c = 7 - x ;
+ *r = 7 - y ;
+ }
}
/* ---- get physical x y for a board column and row (e2 f.e.) ---- */
void cr2xy ( short c, short r, short *x, short *y ) {
- if ( computer == black ) {
- *x = c ;
- *y = r ;
- } else {
- *x = 7 - c ;
- *y = 7 - r ;
- }
+ if ( computer == black ) {
+ *x = c ;
+ *y = r ;
+ } else {
+ *x = 7 - c ;
+ *y = 7 - r ;
+ }
}
/* ---- Draw a complete board ---- */
static void cb_drawboard (void) {
short r , c , x , y ;
- short l , piece , p_color ;
- int b_color=1;
-
- rb->lcd_clear_display();
+ short l , piece , p_color ;
+ int b_color=1;
+
+ rb->lcd_clear_display();
- for (r = 0; r < 8; r++) {
+ for (r = 0; r < 8; r++) {
for (c = 0; c < 8; c++) {
l = locn[r][c];
piece = board[l] ;
- p_color = color[l] ;
- cr2xy ( c , r , &x , &y );
- if ( piece == no_piece ) {
- rb->lcd_bitmap_part ( chessbox_pieces , 0 ,
- TILE_HEIGHT * b_color ,
- TILE_WIDTH ,
- XOFS + x*TILE_WIDTH ,
- YOFS + ( 7 - y )*TILE_HEIGHT ,
- TILE_WIDTH ,
- TILE_HEIGHT );
- } else {
- rb->lcd_bitmap_part ( chessbox_pieces ,
- 0 ,
- 2 * TILE_HEIGHT +
- 4 * TILE_HEIGHT * ( piece - 1 ) +
- 2 * TILE_HEIGHT * p_color +
- TILE_HEIGHT * b_color ,
- TILE_WIDTH ,
- XOFS + x*TILE_WIDTH ,
- YOFS + (7 - y)*TILE_HEIGHT ,
- TILE_WIDTH ,
- TILE_HEIGHT );
- }
- b_color = (b_color == 1) ? 0 : 1 ;
+ p_color = color[l] ;
+ cr2xy ( c , r , &x , &y );
+ if ( piece == no_piece ) {
+ rb->lcd_bitmap_part ( chessbox_pieces , 0 ,
+ TILE_HEIGHT * b_color ,
+ TILE_WIDTH ,
+ XOFS + x*TILE_WIDTH ,
+ YOFS + ( 7 - y )*TILE_HEIGHT ,
+ TILE_WIDTH ,
+ TILE_HEIGHT );
+ } else {
+ rb->lcd_bitmap_part ( chessbox_pieces ,
+ 0 ,
+ 2 * TILE_HEIGHT +
+ 4 * TILE_HEIGHT * ( piece - 1 ) +
+ 2 * TILE_HEIGHT * p_color +
+ TILE_HEIGHT * b_color ,
+ TILE_WIDTH ,
+ XOFS + x*TILE_WIDTH ,
+ YOFS + (7 - y)*TILE_HEIGHT ,
+ TILE_WIDTH ,
+ TILE_HEIGHT );
+ }
+ b_color = (b_color == 1) ? 0 : 1 ;
}
- b_color = (b_color == 1) ? 0 : 1 ;
+ b_color = (b_color == 1) ? 0 : 1 ;
+ }
+
+ /* draw board limits */
+ if ( LCD_WIDTH > TILE_WIDTH*8 ) {
+ rb->lcd_set_drawmode ( DRMODE_FG );
+ rb->lcd_drawline ( XOFS - 1 , YOFS ,
+ XOFS - 1 , YOFS + TILE_HEIGHT*8 );
+ rb->lcd_drawline ( XOFS + 8*TILE_WIDTH , YOFS ,
+ XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 );
+ }
+ if ( LCD_HEIGHT > TILE_HEIGHT*8 ) {
+ rb->lcd_set_drawmode ( DRMODE_FG );
+ rb->lcd_drawline ( XOFS , YOFS - 1 ,
+ XOFS + TILE_WIDTH*8 , YOFS - 1 );
+ rb->lcd_drawline ( XOFS , YOFS + TILE_HEIGHT*8 ,
+ XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 );
}
-
- /* draw board limits */
- if ( LCD_WIDTH > TILE_WIDTH*8 ) {
- rb->lcd_set_drawmode ( DRMODE_FG );
- rb->lcd_drawline ( XOFS - 1 , YOFS ,
- XOFS - 1 , YOFS + TILE_HEIGHT*8 );
- rb->lcd_drawline ( XOFS + 8*TILE_WIDTH , YOFS ,
- XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 );
- }
- if ( LCD_HEIGHT > TILE_HEIGHT*8 ) {
- rb->lcd_set_drawmode ( DRMODE_FG );
- rb->lcd_drawline ( XOFS , YOFS - 1 ,
- XOFS + TILE_WIDTH*8 , YOFS - 1 );
- rb->lcd_drawline ( XOFS , YOFS + TILE_HEIGHT*8 ,
- XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 );
- }
- rb->lcd_update();
+ rb->lcd_update();
}
/* ---- Switch mark on board ---- */
void cb_switch ( short x , short y ) {
- rb->lcd_set_drawmode ( DRMODE_COMPLEMENT );
- rb->lcd_drawrect ( XOFS + x*TILE_WIDTH + 1 ,
- YOFS + ( 7 - y )*TILE_HEIGHT +1 ,
- TILE_WIDTH-2 , TILE_HEIGHT-2 );
- rb->lcd_update();
+ rb->lcd_set_drawmode ( DRMODE_COMPLEMENT );
+ rb->lcd_drawrect ( XOFS + x*TILE_WIDTH + 1 ,
+ YOFS + ( 7 - y )*TILE_HEIGHT +1 ,
+ TILE_WIDTH-2 , TILE_HEIGHT-2 );
+ rb->lcd_update();
+}
+
+/* ---- callback for capturing interaction while thinking ---- */
+void cb_wt_callback ( void ) {
+ int button = BUTTON_NONE;
+
+ wt_command = COMMAND_NOP;
+ button = rb->button_get(false);
+ switch (button) {
+ case CB_QUIT:
+ wt_command = COMMAND_QUIT;
+ timeout = true;
+ break;
+ case CB_PLAY:
+ wt_command = COMMAND_PLAY;
+ timeout = true;
+ break;
+ }
}
/* ---- increase playing level ---- */
void cb_levelup ( void ) {
- Level ++;
- if ( Level == 8 ) Level = 1;
- switch (Level) {
- case 1 :
- TCmoves = 60;
- TCminutes = 5;
- rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" );
- break;
- case 2 :
- TCmoves = 60;
- TCminutes = 15;
- rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" );
- break;
- case 3 :
- TCmoves = 60;
- TCminutes = 30;
- rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" );
- break;
- case 4 :
- TCmoves = 40;
- TCminutes = 30;
- rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" );
- break;
- case 5 :
- TCmoves = 40;
- TCminutes = 60;
- rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" );
- break;
- case 6 :
- TCmoves = 40;
- TCminutes = 120;
- rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" );
- break;
- case 7 :
- TCmoves = 40;
- TCminutes = 240;
- rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" );
- break;
- case 8 :
- TCmoves = 1;
- TCminutes = 15;
- rb->splash ( 50 , true , "Level 8: 1 move / 15 min" );
- break;
- case 9 :
- TCmoves = 1;
- TCminutes = 60;
- rb->splash ( 50 , true , "Level 9: 1 move / 60 min" );
- break;
- case 10 :
- TCmoves = 1;
- TCminutes = 600;
- rb->splash ( 50 , true , "Level 10: 1 move / 600 min" );
- break;
- }
+ Level ++;
+ if ( Level == 8 ) Level = 1;
+ switch (Level) {
+ case 1 :
+ TCmoves = 60;
+ TCminutes = 5;
+ rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" );
+ break;
+ case 2 :
+ TCmoves = 60;
+ TCminutes = 15;
+ rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" );
+ break;
+ case 3 :
+ TCmoves = 60;
+ TCminutes = 30;
+ rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" );
+ break;
+ case 4 :
+ TCmoves = 40;
+ TCminutes = 30;
+ rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" );
+ break;
+ case 5 :
+ TCmoves = 40;
+ TCminutes = 60;
+ rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" );
+ break;
+ case 6 :
+ TCmoves = 40;
+ TCminutes = 120;
+ rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" );
+ break;
+ case 7 :
+ TCmoves = 40;
+ TCminutes = 240;
+ rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" );
+ break;
+ case 8 :
+ TCmoves = 1;
+ TCminutes = 15;
+ rb->splash ( 50 , true , "Level 8: 1 move / 15 min" );
+ break;
+ case 9 :
+ TCmoves = 1;
+ TCminutes = 60;
+ rb->splash ( 50 , true , "Level 9: 1 move / 60 min" );
+ break;
+ case 10 :
+ TCmoves = 1;
+ TCminutes = 600;
+ rb->splash ( 50 , true , "Level 10: 1 move / 600 min" );
+ break;
+ }
TCflag = (TCmoves > 1);
- SetTimeControl();
+ SetTimeControl();
};
/* ---- main user loop ---- */
struct cb_command cb_getcommand (void) {
- static short x = 4 , y = 4 ;
- short c , r , l;
- int button, lastbutton = BUTTON_NONE;
- int marked = false , from_marked = false ;
- short marked_x = 0 , marked_y = 0 ;
- struct cb_command result = { 0, {0,0,0,0,0}, 0 };
-
- cb_switch ( x , y );
- /* main loop */
- while ( true ) {
- button = rb->button_get(true);
- switch (button) {
- case CB_QUIT:
- result.type = COMMAND_QUIT;
- return result;
-/* case CB_RESTART:
- result.type = COMMAND_RESTART;
- return result;*/
- case CB_LEVEL:
- result.type = COMMAND_LEVEL;
- return result;
- case CB_PLAY:
+ static short x = 4 , y = 4 ;
+ short c , r , l;
+ int button, lastbutton = BUTTON_NONE;
+ int marked = false , from_marked = false ;
+ short marked_x = 0 , marked_y = 0 ;
+ struct cb_command result = { 0, {0,0,0,0,0}, 0 };
+
+ cb_switch ( x , y );
+ /* main loop */
+ while ( true ) {
+ button = rb->button_get(true);
+ switch (button) {
+ case CB_QUIT:
+ result.type = COMMAND_QUIT;
+ return result;
+#if 0
+ case CB_RESTART:
+ result.type = COMMAND_RESTART;
+ return result;
+#endif
+ case CB_LEVEL:
+ result.type = COMMAND_LEVEL;
+ return result;
+ case CB_PLAY:
#ifdef CB_PLAY_PRE
if (lastbutton != CB_PLAY_PRE)
break;
#endif
- result.type = COMMAND_PLAY;
- return result;
- case CB_UP:
- if ( !from_marked ) cb_switch ( x , y );
- y++;
- if ( y == 8 ) {
- y = 0;
- x--;
- if ( x < 0 ) x = 7;
- }
- if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
- from_marked = true ;
- } else {
- from_marked = false ;
- cb_switch ( x , y );
- }
- break;
- case CB_DOWN:
- if ( !from_marked ) cb_switch ( x , y );
- y--;
- if ( y < 0 ) {
- y = 7;
- x++;
- if ( x == 8 ) x = 0;
- }
- if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
- from_marked = true ;
- } else {
- from_marked = false ;
- cb_switch ( x , y );
- }
- break;
- case CB_LEFT:
- if ( !from_marked ) cb_switch ( x , y );
- x--;
- if ( x < 0 ) {
- x = 7;
- y++;
- if ( y == 8 ) y = 0;
- }
- if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
- from_marked = true ;
- } else {
- from_marked = false ;
- cb_switch ( x , y );
- }
- break;
- case CB_RIGHT:
- if ( !from_marked ) cb_switch ( x , y );
- x++;
- if ( x == 8 ) {
- x = 0;
- y--;
- if ( y < 0 ) y = 7;
- }
- if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
- from_marked = true ;
- } else {
- from_marked = false ;
- cb_switch ( x , y );
- }
- break;
- case CB_SELECT:
+ result.type = COMMAND_PLAY;
+ return result;
+ case CB_UP:
+ if ( !from_marked ) cb_switch ( x , y );
+ y++;
+ if ( y == 8 ) {
+ y = 0;
+ x--;
+ if ( x < 0 ) x = 7;
+ }
+ if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
+ from_marked = true ;
+ } else {
+ from_marked = false ;
+ cb_switch ( x , y );
+ }
+ break;
+ case CB_DOWN:
+ if ( !from_marked ) cb_switch ( x , y );
+ y--;
+ if ( y < 0 ) {
+ y = 7;
+ x++;
+ if ( x == 8 ) x = 0;
+ }
+ if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
+ from_marked = true ;
+ } else {
+ from_marked = false ;
+ cb_switch ( x , y );
+ }
+ break;
+ case CB_LEFT:
+ if ( !from_marked ) cb_switch ( x , y );
+ x--;
+ if ( x < 0 ) {
+ x = 7;
+ y++;
+ if ( y == 8 ) y = 0;
+ }
+ if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
+ from_marked = true ;
+ } else {
+ from_marked = false ;
+ cb_switch ( x , y );
+ }
+ break;
+ case CB_RIGHT:
+ if ( !from_marked ) cb_switch ( x , y );
+ x++;
+ if ( x == 8 ) {
+ x = 0;
+ y--;
+ if ( y < 0 ) y = 7;
+ }
+ if ( marked && ( marked_x == x ) && ( marked_y == y ) ) {
+ from_marked = true ;
+ } else {
+ from_marked = false ;
+ cb_switch ( x , y );
+ }
+ break;
+ case CB_SELECT:
#ifdef CB_SELECT_PRE
if (lastbutton != CB_SELECT_PRE)
break;
#endif
- if ( !marked ) {
- xy2cr ( x , y , &c , &r );
+ if ( !marked ) {
+ xy2cr ( x , y , &c , &r );
l = locn[r][c];
if ( ( color[l]!=computer ) && ( board[l]!=no_piece ) ) {
- marked = true;
- from_marked = true ;
- marked_x = x;
- marked_y = y;
- }
- } else {
- if ( ( marked_x == x ) && ( marked_y == y ) ) {
- marked = false;
- from_marked = false;
- } else {
- xy2cr ( marked_x , marked_y , &c , &r );
- result.mv_s[0] = 'a' + c;
- result.mv_s[1] = '1' + r;
- xy2cr ( x , y , &c , &r );
- result.mv_s[2] = 'a' + c;
- result.mv_s[3] = '1' + r;
- result.mv_s[4] = '\00';
- result.type = COMMAND_MOVE;
- return result;
- }
- }
- break;
- }
- if (button != BUTTON_NONE)
+ marked = true;
+ from_marked = true ;
+ marked_x = x;
+ marked_y = y;
+ }
+ } else {
+ if ( ( marked_x == x ) && ( marked_y == y ) ) {
+ marked = false;
+ from_marked = false;
+ } else {
+ xy2cr ( marked_x , marked_y , &c , &r );
+ result.mv_s[0] = 'a' + c;
+ result.mv_s[1] = '1' + r;
+ xy2cr ( x , y , &c , &r );
+ result.mv_s[2] = 'a' + c;
+ result.mv_s[3] = '1' + r;
+ result.mv_s[4] = '\00';
+ result.type = COMMAND_MOVE;
+ return result;
+ }
+ }
+ break;
+ }
+ if (button != BUTTON_NONE)
lastbutton = button;
- }
+ }
}
@@ -432,77 +456,87 @@ struct cb_command cb_getcommand (void) {
* plugin entry point.
******************************************************************************/
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
- struct cb_command command;
- /* init status */
- bool exit = false;
-
+ struct cb_command command;
+ /* init status */
+ bool exit = false;
+
/* plugin init */
(void)parameter;
rb = api;
/* end of plugin init */
- /* load opening book, soon */
-
- /* init board */
- GNUChess_Initialize();
-
- /* draw the board */
- /* I don't like configscreens, start game inmediatly */
- cb_drawboard();
-
- while (!exit) {
- if ( mate ) {
- rb->splash ( 500 , true , "Checkmate!" );
- rb->button_get(true);
- GNUChess_Initialize();
- cb_drawboard();
- }
- command = cb_getcommand ();
- switch (command.type) {
- case COMMAND_MOVE:
- if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) {
- rb->splash ( 50 , true , "Illegal move!" );
- cb_drawboard();
- } else {
- cb_drawboard();
- rb->splash ( 0 , true , "Thinking..." );
+ /* load opening book, soon */
+
+ /* init board */
+ GNUChess_Initialize();
+
+ /* draw the board */
+ /* I don't like configscreens, start game inmediatly */
+ cb_drawboard();
+
+ while (!exit) {
+ if ( mate ) {
+ rb->splash ( 500 , true , "Checkmate!" );
+ rb->button_get(true);
+ GNUChess_Initialize();
+ cb_drawboard();
+ }
+ command = cb_getcommand ();
+ switch (command.type) {
+ case COMMAND_MOVE:
+ if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) {
+ rb->splash ( 50 , true , "Illegal move!" );
+ cb_drawboard();
+ } else {
+ cb_drawboard();
+ rb->splash ( 0 , true , "Thinking..." );
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
- rb->cpu_boost ( true );
+ rb->cpu_boost ( true );
#endif
- SelectMove ( computer , 0 );
+ SelectMove ( computer , 0 , cb_wt_callback );
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
- rb->cpu_boost ( false );
+ rb->cpu_boost ( false );
#endif
- cb_drawboard();
- }
- break;
-/* case COMMAND_RESTART:
- GNUChess_Initialize();
- cb_drawboard();
- break;*/
- case COMMAND_PLAY:
- opponent = !opponent; computer = !computer;
- rb->splash ( 0 , true , "Thinking..." );
+ if ( wt_command == COMMAND_QUIT ) {
+ exit = true;
+ break;
+ }
+ cb_drawboard();
+ }
+ break;
+#if 0
+ case COMMAND_RESTART:
+ GNUChess_Initialize();
+ cb_drawboard();
+ break;
+#endif
+ case COMMAND_PLAY:
+ opponent = !opponent; computer = !computer;
+ rb->splash ( 0 , true , "Thinking..." );
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
- rb->cpu_boost ( true );
+ rb->cpu_boost ( true );
#endif
- SelectMove ( computer , 0 );
+ SelectMove ( computer , 0 , cb_wt_callback );
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
- rb->cpu_boost ( false );
+ rb->cpu_boost ( false );
#endif
- cb_drawboard();
- break;
- case COMMAND_LEVEL:
- cb_levelup ( );
- cb_drawboard();
- break;
- case COMMAND_QUIT:
- /*cb_saveposition();*/
- exit = true;
- break;
- }
- }
-
+ if ( wt_command == COMMAND_QUIT ) {
+ exit = true;
+ break;
+ }
+ cb_drawboard();
+ break;
+ case COMMAND_LEVEL:
+ cb_levelup ( );
+ cb_drawboard();
+ break;
+ case COMMAND_QUIT:
+ /*cb_saveposition();*/
+ exit = true;
+ break;
+ }
+ }
+
rb->lcd_setfont(FONT_UI);
return PLUGIN_OK;
}
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] );
void OpeningBook ( void );
int search ( short side, short ply, short depth,
short alpha, short beta,
- unsigned short bstline[], short *rpt );
+ unsigned short bstline[], short *rpt,
+ void (*callback)(void) );
int evaluate ( short side, short xside, short ply, short depth,
short alpha, short beta );
int ProbeTTable ( short side, short depth,
@@ -333,9 +334,6 @@ short pscore[3];
xside = otherside[side];
pscore[white] = pscore[black] = 0;
- /* ok, I will yield here for lower levels */
- rb->yield();
-
for (c1 = white; c1 <= black; c1++)
{
c2 = otherside[c1];
@@ -1018,8 +1016,7 @@ register int sq;
/* ............ MOVE GENERATION & SEARCH ROUTINES .............. */
-int SelectMove(side,iop)
-short side,iop;
+int SelectMove( short side, short iop , void (*callback)(void))
/*
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;
{
Sdepth++;
/*ShowDepth(' ');*/
- score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt);
+ score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt,callback);
for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i];
if (score < alpha && !timeout)
{
/*ShowDepth('-');*/
ExtraTime = 10*ResponseTime;
ZeroTTable();
- score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt);
+ score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt,callback);
}
if (score > beta && !timeout && !(root->flags & exact))
{
/*ShowDepth('+');*/
ExtraTime = 0;
ZeroTTable();
- score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt);
+ score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt,callback);
}
score = root->score;
if (!timeout)
@@ -1209,9 +1206,9 @@ struct BookEntry *p;
}\
}
-int search(side,ply,depth,alpha,beta,bstline,rpt)
-short side,ply,depth,alpha,beta,*rpt;
-unsigned short bstline[];
+int search( short side, short ply, short depth,
+ short alpha, short beta, unsigned short bstline[], short *rpt,
+ void (*callback)(void) )
/*
Perform an alpha-beta search to determine the score for the current
@@ -1238,8 +1235,10 @@ short xside,pbst,d,e,cf,score,rcnt;
unsigned short mv,nxtline[maxdepth];
struct leaf *node,tmp;
- /* ok, I will yield here for higher levels */
+ /* this is the only place we need to yield */
rb->yield();
+ /* and check for user interaction */
+ callback();
NodeCnt++;
xside = otherside[side];
@@ -1308,7 +1307,7 @@ struct leaf *node,tmp;
PawnThreat[ply] = (node->flags & pwnthrt);
Tscore[ply] = node->score;
node->score = -search(xside,ply+1,depth-1,-beta,-alpha,
- nxtline,&rcnt);
+ nxtline,&rcnt,callback);
if (abs(node->score) > 9000) node->flags |= exact;
else if (rcnt == 1) node->score /= 2;
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];
extern short color[64];
extern long Level;
extern short TCflag,TCmoves,TCminutes;
+extern short timeout;
/* ---- RockBox integration ---- */
extern struct plugin_api* rb;
@@ -33,8 +34,7 @@ extern struct plugin_api* rb;
/* ---- The beginning of a GNUChess v2 APIfication ---- */
void SetTimeControl(void);
void GNUChess_Initialize(void);
-int VerifyMove(char s[],short iop,unsigned short *mv);
-int SelectMove ( short side, short iop);
-
+int VerifyMove(char s[],short iop,unsigned short *mv);
+int SelectMove ( short side, short iop , void (*callback)(void) );
#endif