1
0
Fork 0
forked from len0rd/rockbox

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 LINKFILE := $(OBJDIR)/link.lds
DEPFILE = $(OBJDIR)/dep-chessbox DEPFILE = $(OBJDIR)/dep-chessbox
SRC = chessbox.c gnuchess.c SRC = chessbox.c gnuchess.c opening.c
SOURCES = $(SRC) SOURCES = $(SRC)
OBJS := $(SRC:%.c=$(OBJDIR)/%.o) OBJS := $(SRC:%.c=$(OBJDIR)/%.o)

View file

@ -1,6 +1,6 @@
#include "config.h" #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 */ * only used/ necessary for SH-based archos targets */
OUTPUT_FORMAT(elf32-sh) OUTPUT_FORMAT(elf32-sh)
@ -8,7 +8,7 @@ OUTPUT_FORMAT(elf32-sh)
#define DRAMORIG 0x09000000 #define DRAMORIG 0x09000000
#define PLUGIN_LENGTH PLUGIN_BUFFER_SIZE #define PLUGIN_LENGTH PLUGIN_BUFFER_SIZE
#define OVERLAY_LENGTH 0x20000 #define OVERLAY_LENGTH 0x30000
#define OVERLAY_ORIGIN (DRAMORIG + (MEMORYSIZE * 0x100000) - PLUGIN_LENGTH - OVERLAY_LENGTH) #define OVERLAY_ORIGIN (DRAMORIG + (MEMORYSIZE * 0x100000) - PLUGIN_LENGTH - OVERLAY_LENGTH)
MEMORY MEMORY

View file

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

View file

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

View file

@ -35,6 +35,7 @@ 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 bool withbook;
extern long Level; extern long Level;
extern short TCflag,TCmoves,TCminutes; extern short TCflag,TCmoves,TCminutes;
extern short timeout; 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