Chessbox: Patch #5052 by Miguel A. Arevalo: opening book. * Simplified drawing of board borders, and fixed a graphical glitch only visible on targets where all 4 borders are visible (ipod mini).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9676 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2006-04-15 11:27:47 +00:00
parent 7aac7520ac
commit 7b22e99bd8
7 changed files with 2250 additions and 44 deletions

View file

@ -18,7 +18,7 @@ endif
LINKFILE := $(OBJDIR)/link.lds
DEPFILE = $(OBJDIR)/dep-chessbox
SRC = chessbox.c gnuchess.c
SRC = chessbox.c gnuchess.c opening.c
SOURCES = $(SRC)
OBJS := $(SRC:%.c=$(OBJDIR)/%.o)

View file

@ -1,6 +1,6 @@
#include "config.h"
/* linker script for rockboy as an overlay,
/* linker script for chessbox as an overlay,
* only used/ necessary for SH-based archos targets */
OUTPUT_FORMAT(elf32-sh)
@ -8,7 +8,7 @@ OUTPUT_FORMAT(elf32-sh)
#define DRAMORIG 0x09000000
#define PLUGIN_LENGTH PLUGIN_BUFFER_SIZE
#define OVERLAY_LENGTH 0x20000
#define OVERLAY_LENGTH 0x30000
#define OVERLAY_ORIGIN (DRAMORIG + (MEMORYSIZE * 0x100000) - PLUGIN_LENGTH - OVERLAY_LENGTH)
MEMORY

View file

@ -24,6 +24,7 @@
#ifdef HAVE_LCD_BITMAP
#include "gnuchess.h"
#include "opening.h"
/* type definitions */
struct cb_command {
@ -249,20 +250,16 @@ static void cb_drawboard (void) {
}
/* 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 );
}
#if (LCD_WIDTH > TILE_WIDTH*8) && (LCD_HEIGHT > TILE_HEIGHT*8)
rb->lcd_drawrect(XOFS - 1, YOFS - 1, TILE_WIDTH*8 + 2, TILE_HEIGHT*8 + 2);
#elif LCD_WIDTH > TILE_WIDTH*8
rb->lcd_vline(XOFS - 1, 0, LCD_HEIGHT - 1);
rb->lcd_vline(XOFS + 8*TILE_WIDTH, 0, LCD_HEIGHT - 1);
#elif LCD_HEIGHT > TILE_HEIGHT*8
rb->lcd_hline(0, LCD_WIDTH - 1, YOFS - 1);
rb->lcd_hline(0, LCD_WIDTH - 1, YOFS + TILE_HEIGHT*8);
#endif
rb->lcd_update();
}
@ -273,6 +270,7 @@ void cb_switch ( short x , short y ) {
YOFS + ( 7 - y )*TILE_HEIGHT +1 ,
TILE_WIDTH-2 , TILE_HEIGHT-2 );
rb->lcd_update();
rb->lcd_set_drawmode ( DRMODE_SOLID );
}
/* ---- callback for capturing interaction while thinking ---- */
@ -370,6 +368,7 @@ void cb_saveposition ( void ) {
rb->write(fd, &(kingmoved[white]), sizeof(kingmoved[white]));
rb->write(fd, &(kingmoved[black]), sizeof(kingmoved[black]));
rb->write(fd, &(withbook), sizeof(withbook));
rb->write(fd, &(Level), sizeof(Level));
rb->write(fd, &(TCflag), sizeof(TCflag));
rb->write(fd, &(OperatorTime), sizeof(OperatorTime));
@ -421,6 +420,7 @@ void cb_restoreposition ( void ) {
rb->read(fd, &(kingmoved[white]), sizeof(kingmoved[white]));
rb->read(fd, &(kingmoved[black]), sizeof(kingmoved[black]));
rb->read(fd, &(withbook), sizeof(withbook));
rb->read(fd, &(Level), sizeof(Level));
rb->read(fd, &(TCflag), sizeof(TCflag));
rb->read(fd, &(OperatorTime), sizeof(OperatorTime));

View file

@ -27,6 +27,7 @@
#include "plugin.h"
#include "gnuchess.h"
#include "opening.h"
#include <ctype.h>
@ -96,6 +97,7 @@ short PieceList[2][16],PieceCnt[2],atak[2][64],PawnCnt[2][8];
short castld[2],kingmoved[2],mtl[2],pmtl[2],emtl[2],hung[2];
short c1,c2,*atk1,*atk2,*PC1,*PC2,EnemyKing;
short mate,post,opponent,computer,Sdepth,Awindow,Bwindow,dither;
bool withbook ;
long ResponseTime,ExtraTime,Level,et,et0,time0,cputimer,ft;
long NodeCnt,evrate,ETnodes,EvalNodes,HashCnt;
short quit,reverse,bothsides,hashflag,InChk,player,force,easy,beep;
@ -107,7 +109,6 @@ short Pscore[maxdepth],Tscore[maxdepth],Threat[maxdepth];
struct GameRec GameList[240];
short GameCnt,Game50,epsquare,lpost,rcptr,contempt;
short MaxSearchDepth,Xscore;
struct BookEntry *Book;
struct TimeControlRec TimeControl;
short TCflag,TCmoves,TCminutes,OperatorTime;
short otherside[3]={1,0,2};
@ -1051,8 +1052,8 @@ static short i,alpha,beta,score,tempb,tempc,tempsf,tempst,xside,rpt;
TrPnt[1] = 0; root = &Tree[0];
MoveList(side,1);
for (i = TrPnt[1]; i < TrPnt[2]; i++) pick(i,TrPnt[2]-1);
/*if (Book != NULL) OpeningBook();*/
if (Book != NULL) timeout = true;
if (withbook) OpeningBook();
if (withbook) timeout = true;
NodeCnt = ETnodes = EvalNodes = HashCnt = 0;
Zscore = 0; zwndw = 20;
}
@ -1103,7 +1104,7 @@ static short i,alpha,beta,score,tempb,tempc,tempsf,tempst,xside,rpt;
score = root->score;
if (rpt >= 2 || score < -12000) root->flags |= draw;
if (iop == 2) return(0);
if (Book == NULL) hint = PrVar[2];
if (!withbook) hint = PrVar[2];
ElapsedTime(1);
if (score > -9999 && rpt <= 2)
@ -1148,36 +1149,38 @@ void OpeningBook()
*/
{
short j,pnt;
unsigned short m,*mp;
unsigned r,r0;
struct BookEntry *p;
short j,pnt;
unsigned short m;
unsigned r,r0;
int o_c=0 , m_c=0 ;
rb->srand((unsigned)time0);
r0 = m = 0;
p = Book;
while (p != NULL)
{
mp = p->mv;
for (j = 0; j <= GameCnt; j++)
if (GameList[j].gmove != *(mp++)) break;
if (j > GameCnt)
if ((r=rb->rand()) > r0)
{
r0 = r; m = *mp;
hint = *(++mp);
rb->srand ( *rb->current_tick ) ;
r0 = 0;
m = 0;
while ( o_c < MAX_OPENING ) {
m_c = 0 ;
for (j = 0; j <= GameCnt; j++) {
if ( GameList[j].gmove != OBook[o_c][m_c] ) break;
m_c++;
}
/* I added ( m != OBook[o_c][m_c] ) trying to get more random games */
if ( ( j > GameCnt ) && ( m != OBook[o_c][m_c] ) ) {
r=rb->rand();
if ( r > r0 ) {
r0 = r; m = OBook[o_c][m_c];
hint = OBook[o_c][m_c+1];
}
p = p->next;
}
o_c++;
}
for (pnt = TrPnt[1]; pnt < TrPnt[2]; pnt++)
if ((Tree[pnt].f<<8) + Tree[pnt].t == m) Tree[pnt].score = 0;
pick(TrPnt[1],TrPnt[2]-1);
if (Tree[TrPnt[1]].score < 0) Book = NULL;
if (Tree[TrPnt[1]].score < 0) withbook = false;
}
/*if (post) ShowCurrentMove(pnt,node->f,node->t);\*/
#define UpdateSearchStatus \
{\
if (pnt > TrPnt[1])\
@ -2329,7 +2332,7 @@ void NewGame() {
/*time0 = time((long *)0);*/
time0 = *(rb->current_tick) / HZ ;
ElapsedTime(1);
/*GetOpenings();*/
withbook = true;
}
/* ---- Initialize variables and reset board ---- */
@ -2344,7 +2347,6 @@ void GNUChess_Initialize ( void ) {
TCflag = true;
NewGame();
MaxSearchDepth = 29 ;
/* remember to GetOpenings */
}
void algbr(f,t,flag)

View file

@ -35,6 +35,7 @@ extern short mate,opponent,computer,Sdepth;
extern short locn[8][8];
extern short board[64];
extern short color[64];
extern bool withbook;
extern long Level;
extern short TCflag,TCmoves,TCminutes;
extern short timeout;

2195
apps/plugins/chessbox/opening.c Executable file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
#ifndef _OPENING_H_
#define _OPENING_H_
#define MAX_OPENING 241
extern unsigned short OBook[241][56];
#endif