1
0
Fork 0
forked from len0rd/rockbox

latest update by Miguel Arevalo

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9037 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Marcoen Hirschberg 2006-03-14 20:55:59 +00:00
parent 258a693e95
commit 789e01bd06
3 changed files with 181 additions and 37 deletions

View file

@ -5,6 +5,7 @@
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/ * \/ \/ \/ \/ \/
* $Id$
* *
* Copyright (C) 2006 Miguel A. Arévalo * Copyright (C) 2006 Miguel A. Arévalo
* Color graphics from eboard * Color graphics from eboard
@ -46,6 +47,7 @@ PLUGIN_HEADER
#define CB_RIGHT BUTTON_RIGHT #define CB_RIGHT BUTTON_RIGHT
#define CB_PLAY (BUTTON_SELECT | BUTTON_PLAY) #define CB_PLAY (BUTTON_SELECT | BUTTON_PLAY)
#define CB_LEVEL (BUTTON_SELECT | BUTTON_RIGHT) #define CB_LEVEL (BUTTON_SELECT | BUTTON_RIGHT)
#define CB_RESTART (BUTTON_SELECT | BUTTON_LEFT)
#define CB_QUIT (BUTTON_SELECT | BUTTON_MENU) #define CB_QUIT (BUTTON_SELECT | BUTTON_MENU)
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD #elif CONFIG_KEYPAD == IAUDIO_X5_PAD
@ -56,6 +58,7 @@ PLUGIN_HEADER
#define CB_RIGHT BUTTON_RIGHT #define CB_RIGHT BUTTON_RIGHT
#define CB_PLAY BUTTON_PLAY #define CB_PLAY BUTTON_PLAY
#define CB_LEVEL BUTTON_REC #define CB_LEVEL BUTTON_REC
#define CB_RESTART BUTTON_SELECT
#define CB_QUIT BUTTON_POWER #define CB_QUIT BUTTON_POWER
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
@ -66,6 +69,7 @@ PLUGIN_HEADER
#define CB_RIGHT BUTTON_RIGHT #define CB_RIGHT BUTTON_RIGHT
#define CB_PLAY BUTTON_ON #define CB_PLAY BUTTON_ON
#define CB_LEVEL BUTTON_MODE #define CB_LEVEL BUTTON_MODE
#define CB_RESTART BUTTON_REC
#define CB_QUIT BUTTON_OFF #define CB_QUIT BUTTON_OFF
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
@ -138,14 +142,31 @@ PLUGIN_HEADER
#define XOFS ((LCD_WIDTH-8*TILE_WIDTH)/2) #define XOFS ((LCD_WIDTH-8*TILE_WIDTH)/2)
#define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2) #define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2)
/* save files */
#define SAVE_FILE PLUGIN_DIR "/chessbox.save"
/* commands enum */ /* commands enum */
#define COMMAND_NOP 0 #define COMMAND_NOP 0
#define COMMAND_MOVE 1 #define COMMAND_MOVE 1
#define COMMAND_PLAY 2 #define COMMAND_PLAY 2
#define COMMAND_LEVEL 3 #define COMMAND_LEVEL 3
/*#define COMMAND_RESTART 4*/ #ifdef CB_RESTART
#define COMMAND_RESTART 4
#endif
#define COMMAND_QUIT 5 #define COMMAND_QUIT 5
/* level+1's string */
const char *level_string[] = { "Level 1: 60 moves / 5 min" ,
"Level 2: 60 moves / 15 min" ,
"Level 3: 60 moves / 30 min" ,
"Level 4: 40 moves / 30 min" ,
"Level 5: 40 moves / 60 min" ,
"Level 6: 40 moves / 120 min" ,
"Level 7: 40 moves / 240 min" ,
"Level 8: 1 move / 15 min" ,
"Level 9: 1 move / 60 min" ,
"Level 10: 1 move / 600 min" };
/* "While thinking" command */ /* "While thinking" command */
int wt_command = COMMAND_NOP; int wt_command = COMMAND_NOP;
@ -262,69 +283,188 @@ void cb_wt_callback ( void ) {
} }
} }
/* ---- increase playing level ---- */ /* ---- set playing parameters depending on level ---- */
void cb_levelup ( void ) { void cb_setlevel ( int lev ) {
Level ++; Level = (lev > 7) ? 7 : ( (lev < 1) ? 1 : lev ) ;
if ( Level == 8 ) Level = 1;
switch (Level) { switch (Level) {
case 1 : case 1 :
TCmoves = 60; TCmoves = 60;
TCminutes = 5; TCminutes = 5;
rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" );
break; break;
case 2 : case 2 :
TCmoves = 60; TCmoves = 60;
TCminutes = 15; TCminutes = 15;
rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" );
break; break;
case 3 : case 3 :
TCmoves = 60; TCmoves = 60;
TCminutes = 30; TCminutes = 30;
rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" );
break; break;
case 4 : case 4 :
TCmoves = 40; TCmoves = 40;
TCminutes = 30; TCminutes = 30;
rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" );
break; break;
case 5 : case 5 :
TCmoves = 40; TCmoves = 40;
TCminutes = 60; TCminutes = 60;
rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" );
break; break;
case 6 : case 6 :
TCmoves = 40; TCmoves = 40;
TCminutes = 120; TCminutes = 120;
rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" );
break; break;
case 7 : case 7 :
TCmoves = 40; TCmoves = 40;
TCminutes = 240; TCminutes = 240;
rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" );
break; break;
case 8 : case 8 :
TCmoves = 1; TCmoves = 1;
TCminutes = 15; TCminutes = 15;
rb->splash ( 50 , true , "Level 8: 1 move / 15 min" );
break; break;
case 9 : case 9 :
TCmoves = 1; TCmoves = 1;
TCminutes = 60; TCminutes = 60;
rb->splash ( 50 , true , "Level 9: 1 move / 60 min" );
break; break;
case 10 : case 10 :
TCmoves = 1; TCmoves = 1;
TCminutes = 600; TCminutes = 600;
rb->splash ( 50 , true , "Level 10: 1 move / 600 min" );
break; break;
} }
TCflag = (TCmoves > 1); TCflag = (TCmoves > 1);
SetTimeControl(); SetTimeControl();
}
/* ---- increase playing level ---- */
void cb_levelup ( void ) {
if ( Level == 7 )
cb_setlevel ( 1 );
else
cb_setlevel ( Level+1 );
rb->splash ( 50 , true , level_string[Level-1] );
}; };
/* ---- Save current position ---- */
void cb_saveposition ( void ) {
int fd;
short sq,i,c;
unsigned short temp;
rb->splash ( 0 , true , "Saving position" );
fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
computer++; rb->write(fd, &(computer), sizeof(computer)); computer--;
opponent++; rb->write(fd, &(opponent), sizeof(opponent)); opponent--;
rb->write(fd, &(Game50), sizeof(Game50));
rb->write(fd, &(castld[white]), sizeof(castld[white]));
rb->write(fd, &(castld[black]), sizeof(castld[black]));
rb->write(fd, &(kingmoved[white]), sizeof(kingmoved[white]));
rb->write(fd, &(kingmoved[black]), sizeof(kingmoved[black]));
rb->write(fd, &(Level), sizeof(Level));
rb->write(fd, &(TCflag), sizeof(TCflag));
rb->write(fd, &(OperatorTime), sizeof(OperatorTime));
rb->write(fd, &(TimeControl.clock[white]),
sizeof(TimeControl.clock[white]) );
rb->write(fd, &(TimeControl.clock[black]),
sizeof(TimeControl.clock[black]) );
rb->write(fd, &(TimeControl.moves[white]),
sizeof(TimeControl.moves[white]) );
rb->write(fd, &(TimeControl.moves[black]),
sizeof(TimeControl.moves[black]) );
for (sq = 0; sq < 64; sq++) {
if (color[sq] == neutral) c = 0; else c = color[sq]+1;
temp = 256*board[sq] + c ;
rb->write(fd, &(temp), sizeof(temp));
}
for (i = 0; i <= GameCnt; i++) {
if (GameList[i].color == neutral)
c = 0;
else
c = GameList[i].color + 1;
rb->write(fd, &(GameList[i].gmove), sizeof(GameList[i].gmove));
rb->write(fd, &(GameList[i].score), sizeof(GameList[i].score));
rb->write(fd, &(GameList[i].depth), sizeof(GameList[i].depth));
rb->write(fd, &(GameList[i].nodes), sizeof(GameList[i].nodes));
rb->write(fd, &(GameList[i].time), sizeof(GameList[i].time));
rb->write(fd, &(GameList[i].piece), sizeof(GameList[i].piece));
rb->write(fd, &(c), sizeof(c));
}
rb->close(fd);
}
/* ---- Restore saved position ---- */
void cb_restoreposition ( void ) {
int fd;
int c;
short sq;
unsigned short m;
if ( (fd = rb->open(SAVE_FILE, O_RDONLY)) >= 0 ) {
rb->splash ( 0 , true , "Loading position" );
rb->read(fd, &(computer), sizeof(computer));
rb->read(fd, &(opponent), sizeof(opponent));
rb->read(fd, &(Game50), sizeof(Game50));
rb->read(fd, &(castld[white]), sizeof(castld[white]));
rb->read(fd, &(castld[black]), sizeof(castld[black]));
rb->read(fd, &(kingmoved[white]), sizeof(kingmoved[white]));
rb->read(fd, &(kingmoved[black]), sizeof(kingmoved[black]));
rb->read(fd, &(Level), sizeof(Level));
rb->read(fd, &(TCflag), sizeof(TCflag));
rb->read(fd, &(OperatorTime), sizeof(OperatorTime));
rb->read(fd, &(TimeControl.clock[white]),
sizeof(TimeControl.clock[white]));
rb->read(fd, &(TimeControl.clock[black]),
sizeof(TimeControl.clock[black]));
rb->read(fd, &(TimeControl.moves[white]),
sizeof(TimeControl.moves[white]));
rb->read(fd, &(TimeControl.moves[black]),
sizeof(TimeControl.moves[black]));
for (sq = 0; sq < 64; sq++) {
rb->read(fd, &(m), sizeof(m));
board[sq] = (m >> 8); color[sq] = (m & 0xFF);
if (color[sq] == 0)
color[sq] = neutral;
else
--color[sq];
}
GameCnt = -1; c = '?';
while (rb->read(fd, &(GameList[++GameCnt].gmove),
sizeof(GameList[GameCnt].gmove)) > 0) {
rb->read(fd, &(GameList[GameCnt].score),
sizeof(GameList[GameCnt].score));
rb->read(fd, &(GameList[GameCnt].depth),
sizeof(GameList[GameCnt].depth));
rb->read(fd, &(GameList[GameCnt].nodes),
sizeof(GameList[GameCnt].nodes));
rb->read(fd, &(GameList[GameCnt].time),
sizeof(GameList[GameCnt].time));
rb->read(fd, &(GameList[GameCnt].piece),
sizeof(GameList[GameCnt].piece));
rb->read(fd, &(GameList[GameCnt].color),
sizeof(GameList[GameCnt].color));
if (GameList[GameCnt].color == 0)
GameList[GameCnt].color = neutral;
else
--GameList[GameCnt].color;
}
GameCnt--;
if (TimeControl.clock[white] > 0)
TCflag = true;
computer--; opponent--;
}
rb->close(fd);
cb_setlevel(Level);
InitializeStats();
Sdepth = 0;
}
/* ---- main user loop ---- */ /* ---- main user loop ---- */
struct cb_command cb_getcommand (void) { struct cb_command cb_getcommand (void) {
static short x = 4 , y = 4 ; static short x = 4 , y = 3 ;
short c , r , l; short c , r , l;
int button, lastbutton = BUTTON_NONE; int button, lastbutton = BUTTON_NONE;
int marked = false , from_marked = false ; int marked = false , from_marked = false ;
@ -339,7 +479,7 @@ struct cb_command cb_getcommand (void) {
case CB_QUIT: case CB_QUIT:
result.type = COMMAND_QUIT; result.type = COMMAND_QUIT;
return result; return result;
#if 0 #ifdef CB_RESTART
case CB_RESTART: case CB_RESTART:
result.type = COMMAND_RESTART; result.type = COMMAND_RESTART;
return result; return result;
@ -470,6 +610,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
/* init board */ /* init board */
GNUChess_Initialize(); GNUChess_Initialize();
/* restore saved position, if saved */
cb_restoreposition();
/* draw the board */ /* draw the board */
/* I don't like configscreens, start game inmediatly */ /* I don't like configscreens, start game inmediatly */
cb_drawboard(); cb_drawboard();
@ -504,7 +647,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
cb_drawboard(); cb_drawboard();
} }
break; break;
#if 0 #ifdef COMMAND_RESTART
case COMMAND_RESTART: case COMMAND_RESTART:
GNUChess_Initialize(); GNUChess_Initialize();
cb_drawboard(); cb_drawboard();
@ -531,12 +674,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
cb_drawboard(); cb_drawboard();
break; break;
case COMMAND_QUIT: case COMMAND_QUIT:
/*cb_saveposition();*/
exit = true; exit = true;
break; break;
} }
} }
cb_saveposition();
rb->lcd_setfont(FONT_UI); rb->lcd_setfont(FONT_UI);
return PLUGIN_OK; return PLUGIN_OK;
} }

View file

@ -32,9 +32,6 @@
#define ttblsz 4096 #define ttblsz 4096
/*#define ttblsz 16384*/
#define huge
#define ctlP 0x4000 #define ctlP 0x4000
#define ctlN 0x2800 #define ctlN 0x2800
#define ctlB 0x1800 #define ctlB 0x1800
@ -74,17 +71,6 @@ struct leaf
short f,t,score,reply; short f,t,score,reply;
unsigned short flags; unsigned short flags;
}; };
struct GameRec
{
unsigned short gmove;
short score,depth,time,piece,color;
long nodes;
};
struct TimeControlRec
{
short moves[2];
long clock[2];
};
struct BookEntry struct BookEntry
{ {
struct BookEntry *next; struct BookEntry *next;
@ -182,7 +168,7 @@ unsigned short hashkey;
unsigned long hashbd; unsigned long hashbd;
struct hashval hashcode[2][7][64]; struct hashval hashcode[2][7][64];
struct hashentry ttable[ttblsz]; struct hashentry ttable[ttblsz];
struct hashentry huge *ptbl; struct hashentry *ptbl;
unsigned char history[8192]; unsigned char history[8192];
short Mwpawn[64],Mbpawn[64],Mknight[2][64],Mbishop[2][64]; short Mwpawn[64],Mbpawn[64],Mknight[2][64],Mbishop[2][64];

View file

@ -19,14 +19,28 @@
#define valueQ 1100 #define valueQ 1100
#define valueK 1200 #define valueK 1200
/* ---- chess system global variables ---- */ /* ---- chess engine global types ---- */
extern short mate,opponent,computer; struct GameRec {
unsigned short gmove;
short score,depth,time,piece,color;
long nodes;
};
struct TimeControlRec {
short moves[2];
long clock[2];
};
/* ---- chess engine global variables ---- */
extern short mate,opponent,computer,Sdepth;
extern short locn[8][8]; extern short locn[8][8];
extern short board[64]; extern short board[64];
extern short color[64]; extern short color[64];
extern long Level; extern long Level;
extern short TCflag,TCmoves,TCminutes; extern short TCflag,TCmoves,TCminutes;
extern short timeout; extern short timeout;
extern short GameCnt,Game50,castld[2],kingmoved[2],OperatorTime;
extern struct TimeControlRec TimeControl;
extern struct GameRec GameList[240];
/* ---- RockBox integration ---- */ /* ---- RockBox integration ---- */
extern struct plugin_api* rb; extern struct plugin_api* rb;
@ -36,5 +50,6 @@ void SetTimeControl(void);
void GNUChess_Initialize(void); void GNUChess_Initialize(void);
int VerifyMove(char s[],short iop,unsigned short *mv); int VerifyMove(char s[],short iop,unsigned short *mv);
int SelectMove ( short side, short iop , void (*callback)(void) ); int SelectMove ( short side, short iop , void (*callback)(void) );
void InitializeStats ( void );
#endif #endif