2006-02-22 14:24:54 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2006-03-14 20:55:59 +00:00
|
|
|
* $Id$
|
2006-02-22 14:24:54 +00:00
|
|
|
*
|
2017-01-31 00:07:47 +00:00
|
|
|
* Copyright (C) 2006 Miguel A. Arévalo
|
2006-02-22 14:24:54 +00:00
|
|
|
* Color graphics from eboard
|
|
|
|
* GNUChess v2 chess engine Copyright (c) 1988 John Stanback
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-02-22 14:24:54 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
#include "plugin.h"
|
|
|
|
|
2009-02-26 21:24:29 +00:00
|
|
|
#if (MEMORYSIZE > 8) /* Lowmem doesn't have playback in chessbox */
|
|
|
|
#define HAVE_PLAYBACK_CONTROL
|
|
|
|
#endif
|
2017-01-31 03:28:02 +00:00
|
|
|
/*#define CHESSBOX_SAVE_FILE_DBG PLUGIN_GAMES_DATA_DIR "/chessbox_dbg.save"*/
|
2009-02-26 21:24:29 +00:00
|
|
|
#ifdef HAVE_PLAYBACK_CONTROL
|
2009-02-26 17:10:27 +00:00
|
|
|
#include "lib/playback_control.h"
|
2009-02-26 17:46:01 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
#include "gnuchess.h"
|
2006-04-15 11:27:47 +00:00
|
|
|
#include "opening.h"
|
2007-05-29 16:33:16 +00:00
|
|
|
#include "chessbox_pgn.h"
|
2006-02-22 14:24:54 +00:00
|
|
|
|
|
|
|
/* type definitions */
|
|
|
|
struct cb_command {
|
2006-03-03 15:01:37 +00:00
|
|
|
int type;
|
|
|
|
char mv_s[5];
|
|
|
|
unsigned short mv;
|
2006-02-22 14:24:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* External bitmaps */
|
|
|
|
extern const fb_data chessbox_pieces[];
|
|
|
|
|
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
|
2007-10-19 09:05:18 +00:00
|
|
|
/* Tile size defined by the assigned bitmap */
|
2008-11-20 11:27:31 +00:00
|
|
|
#include "pluginbitmaps/chessbox_pieces.h"
|
2007-10-19 09:05:18 +00:00
|
|
|
#define TILE_WIDTH BMPWIDTH_chessbox_pieces
|
|
|
|
#define TILE_HEIGHT (BMPHEIGHT_chessbox_pieces/26)
|
2006-02-22 14:24:54 +00:00
|
|
|
|
|
|
|
/* Calculate Offsets */
|
|
|
|
#define XOFS ((LCD_WIDTH-8*TILE_WIDTH)/2)
|
|
|
|
#define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2)
|
|
|
|
|
2006-03-14 20:55:59 +00:00
|
|
|
/* save files */
|
2011-03-02 23:43:54 +00:00
|
|
|
#define SAVE_FILE PLUGIN_GAMES_DATA_DIR "/chessbox.save"
|
2006-03-14 20:55:59 +00:00
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
/* commands enum */
|
2006-03-03 15:01:37 +00:00
|
|
|
#define COMMAND_NOP 0
|
|
|
|
#define COMMAND_MOVE 1
|
|
|
|
#define COMMAND_PLAY 2
|
|
|
|
#define COMMAND_LEVEL 3
|
2007-05-18 22:12:34 +00:00
|
|
|
#define COMMAND_RESTART 4
|
2006-03-03 15:01:37 +00:00
|
|
|
#define COMMAND_QUIT 5
|
2007-05-18 22:12:34 +00:00
|
|
|
#define COMMAND_MENU 6
|
|
|
|
#define COMMAND_SAVE 7
|
|
|
|
#define COMMAND_RESTORE 8
|
|
|
|
#define COMMAND_RESUME 9
|
2007-05-29 16:33:16 +00:00
|
|
|
#define COMMAND_SELECT 10
|
|
|
|
#define COMMAND_NEXT 11
|
|
|
|
#define COMMAND_PREV 12
|
2019-07-15 14:49:55 +00:00
|
|
|
#define COMMAND_VIEW 13
|
|
|
|
#define COMMAND_RETURN 14
|
2007-05-29 16:33:16 +00:00
|
|
|
|
|
|
|
short plugin_mode;
|
2006-03-03 15:01:37 +00:00
|
|
|
|
2006-03-14 20:55:59 +00:00
|
|
|
/* level+1's string */
|
2019-02-06 18:16:58 +00:00
|
|
|
const char *level_string[] = { ID2P(LANG_CHESSBOX_LEVEL_1) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_2) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_3) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_4) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_5) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_6) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_7) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_8) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_9) ,
|
|
|
|
ID2P(LANG_CHESSBOX_LEVEL_10) };
|
2006-03-14 20:55:59 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
/* "While thinking" command */
|
|
|
|
int wt_command = COMMAND_NOP;
|
2006-02-22 14:24:54 +00:00
|
|
|
|
2018-12-23 03:16:32 +00:00
|
|
|
/* System event id */
|
|
|
|
static long cb_sysevent = 0;
|
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
/* ---- Get the board column and row (e2 f.e.) for a physical x y ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void xy2cr ( short x, short y, short *c, short *r ) {
|
2006-03-03 15:01:37 +00:00
|
|
|
if (computer == black ) {
|
|
|
|
*c = x ;
|
|
|
|
*r = y ;
|
|
|
|
} else {
|
|
|
|
*c = 7 - x ;
|
|
|
|
*r = 7 - y ;
|
|
|
|
}
|
2006-02-22 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---- get physical x y for a board column and row (e2 f.e.) ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void cr2xy ( short c, short r, short *x, short *y ) {
|
2006-03-03 15:01:37 +00:00
|
|
|
if ( computer == black ) {
|
|
|
|
*x = c ;
|
|
|
|
*y = r ;
|
|
|
|
} else {
|
|
|
|
*x = 7 - c ;
|
|
|
|
*y = 7 - r ;
|
|
|
|
}
|
2006-02-22 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---- Draw a complete board ---- */
|
|
|
|
static void cb_drawboard (void) {
|
|
|
|
short r , c , x , y ;
|
2006-03-03 15:01:37 +00:00
|
|
|
short l , piece , p_color ;
|
|
|
|
int b_color=1;
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->lcd_clear_display();
|
2006-02-22 14:24:54 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
for (r = 0; r < 8; r++) {
|
2006-02-22 14:24:54 +00:00
|
|
|
for (c = 0; c < 8; c++) {
|
|
|
|
l = locn[r][c];
|
|
|
|
piece = board[l] ;
|
2006-03-03 15:01:37 +00:00
|
|
|
p_color = color[l] ;
|
|
|
|
cr2xy ( c , r , &x , &y );
|
|
|
|
if ( piece == no_piece ) {
|
|
|
|
rb->lcd_bitmap_part ( chessbox_pieces , 0 ,
|
|
|
|
TILE_HEIGHT * b_color ,
|
2017-01-31 00:07:47 +00:00
|
|
|
STRIDE( SCREEN_MAIN,
|
|
|
|
BMPWIDTH_chessbox_pieces,
|
2009-08-31 04:21:21 +00:00
|
|
|
BMPHEIGHT_chessbox_pieces) ,
|
2006-03-03 15:01:37 +00:00
|
|
|
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 ,
|
2017-01-31 00:07:47 +00:00
|
|
|
STRIDE( SCREEN_MAIN,
|
|
|
|
BMPWIDTH_chessbox_pieces,
|
2009-08-31 04:21:21 +00:00
|
|
|
BMPHEIGHT_chessbox_pieces) ,
|
2006-03-03 15:01:37 +00:00
|
|
|
XOFS + x*TILE_WIDTH ,
|
|
|
|
YOFS + (7 - y)*TILE_HEIGHT ,
|
|
|
|
TILE_WIDTH ,
|
|
|
|
TILE_HEIGHT );
|
|
|
|
}
|
|
|
|
b_color = (b_color == 1) ? 0 : 1 ;
|
2006-02-22 14:24:54 +00:00
|
|
|
}
|
2006-03-03 15:01:37 +00:00
|
|
|
b_color = (b_color == 1) ? 0 : 1 ;
|
|
|
|
}
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
/* draw board limits */
|
2006-04-15 11:27:47 +00:00
|
|
|
#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
|
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->lcd_update();
|
2006-02-22 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 18:16:58 +00:00
|
|
|
static short oldx, oldy = 0;
|
|
|
|
void cb_talk(short x, short y)
|
|
|
|
{
|
|
|
|
if (x != oldx || y != oldy) {
|
|
|
|
short c, r;
|
|
|
|
short l, piece, p_color;
|
|
|
|
|
|
|
|
rb->talk_shutup();
|
|
|
|
cr2xy(x, y, &c, &r);
|
|
|
|
l = locn[r][c];
|
|
|
|
piece = board[l];
|
|
|
|
p_color = color[l];
|
|
|
|
if (piece != no_piece) {
|
|
|
|
rb->talk_id (VOICE_WHITE + p_color, true);
|
|
|
|
if (piece >= pawn && piece <= king) {
|
|
|
|
rb->talk_id (VOICE_PAWN + piece - 1, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->talk_id (VOICE_CHAR_A + c, true);
|
|
|
|
rb->talk_id (VOICE_ONE + r, true);
|
|
|
|
oldx = x;
|
|
|
|
oldy = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
/* ---- Switch mark on board ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void cb_switch ( short x , short y ) {
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu)
|
|
|
|
cb_talk(x, y);
|
2006-03-03 15:01:37 +00:00
|
|
|
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();
|
2006-04-15 11:27:47 +00:00
|
|
|
rb->lcd_set_drawmode ( DRMODE_SOLID );
|
2006-03-03 15:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---- callback for capturing interaction while thinking ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void cb_wt_callback ( void ) {
|
2006-03-03 15:01:37 +00:00
|
|
|
int button = BUTTON_NONE;
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
wt_command = COMMAND_NOP;
|
|
|
|
button = rb->button_get(false);
|
|
|
|
switch (button) {
|
2018-12-23 03:16:32 +00:00
|
|
|
case SYS_POWEROFF:
|
|
|
|
cb_sysevent = button;
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef CB_RC_QUIT
|
|
|
|
case CB_RC_QUIT:
|
2018-12-23 03:16:32 +00:00
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
wt_command = COMMAND_QUIT;
|
|
|
|
timeout = true;
|
|
|
|
break;
|
2007-05-18 22:12:34 +00:00
|
|
|
case CB_MENU:
|
|
|
|
wt_command = COMMAND_MENU;
|
|
|
|
timeout = true;
|
|
|
|
break;
|
2006-03-03 15:01:37 +00:00
|
|
|
case CB_PLAY:
|
|
|
|
wt_command = COMMAND_PLAY;
|
|
|
|
timeout = true;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-22 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
2006-03-14 20:55:59 +00:00
|
|
|
/* ---- set playing parameters depending on level ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void cb_setlevel ( int lev ) {
|
2006-03-14 20:55:59 +00:00
|
|
|
Level = (lev > 7) ? 7 : ( (lev < 1) ? 1 : lev ) ;
|
2006-03-03 15:01:37 +00:00
|
|
|
switch (Level) {
|
|
|
|
case 1 :
|
|
|
|
TCmoves = 60;
|
|
|
|
TCminutes = 5;
|
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
TCmoves = 60;
|
|
|
|
TCminutes = 15;
|
|
|
|
break;
|
|
|
|
case 3 :
|
|
|
|
TCmoves = 60;
|
|
|
|
TCminutes = 30;
|
|
|
|
break;
|
|
|
|
case 4 :
|
|
|
|
TCmoves = 40;
|
|
|
|
TCminutes = 30;
|
|
|
|
break;
|
|
|
|
case 5 :
|
|
|
|
TCmoves = 40;
|
|
|
|
TCminutes = 60;
|
|
|
|
break;
|
|
|
|
case 6 :
|
|
|
|
TCmoves = 40;
|
|
|
|
TCminutes = 120;
|
|
|
|
break;
|
|
|
|
case 7 :
|
|
|
|
TCmoves = 40;
|
|
|
|
TCminutes = 240;
|
|
|
|
break;
|
|
|
|
case 8 :
|
|
|
|
TCmoves = 1;
|
|
|
|
TCminutes = 15;
|
|
|
|
break;
|
|
|
|
case 9 :
|
|
|
|
TCmoves = 1;
|
|
|
|
TCminutes = 60;
|
|
|
|
break;
|
|
|
|
case 10 :
|
|
|
|
TCmoves = 1;
|
|
|
|
TCminutes = 600;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-22 14:24:54 +00:00
|
|
|
TCflag = (TCmoves > 1);
|
2006-03-14 20:55:59 +00:00
|
|
|
SetTimeControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---- increase playing level ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void cb_levelup ( void ) {
|
2006-03-14 20:55:59 +00:00
|
|
|
if ( Level == 7 )
|
|
|
|
cb_setlevel ( 1 );
|
|
|
|
else
|
|
|
|
cb_setlevel ( Level+1 );
|
2008-09-24 17:48:10 +00:00
|
|
|
rb->splash ( HZ/2 , level_string[Level-1] );
|
2006-02-22 14:24:54 +00:00
|
|
|
};
|
|
|
|
|
2017-01-31 03:28:02 +00:00
|
|
|
#ifdef CHESSBOX_SAVE_FILE_DBG
|
|
|
|
/* Save a debug file with names, variables, and sizes */
|
|
|
|
static void cb_saveposition_dbg ( void )
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
short sq,i,c;
|
|
|
|
unsigned short temp;
|
|
|
|
char buf[32]="\0";
|
|
|
|
int ch_ct = 0;
|
|
|
|
|
|
|
|
rb->splash ( 0 , "Saving debug" );
|
|
|
|
fd = rb->open(CHESSBOX_SAVE_FILE_DBG, O_WRONLY|O_CREAT, 0666);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"computer = %d, %d bytes\n",computer+1,
|
|
|
|
sizeof(computer));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"opponent = %d, %d bytes\n",opponent+1,
|
|
|
|
sizeof(opponent));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"Game50 = %d, %d bytes\n",Game50,
|
|
|
|
sizeof(Game50));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"CastldWht = %d, %d bytes\n",castld[white],
|
|
|
|
sizeof(castld[white]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"CastldBlk = %d, %d bytes\n",castld[black],
|
|
|
|
sizeof(castld[black]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"KngMovedWht = %d, %d bytes\n",kingmoved[white],
|
|
|
|
sizeof(kingmoved[white]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"KngMovedBlk = %d, %d bytes\n",kingmoved[black],
|
|
|
|
sizeof(kingmoved[black]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"WithBook = %d, %d bytes\n",withbook,
|
|
|
|
sizeof(withbook));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"Lvl = %ld, %d bytes\n",Level,
|
|
|
|
sizeof(Level));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"TCflag = %d, %d bytes\n",TCflag,
|
|
|
|
sizeof(TCflag));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"OpTime = %d, %d bytes\n",OperatorTime,
|
|
|
|
sizeof(OperatorTime));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"TmCtlClkWht = %ld, %d bytes\n",
|
|
|
|
TimeControl.clock[white], sizeof(TimeControl.clock[white]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"TmCtlClkBlk = %ld, %d bytes\n",
|
|
|
|
TimeControl.clock[black], sizeof(TimeControl.clock[black]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"TmCtlMovesWht = %d, %d bytes\n",
|
|
|
|
TimeControl.moves[white], sizeof(TimeControl.moves[white]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"TmCtlMovesBlk = %d, %d bytes\n",
|
|
|
|
TimeControl.moves[black], sizeof(TimeControl.moves[black]));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
for (sq = 0; sq < 64; sq++) {
|
|
|
|
if (color[sq] == neutral) c = 0; else c = color[sq]+1;
|
|
|
|
temp = 256*board[sq] + c ;
|
|
|
|
ch_ct = rb->snprintf(buf,31,"sq %02d = %d, %d bytes\n",sq, temp,
|
|
|
|
sizeof(temp));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
}
|
2019-07-15 14:49:55 +00:00
|
|
|
for (i = 0; i < ((GameCnt + 1) & 0xFF); i++) {
|
2017-01-31 03:28:02 +00:00
|
|
|
ch_ct = rb->snprintf(buf,31,"GameCt %d, %d bytes\n",i,
|
|
|
|
sizeof(GameCnt));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
if (GameList[i].color == neutral)
|
|
|
|
{
|
|
|
|
c = 0;
|
|
|
|
ch_ct = rb->snprintf(buf,31,"color = %d, %d bytes\n",c,
|
|
|
|
sizeof(c));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c = GameList[i].color + 1;
|
|
|
|
ch_ct = rb->snprintf(buf,31,"gmove = %d, %d bytes\n",GameList[i].gmove,
|
|
|
|
sizeof(GameList[i].gmove));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"score = %d, %d bytes\n",GameList[i].score,
|
|
|
|
sizeof(GameList[i].score));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"depth = %d, %d bytes\n",GameList[i].depth,
|
|
|
|
sizeof(GameList[i].depth));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"nodes = %ld, %d bytes\n",GameList[i].nodes,
|
|
|
|
sizeof(GameList[i].nodes));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"time = %d, %d bytes\n",GameList[i].time,
|
|
|
|
sizeof(GameList[i].time));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"piece = %d, %d bytes\n",GameList[i].piece,
|
|
|
|
sizeof(GameList[i].piece));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
ch_ct = rb->snprintf(buf,31,"color = %d, %d bytes\n",c,sizeof(c));
|
|
|
|
rb->write(fd, buf, ch_ct);
|
|
|
|
}
|
|
|
|
rb->close(fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
/* ---- Save current position and game history ---- */
|
|
|
|
static void cb_saveposition ( struct pgn_game_node* game ) {
|
2006-03-14 20:55:59 +00:00
|
|
|
int fd;
|
|
|
|
short sq,i,c;
|
|
|
|
unsigned short temp;
|
2019-07-15 14:49:55 +00:00
|
|
|
struct pgn_ply_node *ply;
|
|
|
|
char buf[4];
|
|
|
|
|
2017-01-31 03:28:02 +00:00
|
|
|
#ifdef CHESSBOX_SAVE_FILE_DBG
|
|
|
|
cb_saveposition_dbg();
|
|
|
|
#endif
|
2019-07-15 14:49:55 +00:00
|
|
|
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( 0 , ID2P(LANG_CHESSBOX_SAVING_POSITION) );
|
2006-03-14 20:55:59 +00:00
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
2006-03-14 20:55:59 +00:00
|
|
|
|
|
|
|
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]));
|
|
|
|
|
2006-04-15 11:27:47 +00:00
|
|
|
rb->write(fd, &(withbook), sizeof(withbook));
|
2006-03-14 20:55:59 +00:00
|
|
|
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));
|
|
|
|
}
|
2019-07-15 14:49:55 +00:00
|
|
|
c = GameCnt;
|
|
|
|
rb->write(fd, &(c), sizeof(c));
|
|
|
|
for (i = 0; i < ((GameCnt + 1) & 0xFF); i++) {
|
2006-03-14 20:55:59 +00:00
|
|
|
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));
|
|
|
|
}
|
2019-07-15 14:49:55 +00:00
|
|
|
for (ply=game->first_ply; ply!=NULL; ply=ply->next_node) {
|
|
|
|
buf[0] = ply->column_from + 'a';
|
|
|
|
buf[1] = ply->row_from + '1';
|
|
|
|
buf[2] = ply->column_to + 'a';
|
|
|
|
buf[3] = ply->row_to + '1';
|
|
|
|
rb->write(fd, buf, 4);
|
|
|
|
}
|
2006-03-14 20:55:59 +00:00
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
/* ---- Restore saved position and game history ---- */
|
|
|
|
static struct pgn_game_node* cb_restoreposition ( void ) {
|
2006-03-14 20:55:59 +00:00
|
|
|
int fd;
|
|
|
|
short sq;
|
|
|
|
unsigned short m;
|
2019-07-15 14:49:55 +00:00
|
|
|
short n;
|
|
|
|
char buf[4];
|
|
|
|
struct pgn_game_node* game = pgn_init_game();
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-03-14 20:55:59 +00:00
|
|
|
if ( (fd = rb->open(SAVE_FILE, O_RDONLY)) >= 0 ) {
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( 0 , ID2P(LANG_CHESSBOX_LOADING_POSITION) );
|
2006-03-14 20:55:59 +00:00
|
|
|
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]));
|
|
|
|
|
2006-04-15 11:27:47 +00:00
|
|
|
rb->read(fd, &(withbook), sizeof(withbook));
|
2006-03-14 20:55:59 +00:00
|
|
|
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];
|
|
|
|
}
|
2019-07-15 14:49:55 +00:00
|
|
|
rb->read(fd, &(n), sizeof(n));
|
|
|
|
n++;
|
|
|
|
n &= 0xFF;
|
|
|
|
for (GameCnt = 0; GameCnt < n; GameCnt++) {
|
|
|
|
rb->read(fd, &(GameList[GameCnt].gmove),
|
|
|
|
sizeof(GameList[GameCnt].gmove));
|
2006-03-14 20:55:59 +00:00
|
|
|
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),
|
2019-07-15 14:49:55 +00:00
|
|
|
sizeof(GameList[GameCnt].color));
|
2006-03-14 20:55:59 +00:00
|
|
|
if (GameList[GameCnt].color == 0)
|
|
|
|
GameList[GameCnt].color = neutral;
|
|
|
|
else
|
|
|
|
--GameList[GameCnt].color;
|
|
|
|
}
|
|
|
|
GameCnt--;
|
|
|
|
if (TimeControl.clock[white] > 0)
|
|
|
|
TCflag = true;
|
|
|
|
computer--; opponent--;
|
2019-07-15 14:49:55 +00:00
|
|
|
n = 0;
|
|
|
|
while (rb->read(fd, buf, 4) > 0)
|
|
|
|
pgn_append_ply(game, ((n++) & 1) ? black : white, buf, false);
|
|
|
|
rb->close(fd);
|
2006-03-14 20:55:59 +00:00
|
|
|
}
|
|
|
|
cb_setlevel(Level);
|
|
|
|
InitializeStats();
|
|
|
|
Sdepth = 0;
|
2019-07-15 14:49:55 +00:00
|
|
|
|
|
|
|
return game;
|
2006-03-14 20:55:59 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 16:33:16 +00:00
|
|
|
/* ---- show menu in viewer mode---- */
|
|
|
|
static int cb_menu_viewer(void)
|
|
|
|
{
|
|
|
|
int selection;
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2019-02-06 18:16:58 +00:00
|
|
|
MENUITEM_STRINGLIST(menu,"Chessbox Menu",NULL,
|
|
|
|
ID2P(LANG_CHESSBOX_MENU_RESTART_GAME),
|
|
|
|
ID2P(LANG_CHESSBOX_MENU_SELECT_OTHER_GAME),
|
2019-07-15 14:49:55 +00:00
|
|
|
ID2P(LANG_CHESSBOX_MENU_RESUME_GAME),
|
|
|
|
ID2P(LANG_RETURN),
|
2019-02-06 18:16:58 +00:00
|
|
|
ID2P(LANG_MENU_QUIT));
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
2007-05-29 16:33:16 +00:00
|
|
|
{
|
2019-07-15 14:49:55 +00:00
|
|
|
case 0:
|
|
|
|
return COMMAND_RESTART;
|
|
|
|
case 1:
|
|
|
|
return COMMAND_SELECT;
|
|
|
|
case 3:
|
|
|
|
return COMMAND_RETURN;
|
|
|
|
case 4:
|
|
|
|
return COMMAND_QUIT;
|
2007-05-29 16:33:16 +00:00
|
|
|
}
|
2019-07-15 14:49:55 +00:00
|
|
|
return COMMAND_RESUME;
|
2007-05-29 16:33:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
/* ---- get a command in viewer mode ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static struct cb_command cb_get_viewer_command (void) {
|
2007-05-29 16:33:16 +00:00
|
|
|
int button;
|
|
|
|
struct cb_command result = { 0, {0,0,0,0,0}, 0 };
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2007-05-29 16:33:16 +00:00
|
|
|
/* main loop */
|
|
|
|
while ( true ) {
|
|
|
|
button = rb->button_get(true);
|
|
|
|
switch (button) {
|
2018-12-23 03:16:32 +00:00
|
|
|
case SYS_POWEROFF:
|
|
|
|
cb_sysevent = button;
|
2007-05-29 16:33:16 +00:00
|
|
|
#ifdef CB_RC_QUIT
|
|
|
|
case CB_RC_QUIT:
|
2018-12-23 03:16:32 +00:00
|
|
|
#endif
|
2007-05-29 16:33:16 +00:00
|
|
|
result.type = COMMAND_QUIT;
|
|
|
|
return result;
|
2015-04-22 22:07:27 +00:00
|
|
|
#ifdef CB_RESTART
|
|
|
|
case CB_RESTART:
|
|
|
|
result.type = COMMAND_RESTART;
|
|
|
|
return result;
|
2007-05-29 16:33:16 +00:00
|
|
|
#endif
|
|
|
|
case CB_MENU:
|
|
|
|
result.type = cb_menu_viewer();
|
|
|
|
return result;
|
|
|
|
case CB_LEFT:
|
|
|
|
result.type = COMMAND_PREV;
|
|
|
|
return result;
|
|
|
|
case CB_RIGHT:
|
|
|
|
result.type = COMMAND_NEXT;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---- viewer main loop ---- */
|
2019-07-15 14:49:55 +00:00
|
|
|
static bool cb_start_viewer(const char* filename){
|
2007-05-29 16:33:16 +00:00
|
|
|
struct pgn_game_node *first_game, *selected_game;
|
|
|
|
struct pgn_ply_node *curr_ply;
|
|
|
|
bool exit_game = false;
|
|
|
|
bool exit_viewer = false;
|
2019-07-15 14:49:55 +00:00
|
|
|
bool exit_app = false;
|
2007-05-29 16:33:16 +00:00
|
|
|
struct cb_command command;
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
first_game = pgn_list_games(filename);
|
2007-05-29 16:33:16 +00:00
|
|
|
if (first_game == NULL){
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( HZ*2 , ID2P(LANG_CHESSBOX_NO_GAMES) );
|
2019-07-15 14:49:55 +00:00
|
|
|
return exit_app;
|
2007-05-29 16:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2009-01-16 10:34:40 +00:00
|
|
|
selected_game = pgn_show_game_list(first_game);
|
2007-05-29 16:33:16 +00:00
|
|
|
if (selected_game == NULL){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_parse_game(filename, selected_game);
|
2007-05-29 16:33:16 +00:00
|
|
|
if (selected_game->first_ply != NULL) {
|
|
|
|
|
|
|
|
/* init board */
|
|
|
|
GNUChess_Initialize();
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2007-05-29 16:33:16 +00:00
|
|
|
/* draw the board */
|
|
|
|
cb_drawboard();
|
|
|
|
|
|
|
|
curr_ply = selected_game->first_ply;
|
|
|
|
exit_game = false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
command = cb_get_viewer_command ();
|
|
|
|
switch (command.type) {
|
|
|
|
case COMMAND_PREV:
|
|
|
|
/* unapply the previous ply */
|
|
|
|
if (curr_ply->prev_node != NULL){
|
|
|
|
curr_ply = curr_ply->prev_node;
|
|
|
|
} else {
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( HZ*2 , ID2P(LANG_CHESSBOX_GAME_BEGINNING) );
|
2007-05-29 16:33:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-31 00:07:47 +00:00
|
|
|
board[locn[curr_ply->row_from][curr_ply->column_from]]
|
2007-05-29 16:33:16 +00:00
|
|
|
= board[locn[curr_ply->row_to][curr_ply->column_to]];
|
|
|
|
color[locn[curr_ply->row_from][curr_ply->column_from]]
|
|
|
|
= color[locn[curr_ply->row_to][curr_ply->column_to]];
|
|
|
|
board[locn[curr_ply->row_to][curr_ply->column_to]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_to][curr_ply->column_to]] = neutral;
|
|
|
|
if (curr_ply->taken_piece != no_piece && !curr_ply->enpassant){
|
|
|
|
board[locn[curr_ply->row_to][curr_ply->column_to]]
|
|
|
|
= curr_ply->taken_piece;
|
|
|
|
color[locn[curr_ply->row_to][curr_ply->column_to]]
|
|
|
|
= ((curr_ply->player==white)?black:white);
|
|
|
|
}
|
|
|
|
if (curr_ply->castle){
|
|
|
|
if (curr_ply->column_to == 6){
|
|
|
|
/* castling kingside */
|
|
|
|
board[locn[curr_ply->row_to][7]] = rook;
|
|
|
|
color[locn[curr_ply->row_to][7]] = curr_ply->player;
|
|
|
|
board[locn[curr_ply->row_to][5]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_to][5]] = neutral;
|
|
|
|
} else {
|
|
|
|
/* castling queenside */
|
|
|
|
board[locn[curr_ply->row_to][0]] = rook;
|
|
|
|
color[locn[curr_ply->row_to][0]] = curr_ply->player;
|
|
|
|
board[locn[curr_ply->row_to][3]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_to][3]] = neutral;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (curr_ply->enpassant){
|
|
|
|
board[locn[curr_ply->row_from][curr_ply->column_to]] = pawn;
|
|
|
|
color[locn[curr_ply->row_from][curr_ply->column_to]]
|
|
|
|
= ((curr_ply->player==white)?black:white);
|
|
|
|
}
|
|
|
|
if (curr_ply->promotion){
|
|
|
|
board[locn[curr_ply->row_from][curr_ply->column_from]] = pawn;
|
|
|
|
color[locn[curr_ply->row_from][curr_ply->column_from]]
|
|
|
|
= curr_ply->player;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_NEXT:
|
|
|
|
/* apply the current move */
|
|
|
|
if (curr_ply->player == neutral){
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( HZ*2 , ID2P(LANG_CHESSBOX_GAME_END) );
|
2007-05-29 16:33:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu) {
|
|
|
|
rb->talk_id (VOICE_WHITE + curr_ply->player, false);
|
|
|
|
if (curr_ply->castle){
|
|
|
|
rb->talk_id (VOICE_CHESSBOX_CASTLE, true);
|
|
|
|
if (curr_ply->column_to == 6){
|
|
|
|
rb->talk_id (VOICE_CHESSBOX_KINGSIDE, true);
|
|
|
|
} else {
|
|
|
|
rb->talk_id (VOICE_CHESSBOX_QUEENSIDE, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rb->talk_id (VOICE_PAWN +
|
|
|
|
board[locn[curr_ply->row_from]
|
|
|
|
[curr_ply->column_from]]
|
|
|
|
- 1, true);
|
|
|
|
rb->talk_id (VOICE_CHAR_A + curr_ply->column_from,
|
|
|
|
true);
|
|
|
|
rb->talk_id (VOICE_ONE + curr_ply->row_from, true);
|
|
|
|
if (board[locn[curr_ply->row_to]
|
|
|
|
[curr_ply->column_to]] != no_piece) {
|
|
|
|
rb->talk_id (VOICE_CHESSBOX_CAPTURES, true);
|
|
|
|
rb->talk_id (VOICE_PAWN +
|
|
|
|
board[locn[curr_ply->row_to]
|
|
|
|
[curr_ply->column_to]]
|
|
|
|
- 1, true);
|
|
|
|
}
|
|
|
|
rb->talk_id (VOICE_CHAR_A + curr_ply->column_to,
|
|
|
|
true);
|
|
|
|
rb->talk_id (VOICE_ONE + curr_ply->row_to, true);
|
|
|
|
}
|
|
|
|
}
|
2007-05-29 16:33:16 +00:00
|
|
|
board[locn[curr_ply->row_to][curr_ply->column_to]]
|
|
|
|
= board[locn[curr_ply->row_from][curr_ply->column_from]];
|
|
|
|
color[locn[curr_ply->row_to][curr_ply->column_to]]
|
|
|
|
= color[locn[curr_ply->row_from][curr_ply->column_from]];
|
|
|
|
board[locn[curr_ply->row_from][curr_ply->column_from]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_from][curr_ply->column_from]] = neutral;
|
|
|
|
if (curr_ply->castle){
|
|
|
|
if (curr_ply->column_to == 6){
|
|
|
|
/* castling kingside */
|
|
|
|
board[locn[curr_ply->row_to][5]] = rook;
|
|
|
|
color[locn[curr_ply->row_to][5]] = curr_ply->player;
|
|
|
|
board[locn[curr_ply->row_to][7]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_to][7]] = neutral;
|
|
|
|
} else {
|
|
|
|
/* castling queenside */
|
|
|
|
board[locn[curr_ply->row_to][3]] = rook;
|
|
|
|
color[locn[curr_ply->row_to][3]] = curr_ply->player;
|
|
|
|
board[locn[curr_ply->row_to][0]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_to][0]] = neutral;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (curr_ply->enpassant){
|
|
|
|
board[locn[curr_ply->row_from][curr_ply->column_to]] = no_piece;
|
|
|
|
color[locn[curr_ply->row_from][curr_ply->column_to]] = neutral;
|
|
|
|
}
|
|
|
|
if (curr_ply->promotion){
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu)
|
|
|
|
rb->talk_id (VOICE_PAWN +
|
|
|
|
curr_ply->promotion_piece - 1,
|
|
|
|
true);
|
2007-05-29 16:33:16 +00:00
|
|
|
board[locn[curr_ply->row_to][curr_ply->column_to]]
|
|
|
|
= curr_ply->promotion_piece;
|
|
|
|
color[locn[curr_ply->row_to][curr_ply->column_to]]
|
|
|
|
= curr_ply->player;
|
|
|
|
}
|
|
|
|
if (curr_ply->next_node != NULL){
|
|
|
|
curr_ply = curr_ply->next_node;
|
|
|
|
}
|
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_RESTART:
|
|
|
|
GNUChess_Initialize();
|
|
|
|
cb_drawboard();
|
|
|
|
curr_ply = selected_game->first_ply;
|
2015-04-22 22:07:27 +00:00
|
|
|
break;
|
2007-05-29 16:33:16 +00:00
|
|
|
case COMMAND_SELECT:
|
|
|
|
exit_game = true;
|
|
|
|
break;
|
|
|
|
case COMMAND_QUIT:
|
2019-07-15 14:49:55 +00:00
|
|
|
exit_app = true;
|
2021-07-24 14:39:01 +00:00
|
|
|
/* fallthrough */
|
2019-07-15 14:49:55 +00:00
|
|
|
case COMMAND_RETURN:
|
2007-05-29 16:33:16 +00:00
|
|
|
exit_viewer = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!exit_game && !exit_viewer);
|
|
|
|
} else {
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( HZ*2 , ID2P(LANG_CHESSBOX_PGN_PARSE_ERROR));
|
2007-05-29 16:33:16 +00:00
|
|
|
}
|
|
|
|
} while (!exit_viewer);
|
2019-07-15 14:49:55 +00:00
|
|
|
return exit_app;
|
2007-05-29 16:33:16 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 22:12:34 +00:00
|
|
|
/* ---- show menu ---- */
|
|
|
|
static int cb_menu(void)
|
|
|
|
{
|
|
|
|
int selection;
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2019-02-06 18:16:58 +00:00
|
|
|
MENUITEM_STRINGLIST(menu,"Chessbox Menu",NULL,
|
|
|
|
ID2P(LANG_CHESSBOX_MENU_NEW_GAME),
|
|
|
|
ID2P(LANG_CHESSBOX_MENU_RESUME_GAME),
|
|
|
|
ID2P(LANG_CHESSBOX_MENU_SAVE_GAME),
|
|
|
|
ID2P(LANG_CHESSBOX_MENU_RESTORE_GAME),
|
2019-07-15 14:49:55 +00:00
|
|
|
ID2P(LANG_CHESSBOX_MENU_VIEW_GAMES),
|
2009-02-26 21:24:29 +00:00
|
|
|
#ifdef HAVE_PLAYBACK_CONTROL
|
2019-02-06 18:16:58 +00:00
|
|
|
ID2P(LANG_PLAYBACK_CONTROL),
|
2009-02-26 17:46:01 +00:00
|
|
|
#endif
|
2019-02-06 18:16:58 +00:00
|
|
|
ID2P(LANG_MENU_QUIT));
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
switch(rb->do_menu(&menu, &selection, NULL, false))
|
2007-05-18 22:12:34 +00:00
|
|
|
{
|
2019-07-15 14:49:55 +00:00
|
|
|
case 0:
|
|
|
|
return COMMAND_RESTART;
|
|
|
|
case 2:
|
|
|
|
return COMMAND_SAVE;
|
|
|
|
case 3:
|
|
|
|
return COMMAND_RESTORE;
|
|
|
|
case 4:
|
|
|
|
return COMMAND_VIEW;
|
|
|
|
case 5:
|
2009-02-26 21:24:29 +00:00
|
|
|
#ifdef HAVE_PLAYBACK_CONTROL
|
2019-07-15 14:49:55 +00:00
|
|
|
playback_control(NULL);
|
|
|
|
break;
|
|
|
|
case 6:
|
2009-02-26 17:46:01 +00:00
|
|
|
#endif
|
2019-07-15 14:49:55 +00:00
|
|
|
return COMMAND_QUIT;
|
2007-05-18 22:12:34 +00:00
|
|
|
}
|
2019-07-15 14:49:55 +00:00
|
|
|
return COMMAND_RESUME;
|
2007-05-18 22:12:34 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 16:33:16 +00:00
|
|
|
/* ---- get a command in game mode ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static struct cb_command cb_getcommand (void) {
|
2006-03-14 20:55:59 +00:00
|
|
|
static short x = 4 , y = 3 ;
|
2006-03-03 15:01:37 +00:00
|
|
|
short c , r , l;
|
2011-05-01 14:44:20 +00:00
|
|
|
int button;
|
|
|
|
#if defined(CB_PLAY_PRE) || defined(CB_SELECT_PRE)
|
|
|
|
int lastbutton = BUTTON_NONE;
|
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
int marked = false , from_marked = false ;
|
|
|
|
short marked_x = 0 , marked_y = 0 ;
|
|
|
|
struct cb_command result = { 0, {0,0,0,0,0}, 0 };
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
cb_switch ( x , y );
|
|
|
|
/* main loop */
|
|
|
|
while ( true ) {
|
|
|
|
button = rb->button_get(true);
|
|
|
|
switch (button) {
|
2018-12-23 03:16:32 +00:00
|
|
|
case SYS_POWEROFF:
|
|
|
|
cb_sysevent = button;
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef CB_RC_QUIT
|
|
|
|
case CB_RC_QUIT:
|
2018-12-23 03:16:32 +00:00
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
result.type = COMMAND_QUIT;
|
|
|
|
return result;
|
2015-04-22 22:07:27 +00:00
|
|
|
#ifdef CB_RESTART
|
|
|
|
case CB_RESTART:
|
|
|
|
result.type = COMMAND_RESTART;
|
|
|
|
return result;
|
2007-05-18 22:12:34 +00:00
|
|
|
#endif
|
|
|
|
case CB_MENU:
|
|
|
|
result.type = cb_menu();
|
|
|
|
return result;
|
2006-03-03 15:01:37 +00:00
|
|
|
case CB_LEVEL:
|
|
|
|
result.type = COMMAND_LEVEL;
|
|
|
|
return result;
|
|
|
|
case CB_PLAY:
|
2006-02-24 00:51:37 +00:00
|
|
|
#ifdef CB_PLAY_PRE
|
|
|
|
if (lastbutton != CB_PLAY_PRE)
|
|
|
|
break;
|
2015-07-19 23:50:26 +00:00
|
|
|
/* fallthrough */
|
|
|
|
#endif
|
|
|
|
#ifdef CB_PLAY_ALT
|
|
|
|
case CB_PLAY_ALT:
|
2006-02-24 00:51:37 +00:00
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
result.type = COMMAND_PLAY;
|
|
|
|
return result;
|
|
|
|
case CB_UP:
|
2015-04-22 22:07:27 +00:00
|
|
|
#ifdef CB_SCROLL_UP
|
|
|
|
case CB_SCROLL_UP:
|
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
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 ;
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu) {
|
|
|
|
cb_talk(x, y);
|
|
|
|
rb->talk_id(VOICE_MARKED, true);
|
|
|
|
}
|
2006-03-03 15:01:37 +00:00
|
|
|
} else {
|
|
|
|
from_marked = false ;
|
|
|
|
cb_switch ( x , y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CB_DOWN:
|
2015-04-22 22:07:27 +00:00
|
|
|
#ifdef CB_SCROLL_DOWN
|
|
|
|
case CB_SCROLL_DOWN:
|
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
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 ;
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu) {
|
|
|
|
cb_talk(x, y);
|
|
|
|
rb->talk_id(VOICE_MARKED, true);
|
|
|
|
}
|
2006-03-03 15:01:37 +00:00
|
|
|
} else {
|
|
|
|
from_marked = false ;
|
|
|
|
cb_switch ( x , y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CB_LEFT:
|
2015-04-22 22:07:27 +00:00
|
|
|
#ifdef CB_SCROLL_LEFT
|
|
|
|
case CB_SCROLL_LEFT:
|
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
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 ;
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu) {
|
|
|
|
cb_talk(x, y);
|
|
|
|
rb->talk_id(VOICE_MARKED, true);
|
|
|
|
}
|
2006-03-03 15:01:37 +00:00
|
|
|
} else {
|
|
|
|
from_marked = false ;
|
|
|
|
cb_switch ( x , y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CB_RIGHT:
|
2015-04-22 22:07:27 +00:00
|
|
|
#ifdef CB_SCROLL_RIGHT
|
|
|
|
case CB_SCROLL_RIGHT:
|
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
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 ;
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu) {
|
|
|
|
cb_talk(x, y);
|
|
|
|
rb->talk_id(VOICE_MARKED, true);
|
|
|
|
}
|
2006-03-03 15:01:37 +00:00
|
|
|
} else {
|
|
|
|
from_marked = false ;
|
|
|
|
cb_switch ( x , y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CB_SELECT:
|
2006-02-24 00:51:37 +00:00
|
|
|
#ifdef CB_SELECT_PRE
|
|
|
|
if (lastbutton != CB_SELECT_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
if ( !marked ) {
|
|
|
|
xy2cr ( x , y , &c , &r );
|
2006-02-22 14:24:54 +00:00
|
|
|
l = locn[r][c];
|
|
|
|
if ( ( color[l]!=computer ) && ( board[l]!=no_piece ) ) {
|
2006-03-03 15:01:37 +00:00
|
|
|
marked = true;
|
|
|
|
from_marked = true ;
|
|
|
|
marked_x = x;
|
|
|
|
marked_y = y;
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu)
|
|
|
|
rb->talk_id(VOICE_MARKED, false);
|
2006-03-03 15:01:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( ( marked_x == x ) && ( marked_y == y ) ) {
|
|
|
|
marked = false;
|
|
|
|
from_marked = false;
|
2019-02-06 18:16:58 +00:00
|
|
|
if (rb->global_settings->talk_menu)
|
|
|
|
rb->talk_id(VOICE_UNMARKED, false);
|
2006-03-03 15:01:37 +00:00
|
|
|
} 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;
|
|
|
|
}
|
2011-05-01 14:44:20 +00:00
|
|
|
#if defined(CB_PLAY_PRE) || defined(CB_SELECT_PRE)
|
2006-03-03 15:01:37 +00:00
|
|
|
if (button != BUTTON_NONE)
|
2006-02-24 00:51:37 +00:00
|
|
|
lastbutton = button;
|
2011-05-01 14:44:20 +00:00
|
|
|
#endif
|
2006-03-03 15:01:37 +00:00
|
|
|
}
|
2006-02-22 14:24:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-06 18:16:58 +00:00
|
|
|
/* Talk a move */
|
|
|
|
static void talk_move(char *move_buffer)
|
|
|
|
{
|
|
|
|
if (rb->global_settings->talk_menu) {
|
|
|
|
rb->talk_id (VOICE_PAWN +
|
|
|
|
board[locn[move_buffer[3]-'1'][move_buffer[2]-'a']] - 1,
|
|
|
|
false);
|
|
|
|
rb->talk_id(VOICE_CHAR_A + move_buffer[0] - 'a', true);
|
|
|
|
rb->talk_id(VOICE_ONE + move_buffer[1] - '1', true);
|
|
|
|
rb->talk_id(VOICE_CHAR_A + move_buffer[2] - 'a', true);
|
|
|
|
rb->talk_id(VOICE_ONE + move_buffer[3] - '1', true);
|
|
|
|
if (move_buffer[4] == '+' && !mate) {
|
|
|
|
rb->talk_id(VOICE_CHESSBOX_CHECK, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-29 16:33:16 +00:00
|
|
|
/* ---- game main loop ---- */
|
2011-12-31 20:29:08 +00:00
|
|
|
static void cb_play_game(void) {
|
2006-03-03 15:01:37 +00:00
|
|
|
struct cb_command command;
|
2007-09-02 10:11:46 +00:00
|
|
|
struct pgn_game_node *game;
|
|
|
|
char move_buffer[20];
|
2007-05-29 16:33:16 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
/* init status */
|
|
|
|
bool exit = false;
|
2006-02-22 14:24:54 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
/* load opening book, soon */
|
2006-11-15 06:14:27 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
/* init board */
|
|
|
|
GNUChess_Initialize();
|
2007-09-02 10:11:46 +00:00
|
|
|
|
2006-03-14 20:55:59 +00:00
|
|
|
/* restore saved position, if saved */
|
2019-07-15 14:49:55 +00:00
|
|
|
game = cb_restoreposition();
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
/* draw the board */
|
|
|
|
/* I don't like configscreens, start game inmediatly */
|
|
|
|
cb_drawboard();
|
2007-05-29 16:33:16 +00:00
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
while (!exit) {
|
|
|
|
if ( mate ) {
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->talk_force_enqueue_next();
|
|
|
|
rb->splash ( HZ*3 , ID2P(LANG_CHESSBOX_CHECKMATE) );
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->button_get(true);
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_store_game(game);
|
2006-03-03 15:01:37 +00:00
|
|
|
GNUChess_Initialize();
|
2009-01-16 10:34:40 +00:00
|
|
|
game = pgn_init_game();
|
2006-03-03 15:01:37 +00:00
|
|
|
cb_drawboard();
|
|
|
|
}
|
|
|
|
command = cb_getcommand ();
|
|
|
|
switch (command.type) {
|
|
|
|
case COMMAND_MOVE:
|
2007-09-02 10:11:46 +00:00
|
|
|
if ( ! VerifyMove (opponent, command.mv_s , 0 , &command.mv, move_buffer ) ) {
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( HZ/2 , ID2P(LANG_CHESSBOX_ILLEGAL_MOVE) );
|
2006-03-03 15:01:37 +00:00
|
|
|
cb_drawboard();
|
|
|
|
} else {
|
|
|
|
cb_drawboard();
|
2007-09-02 10:11:46 +00:00
|
|
|
|
|
|
|
/* Add the ply to the PGN history (in algebraic notation) */
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_append_ply(game, opponent, move_buffer, mate);
|
2007-09-02 10:11:46 +00:00
|
|
|
|
2019-02-06 18:16:58 +00:00
|
|
|
talk_move(move_buffer);
|
|
|
|
rb->splash ( 0 , ID2P(LANG_CHESSBOX_THINKING) );
|
2006-02-22 14:24:54 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->cpu_boost ( true );
|
2006-02-22 14:24:54 +00:00
|
|
|
#endif
|
2007-05-29 16:33:16 +00:00
|
|
|
SelectMove ( computer , 0 , cb_wt_callback, move_buffer);
|
2006-02-22 14:24:54 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->cpu_boost ( false );
|
2006-02-22 14:24:54 +00:00
|
|
|
#endif
|
2007-09-02 10:11:46 +00:00
|
|
|
/* Add the ply to the PGN history (in algebraic notation) and check
|
|
|
|
* for the result of the game which is only calculated in SelectMove
|
|
|
|
*/
|
|
|
|
if (move_buffer[0] != '\0'){
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_append_ply(game, computer, move_buffer, mate);
|
2019-02-06 18:16:58 +00:00
|
|
|
talk_move(move_buffer);
|
2007-09-02 10:11:46 +00:00
|
|
|
} else {
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_set_result(game, mate);
|
2007-09-02 10:11:46 +00:00
|
|
|
}
|
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
if ( wt_command == COMMAND_QUIT ) {
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cb_drawboard();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case COMMAND_RESTART:
|
|
|
|
GNUChess_Initialize();
|
2009-01-16 10:34:40 +00:00
|
|
|
game = pgn_init_game();
|
2006-03-03 15:01:37 +00:00
|
|
|
cb_drawboard();
|
|
|
|
break;
|
2007-05-18 22:12:34 +00:00
|
|
|
case COMMAND_RESUME:
|
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_SAVE:
|
2019-07-15 14:49:55 +00:00
|
|
|
cb_saveposition(game);
|
2007-05-18 22:12:34 +00:00
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_RESTORE:
|
|
|
|
/* watch out, it will reset the game if no previous game was saved! */
|
|
|
|
|
|
|
|
/* init board */
|
|
|
|
GNUChess_Initialize();
|
2007-09-02 10:11:46 +00:00
|
|
|
|
2007-05-18 22:12:34 +00:00
|
|
|
/* restore saved position, if saved */
|
2019-07-15 14:49:55 +00:00
|
|
|
game = cb_restoreposition();
|
2007-05-18 22:12:34 +00:00
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_VIEW:
|
|
|
|
if (rb->file_exists(pgn_file)) {
|
|
|
|
cb_saveposition(game);
|
|
|
|
if (cb_start_viewer(pgn_file))
|
|
|
|
return;
|
|
|
|
GNUChess_Initialize();
|
|
|
|
game = cb_restoreposition();
|
|
|
|
}else{
|
|
|
|
rb->splash ( HZ*2 , ID2P(LANG_CHESSBOX_NO_GAMES) );
|
|
|
|
}
|
2007-05-18 22:12:34 +00:00
|
|
|
cb_drawboard();
|
|
|
|
break;
|
2006-03-03 15:01:37 +00:00
|
|
|
case COMMAND_PLAY:
|
2007-05-18 22:12:34 +00:00
|
|
|
if (opponent == white) {
|
|
|
|
opponent = black;
|
|
|
|
computer = white;
|
|
|
|
} else {
|
|
|
|
opponent = white;
|
|
|
|
computer = black;
|
|
|
|
}
|
2019-02-06 18:16:58 +00:00
|
|
|
rb->splash ( 0 , ID2P(LANG_CHESSBOX_THINKING) );
|
2007-08-03 21:59:41 +00:00
|
|
|
ElapsedTime(1);
|
2006-02-22 14:24:54 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->cpu_boost ( true );
|
2006-02-22 14:24:54 +00:00
|
|
|
#endif
|
2007-05-29 16:33:16 +00:00
|
|
|
SelectMove ( computer , 0 , cb_wt_callback , move_buffer );
|
2006-02-22 14:24:54 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2006-03-03 15:01:37 +00:00
|
|
|
rb->cpu_boost ( false );
|
2006-02-22 14:24:54 +00:00
|
|
|
#endif
|
2007-09-02 10:11:46 +00:00
|
|
|
|
|
|
|
/* Add the ply to the PGN history (in algebraic notation) and check
|
|
|
|
* for the result of the game which is only calculated in SelectMove
|
|
|
|
*/
|
|
|
|
if (move_buffer[0] != '\0'){
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_append_ply(game, computer, move_buffer, mate);
|
2019-02-06 18:16:58 +00:00
|
|
|
talk_move(move_buffer);
|
2007-09-02 10:11:46 +00:00
|
|
|
} else {
|
2009-01-16 10:34:40 +00:00
|
|
|
pgn_set_result(game, mate);
|
2007-09-02 10:11:46 +00:00
|
|
|
}
|
|
|
|
|
2006-03-03 15:01:37 +00:00
|
|
|
if ( wt_command == COMMAND_QUIT ) {
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_LEVEL:
|
|
|
|
cb_levelup ( );
|
|
|
|
cb_drawboard();
|
|
|
|
break;
|
|
|
|
case COMMAND_QUIT:
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
cb_saveposition(game);
|
2007-05-29 16:33:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* plugin entry point.
|
|
|
|
******************************************************************************/
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter) {
|
2017-01-31 00:07:47 +00:00
|
|
|
|
2007-05-29 16:33:16 +00:00
|
|
|
/* plugin init */
|
|
|
|
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
2018-12-23 03:16:32 +00:00
|
|
|
cb_sysevent = 0;
|
2007-05-29 16:33:16 +00:00
|
|
|
|
|
|
|
/* end of plugin init */
|
|
|
|
|
2017-01-31 00:07:47 +00:00
|
|
|
/* if the plugin was invoked as a viewer, parse the file and show the game list
|
2007-05-29 16:33:16 +00:00
|
|
|
* else, start playing a game
|
|
|
|
*/
|
|
|
|
if (parameter != NULL) {
|
|
|
|
cb_start_viewer((char *)parameter);
|
|
|
|
} else {
|
|
|
|
cb_play_game();
|
|
|
|
}
|
|
|
|
|
2019-07-15 14:49:55 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
|
|
|
|
2018-12-23 03:16:32 +00:00
|
|
|
if (cb_sysevent)
|
|
|
|
rb->default_event_handler(cb_sysevent);
|
|
|
|
|
2006-02-22 14:24:54 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|