···77* \/ \/ \/ \/ \/
88* $Id$
99*
1010-* Copyright (C) 2006 Miguel A. Arévalo
1010+* Copyright (C) 2006 Miguel A. Arévalo
1111* Color graphics from eboard
1212* GNUChess v2 chess engine Copyright (c) 1988 John Stanback
1313*
···2020* KIND, either express or implied.
2121*
2222****************************************************************************/
2323-2323+2424#include "plugin.h"
25252626#if (MEMORYSIZE > 8) /* Lowmem doesn't have playback in chessbox */
···80808181/* level+1's string */
8282const char *level_string[] = { "Level 1: 60 moves / 5 min" ,
8383- "Level 2: 60 moves / 15 min" ,
8383+ "Level 2: 60 moves / 15 min" ,
8484 "Level 3: 60 moves / 30 min" ,
8585 "Level 4: 40 moves / 30 min" ,
8686 "Level 5: 40 moves / 60 min" ,
···120120 short r , c , x , y ;
121121 short l , piece , p_color ;
122122 int b_color=1;
123123-123123+124124 rb->lcd_clear_display();
125125126126 for (r = 0; r < 8; r++) {
···132132 if ( piece == no_piece ) {
133133 rb->lcd_bitmap_part ( chessbox_pieces , 0 ,
134134 TILE_HEIGHT * b_color ,
135135- STRIDE( SCREEN_MAIN,
136136- BMPWIDTH_chessbox_pieces,
135135+ STRIDE( SCREEN_MAIN,
136136+ BMPWIDTH_chessbox_pieces,
137137 BMPHEIGHT_chessbox_pieces) ,
138138 XOFS + x*TILE_WIDTH ,
139139 YOFS + ( 7 - y )*TILE_HEIGHT ,
···146146 4 * TILE_HEIGHT * ( piece - 1 ) +
147147 2 * TILE_HEIGHT * p_color +
148148 TILE_HEIGHT * b_color ,
149149- STRIDE( SCREEN_MAIN,
150150- BMPWIDTH_chessbox_pieces,
149149+ STRIDE( SCREEN_MAIN,
150150+ BMPWIDTH_chessbox_pieces,
151151 BMPHEIGHT_chessbox_pieces) ,
152152 XOFS + x*TILE_WIDTH ,
153153 YOFS + (7 - y)*TILE_HEIGHT ,
···158158 }
159159 b_color = (b_color == 1) ? 0 : 1 ;
160160 }
161161-161161+162162 /* draw board limits */
163163#if (LCD_WIDTH > TILE_WIDTH*8) && (LCD_HEIGHT > TILE_HEIGHT*8)
164164 rb->lcd_drawrect(XOFS - 1, YOFS - 1, TILE_WIDTH*8 + 2, TILE_HEIGHT*8 + 2);
···186186/* ---- callback for capturing interaction while thinking ---- */
187187static void cb_wt_callback ( void ) {
188188 int button = BUTTON_NONE;
189189-189189+190190 wt_command = COMMAND_NOP;
191191 button = rb->button_get(false);
192192 switch (button) {
···270270 int fd;
271271 short sq,i,c;
272272 unsigned short temp;
273273-273273+274274 rb->splash ( 0 , "Saving position" );
275275276276 fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT, 0666);
···323323 int fd;
324324 short sq;
325325 unsigned short m;
326326-326326+327327 if ( (fd = rb->open(SAVE_FILE, O_RDONLY)) >= 0 ) {
328328 rb->splash ( 0 , "Loading position" );
329329 rb->read(fd, &(computer), sizeof(computer));
···393393 int selection;
394394 int result = 0;
395395 bool menu_quit = false;
396396-396396+397397 MENUITEM_STRINGLIST(menu,"Chessbox Menu",NULL,"Restart Game",
398398- "Select Other Game", "Quit");
399399-398398+ "Select Other Game", "Quit");
399399+400400 while(!menu_quit)
401401 {
402402 switch(rb->do_menu(&menu, &selection, NULL, false))
···422422static struct cb_command cb_get_viewer_command (void) {
423423 int button;
424424 struct cb_command result = { 0, {0,0,0,0,0}, 0 };
425425-425425+426426 /* main loop */
427427 while ( true ) {
428428 button = rb->button_get(true);
···476476477477 /* init board */
478478 GNUChess_Initialize();
479479-479479+480480 /* draw the board */
481481 cb_drawboard();
482482···494494 rb->splash ( HZ*2 , "At the begining of the game" );
495495 break;
496496 }
497497- board[locn[curr_ply->row_from][curr_ply->column_from]]
497497+ board[locn[curr_ply->row_from][curr_ply->column_from]]
498498 = board[locn[curr_ply->row_to][curr_ply->column_to]];
499499 color[locn[curr_ply->row_from][curr_ply->column_from]]
500500 = color[locn[curr_ply->row_to][curr_ply->column_to]];
···601601 int selection;
602602 int result = 0;
603603 bool menu_quit = false;
604604-604604+605605 MENUITEM_STRINGLIST(menu,"Chessbox Menu",NULL,"New Game","Resume Game",
606606 "Save Game", "Restore Game",
607607#ifdef HAVE_PLAYBACK_CONTROL
608608 "Playback Control",
609609#endif
610610- "Quit");
611611-610610+ "Quit");
611611+612612 while(!menu_quit)
613613 {
614614 switch(rb->do_menu(&menu, &selection, NULL, false))
···654654 int marked = false , from_marked = false ;
655655 short marked_x = 0 , marked_y = 0 ;
656656 struct cb_command result = { 0, {0,0,0,0,0}, 0 };
657657-657657+658658 cb_switch ( x , y );
659659 /* main loop */
660660 while ( true ) {
···815815816816 /* init PGN history data structures */
817817 game = pgn_init_game();
818818-818818+819819 /* restore saved position, if saved */
820820 cb_restoreposition();
821821 /* TODO: save/restore the PGN history of unfinished games */
822822-822822+823823 /* draw the board */
824824 /* I don't like configscreens, start game inmediatly */
825825 cb_drawboard();
···937937 break;
938938 }
939939 }
940940-940940+941941 cb_saveposition();
942942 /* TODO: save/restore the PGN history of unfinished games */
943943 rb->lcd_setfont(FONT_UI);
···948948* plugin entry point.
949949******************************************************************************/
950950enum plugin_status plugin_start(const void* parameter) {
951951-951951+952952 /* plugin init */
953953954954#if LCD_DEPTH > 1
···957957958958 /* end of plugin init */
959959960960- /* if the plugin was invoked as a viewer, parse the file and show the game list
960960+ /* if the plugin was invoked as a viewer, parse the file and show the game list
961961 * else, start playing a game
962962 */
963963 if (parameter != NULL) {
+3-3
apps/plugins/chessbox/chessbox_pgn.c
···77* \/ \/ \/ \/ \/
88* $Id$
99*
1010-* Copyright (C) 2007 Mauricio Peccorini
1010+* Copyright (C) 2007 Mauricio Peccorini
1111*
1212* This program is free software; you can redistribute it and/or
1313* modify it under the terms of the GNU General Public License
···417417 && ply->column_to + kn_offs[i][1] >= 0 && ply->column_to + kn_offs[i][1] <= 7
418418 && board[locn[ply->row_to + kn_offs[i][0]][ply->column_to + kn_offs[i][1]]] == knight
419419 && color[locn[ply->row_to + kn_offs[i][0]][ply->column_to + kn_offs[i][1]]] == ply->player
420420- && (ply->row_to + kn_offs[i][0] != ply->row_from
420420+ && (ply->row_to + kn_offs[i][0] != ply->row_from
421421 || ply->column_to + kn_offs[i][1] != ply->column_from)){
422422 if (ply->row_to + kn_offs[i][0] != ply->row_from){
423423 unambiguous_position = '1' + ply->row_from;
···878878 /* leave a blank line between the tag section and the game section */
879879 rb->fdprintf(fhandler,"\n\n");
880880881881- rb->close(fhandler);
881881+ rb->close(fhandler);
882882}
+1-1
apps/plugins/chessbox/chessbox_pgn.h
···77* \/ \/ \/ \/ \/
88* $Id$
99*
1010-* Copyright (C) 2007 Mauricio Peccorini
1010+* Copyright (C) 2007 Mauricio Peccorini
1111*
1212* This program is free software; you can redistribute it and/or
1313* modify it under the terms of the GNU General Public License
+138-138
apps/plugins/chessbox/gnuchess.c
···128128 40,41,42,43,44,45,46,47,-1,-1,-1,-1,-1,-1,-1,-1,
129129 48,49,50,51,52,53,54,55,-1,-1,-1,-1,-1,-1,-1,-1,
130130 56,57,58,59,60,61,62,63};
131131-short Dcode[120]=
131131+short Dcode[120]=
132132 {0,1,1,1,1,1,1,1,0,0,0,0,0,0,0x0E,0x0F,
133133 0x10,0x11,0x12,0,0,0,0,0,0,0,0,0,0,0,0x0F,0x1F,
134134 0x10,0x21,0x11,0,0,0,0,0,0,0,0,0,0,0x0F,0,0,
···243243 12,16,24,32,32,24,16,12,
244244 12,16,24,32,32,24,16,12,
245245 0, 0, 0, 0, 0, 0, 0, 0};
246246-246246+247247/* ............ prototypes ............ */
248248void ScorePosition( short side, short *score );
249249void ScoreLoneKing( short side, short *score );
···273273 short alpha, short beta, unsigned short mv );
274274void ZeroTTable ( void );
275275void MoveList ( short side, short ply );
276276-276276+277277void GenMoves ( short ply, short sq, short side, short xside );
278278void LinkMove ( short ply, short f, short t, short xside );
279279void CaptureList ( short side, short xside, short ply );
···294294void algbr ( short f, short t, short flag );
295295void ElapsedTime( short iop);
296296297297-void NewGame(void);
297297+void NewGame(void);
298298299299300300/* ............ POSITIONAL EVALUATION ROUTINES ............ */
301301302302-302302+303303void ScorePosition(side,score)
304304short side,*score;
305305306306/*
307307- Perform normal static evaluation of board position. A score is
308308- generated for each piece and these are summed to get a score for each
309309- side.
307307+ Perform normal static evaluation of board position. A score is
308308+ generated for each piece and these are summed to get a score for each
309309+ side.
310310*/
311311312312{
···334334 }
335335 if (hung[side] > 1) pscore[side] += HUNGX;
336336 if (hung[xside] > 1) pscore[xside] += HUNGX;
337337-337337+338338 *score = mtl[side] - mtl[xside] + pscore[side] - pscore[xside] + 10;
339339 if (dither) *score += rb->rand() % dither;
340340-340340+341341 if (*score > 0 && pmtl[side] == 0) {
342342 if (emtl[side] < valueR) {
343343 *score = 0;
···352352 if (-*score < valueR) *score /= 2;
353353 }
354354 }
355355-355355+356356 if (mtl[xside] == valueK && emtl[side] > valueB) *score += 200;
357357 if (mtl[side] == valueK && emtl[xside] > valueB) *score -= 200;
358358}
···361361void ScoreLoneKing(side,score)
362362short side,*score;
363363364364-/*
364364+/*
365365 Static evaluation when loser has only a king and winner has no pawns
366366 or no pieces.
367367*/
···373373 if (mtl[white] > mtl[black]) winner = white; else winner = black;
374374 loser = otherside[winner];
375375 king1 = PieceList[winner][0]; king2 = PieceList[loser][0];
376376-376376+377377 s = 0;
378378-378378+379379 if (pmtl[winner] > 0)
380380 for (i = 1; i <= PieceCnt[winner]; i++)
381381 s += ScoreKPK(side,winner,loser,king1,king2,PieceList[winner][i]);
382382-382382+383383 else if (emtl[winner] == valueB+valueN)
384384 s = ScoreKBNK(winner,king1,king2);
385385-385385+386386 else if (emtl[winner] > valueB)
387387 s = 500 + emtl[winner] - 2*KingEnding[king2] - 2*distance(king1,king2);
388388-388388+389389 if (side == winner) *score = s; else *score = -s;
390390}
391391···399399400400{
401401register short s,r;
402402-402402+403403 if (PieceCnt[winner] == 1) s = 50; else s = 120;
404404 if (winner == white)
405405 {
···569569 if (PC2[7] == 0) s += KHOPNX;
570570 }
571571 }
572572-573573- if (a2 > 0)
572572+573573+ if (a2 > 0)
574574 {
575575 c = (control[piece] & 0x4FFF);
576576 if (a1 == 0 || a2 > c+1)
···665665short sq,*s,*mob;
666666667667/*
668668- Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the
669669- hung[] array if a pin is found.
668668+ Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the
669669+ hung[] array if a pin is found.
670670*/
671671672672{
673673register short m,u,d,m0,j,piece,pin;
674674-short *Kf;
674674+short *Kf;
675675676676 Kf = Kfield[c1];
677677 *mob = 0;
···763763void ExaminePosition()
764764765765/*
766766- This is done one time before the search is started. Set up arrays
767767- Mwpawn, Mbpawn, Mknight, Mbishop, Mking which are used in the
768768- SqValue() function to determine the positional value of each piece.
766766+ This is done one time before the search is started. Set up arrays
767767+ Mwpawn, Mbpawn, Mknight, Mbishop, Mking which are used in the
768768+ SqValue() function to determine the positional value of each piece.
769769*/
770770771771{
···800800 if (!PawnStorm && stage < 5)
801801 PawnStorm = ((column[wking] < 3 && column[bking] > 4) ||
802802 (column[wking] > 4 && column[bking] < 3));
803803-803803+804804 CopyBoard(pknight,Mknight[white]);
805805 CopyBoard(pknight,Mknight[black]);
806806 CopyBoard(pbishop,Mbishop[white]);
807807 CopyBoard(pbishop,Mbishop[black]);
808808 BlendBoard(KingOpening,KingEnding,Mking[white]);
809809 BlendBoard(KingOpening,KingEnding,Mking[black]);
810810-810810+811811 for (sq = 0; sq < 64; sq++)
812812 {
813813 fyle = column[sq]; rank = row[sq];
···845845 if ((column[bking] < 4 && fyle > 4) ||
846846 (column[bking] > 3 && fyle < 3)) Mbpawn[sq] -= 3*rank;
847847 }
848848-848848+849849 Mknight[white][sq] += 5 - distance(sq,bking);
850850 Mknight[white][sq] += 5 - distance(sq,wking);
851851 Mknight[black][sq] += 5 - distance(sq,wking);
···862862 if (bstrong) Mknight[black][sq] += KNIGHTSTRONG;
863863 if (wstrong) Mbishop[white][sq] += BISHOPSTRONG;
864864 if (bstrong) Mbishop[black][sq] += BISHOPSTRONG;
865865-865865+866866 if (HasBishop[white] == 2) Mbishop[white][sq] += 8;
867867 if (HasBishop[black] == 2) Mbishop[black][sq] += 8;
868868 if (HasKnight[white] == 2) Mknight[white][sq] += 5;
869869 if (HasKnight[black] == 2) Mknight[black][sq] += 5;
870870-870870+871871 if (board[sq] == bishop) {
872872 if (rank % 2 == fyle % 2) {
873873 KBNKsq = 0;
874874- } else {
874874+ } else {
875875 KBNKsq = 7;
876876 }
877877 }
878878-878878+879879 Kfield[white][sq] = Kfield[black][sq] = 0;
880880 if (distance(sq,wking) == 1) Kfield[black][sq] = KATAK;
881881 if (distance(sq,bking) == 1) Kfield[white][sq] = KATAK;
882882-882882+883883 Pd = 0;
884884 for (i = 0; i < 64; i++)
885885 if (board[i] == pawn)
···912912913913void UpdateWeights()
914914915915-/*
916916- If material balance has changed, determine the values for the
917917- positional evaluation terms.
915915+/*
916916+ If material balance has changed, determine the values for the
917917+ positional evaluation terms.
918918*/
919919920920{
···932932 if (tmtl > 3600) stage2 = 0;
933933 else if (tmtl < 1400) stage2 = 10;
934934 else stage2 = (3600-tmtl) / 220;
935935-935935+936936 PEDRNK2B = -15; /* centre pawn on 2nd rank & blocked */
937937 PBLOK = -4; /* blocked backward pawn */
938938 PDOUBLED = -14; /* doubled pawn */
···941941 PADVNCM = 10; /* advanced pawn multiplier */
942942 PADVNCI = 7; /* muliplier for isolated pawn */
943943 PawnBonus = stage;
944944-944944+945945 KNIGHTPOST = (stage+2)/3; /* knight near enemy pieces */
946946 KNIGHTSTRONG = (stage+6)/2; /* occupies pawn hole */
947947-947947+948948 BISHOPSTRONG = (stage+6)/2; /* occupies pawn hole */
949949 BishopBonus = 2*stage;
950950-950950+951951 RHOPN = 10; /* rook on half open file */
952952 RHOPNX = 4;
953953 RookBonus = 6*stage;
954954-954954+955955 XRAY = 8; /* Xray attack on piece */
956956 PINVAL = 10; /* Pin */
957957-957957+958958 KHOPN = (3*stage-30) / 2; /* king on half open file */
959959 KHOPNX = KHOPN / 2;
960960 KCASTLD = 10 - stage;
961961 KMOVD = -40 / (stage+1); /* king moved before castling */
962962 KATAK = (10-stage) / 2; /* B,R attacks near enemy king */
963963 if (stage < 8) KSFTY = 16-2*stage; else KSFTY = 0;
964964-964964+965965 ATAKD = -6; /* defender > attacker */
966966 HUNGP = -8; /* each hung piece */
967967 HUNGX = -12; /* extra for >1 hung piece */
···10031003int SelectMove( short side, short iop , void (*callback)(void), char* move_buffer)
1004100410051005/*
10061006- Select a move by calling function search() at progressively deeper
10071007- ply until time is up or a mate or draw is reached. An alpha-beta
10081008- window of -90 to +90 points is set around the score returned from the
10091009- previous iteration. If Sdepth != 0 then the program has correctly
10101010- predicted the opponents move and the search will start at a depth of
10111011- Sdepth+1 rather than a depth of 1.
10061006+ Select a move by calling function search() at progressively deeper
10071007+ ply until time is up or a mate or draw is reached. An alpha-beta
10081008+ window of -90 to +90 points is set around the score returned from the
10091009+ previous iteration. If Sdepth != 0 then the program has correctly
10101010+ predicted the opponents move and the search will start at a depth of
10111011+ Sdepth+1 rather than a depth of 1.
10121012*/
1013101310141014{
···10321032 ExaminePosition();
10331033 ScorePosition(side,&score);
10341034 Pscore[0] = -score;
10351035-10351035+10361036 if (Sdepth == 0)
10371037 {
10381038 ZeroTTable();
···10431043 if (iop != 2) hint = 0;
10441044 for (i = 0; i < maxdepth; i++)
10451045 PrVar[i] = killr0[i] = killr1[i] = killr2[i] = killr3[i] = 0;
10461046-10461046+10471047 alpha = -9000; beta = 9000;
10481048 rpt = 0;
10491049 TrPnt[1] = 0; root = &Tree[0];
···10541054 NodeCnt = ETnodes = EvalNodes = HashCnt = 0;
10551055 Zscore = 0; zwndw = 20;
10561056 }
10571057-10571057+10581058 while (!timeout && Sdepth < MaxSearchDepth)
10591059 {
10601060 Sdepth++;
···11201120 if (score == -9999 || score == 9998) mate = true;
11211121 if (mate) hint = 0;
11221122 if (root->flags & cstlmask) Game50 = GameCnt;
11231123- else if (board[root->t] == pawn || (root->flags & capture))
11231123+ else if (board[root->t] == pawn || (root->flags & capture))
11241124 Game50 = GameCnt;
11251125 GameList[GameCnt].score = score;
11261126 GameList[GameCnt].nodes = NodeCnt;
···11421142void OpeningBook()
1143114311441144/*
11451145- Go thru each of the opening lines of play and check for a match with
11461146- the current game listing. If a match occurs, generate a random number.
11471147- If this number is the largest generated so far then the next move in
11481148- this line becomes the current "candidate". After all lines are
11491149- checked, the candidate move is put at the top of the Tree[] array and
11501150- will be played by the program. Note that the program does not handle
11511151- book transpositions.
11451145+ Go thru each of the opening lines of play and check for a match with
11461146+ the current game listing. If a match occurs, generate a random number.
11471147+ If this number is the largest generated so far then the next move in
11481148+ this line becomes the current "candidate". After all lines are
11491149+ checked, the candidate move is put at the top of the Tree[] array and
11501150+ will be played by the program. Note that the program does not handle
11511151+ book transpositions.
11521152*/
1153115311541154{
···12031203 void (*callback)(void) )
1204120412051205/*
12061206- Perform an alpha-beta search to determine the score for the current
12071207- board position. If depth <= 0 only capturing moves, pawn promotions
12081208- and responses to check are generated and searched, otherwise all
12091209- moves are processed. The search depth is modified for check evasions,
12101210- certain re-captures and threats. Extensions may continue for up to 11
12111211- ply beyond the nominal search depth.
12061206+ Perform an alpha-beta search to determine the score for the current
12071207+ board position. If depth <= 0 only capturing moves, pawn promotions
12081208+ and responses to check are generated and searched, otherwise all
12091209+ moves are processed. The search depth is modified for check evasions,
12101210+ certain re-captures and threats. Extensions may continue for up to 11
12111211+ ply beyond the nominal search depth.
12121212*/
1213121312141214#define prune (cf && score+node->score < alpha)
···1234123412351235 NodeCnt++;
12361236 xside = otherside[side];
12371237-12371237+12381238 if (ply <= Sdepth+3) repetition(rpt); else *rpt = 0;
12391239 if (*rpt >= 2) return(0);
1240124012411241 score = evaluate(side,xside,ply,depth,alpha,beta);
12421242 if (score > 9000) return(score);
12431243-12431243+12441244 if (depth > 0)
12451245 {
12461246 if (InChk || PawnThreat[ply-1] || ReCapture) ++depth;
···12511251 (InChk || PawnThreat[ply-1] || Parry)) depth = 1;
12521252 else if (score <= beta && MateThreat) depth = 1;
12531253 }
12541254-12541254+12551255 PV = 0;
12561256 if (depth > 0 && hashflag && ply > 1)
12571257 {
···12611261 if (beta == -20000) return(score);
12621262 if (alpha > beta) return(alpha);
12631263 }
12641264-12641264+12651265 if (Sdepth == 1) d = 7; else d = 11;
12661266 if (ply > Sdepth+d || (depth <= 0 && score > beta)) return(score);
12671267···12721272 CaptureList(side,xside,ply);
12731273 }
12741274 }
12751275-12751275+12761276 if (TrPnt[ply] == TrPnt[ply+1]) return(score);
12771277-12771277+12781278 cf = (depth < 1 && ply > Sdepth+1 && !ChkFlag[ply-2] && !slk);
1279127912801280 if (depth > 0) best = -12000; else best = score;
12811281 if (best > alpha) alpha = best;
12821282-12821282+12831283 for (pnt = pbst = TrPnt[ply];
12841284 pnt < TrPnt[ply+1] && best <= beta;
12851285 pnt++)
···12881288 node = &Tree[pnt];
12891289 mv = (node->f << 8) + node->t;
12901290 nxtline[ply+1] = 0;
12911291-12911291+12921292 if (prune) break;
12931293 if (ply == 1) UpdateSearchStatus;
12941294···13391339 if (NodeCnt > ETnodes) ElapsedTime(0);
13401340 if (timeout) return(-Tscore[ply-1]);
13411341 }
13421342-13421342+13431343 node = &Tree[pbst];
13441344 mv = (node->f<<8) + node->t;
13451345 if (hashflag && ply <= Sdepth && *rpt == 0 && best == alpha)
···13681368short side,xside,ply,depth,alpha,beta;
1369136913701370/*
13711371- Compute an estimate of the score by adding the positional score from
13721372- the previous ply to the material difference. If this score falls
13731373- inside a window which is 180 points wider than the alpha-beta window
13741374- (or within a 50 point window during quiescence search) call
13751375- ScorePosition() to determine a score, otherwise return the estimated
13761376- score. If one side has only a king and the other either has no pawns
13771377- or no pieces then the function ScoreLoneKing() is called.
13711371+ Compute an estimate of the score by adding the positional score from
13721372+ the previous ply to the material difference. If this score falls
13731373+ inside a window which is 180 points wider than the alpha-beta window
13741374+ (or within a 50 point window during quiescence search) call
13751375+ ScorePosition() to determine a score, otherwise return the estimated
13761376+ score. If one side has only a king and the other either has no pawns
13771377+ or no pieces then the function ScoreLoneKing() is called.
13781378*/
1379137913801380{
···13841384 hung[white] = hung[black] = 0;
13851385 slk = ((mtl[white] == valueK && (pmtl[black] == 0 || emtl[black] == 0)) ||
13861386 (mtl[black] == valueK && (pmtl[white] == 0 || emtl[white] == 0)));
13871387-13871387+13881388 if (slk) evflag = false;
13891389- else evflag =
13891389+ else evflag =
13901390 (ply == 1 || ply < Sdepth ||
13911391 (depth == 0 && Xscore > alpha-xwndw && Xscore < beta+xwndw) ||
13921392 (depth < 0 && Xscore > alpha-25 && Xscore < beta+25));
13931393-13931393+13941394 if (evflag)
13951395 {
13961396 EvalNodes++;
···14061406 InChk = SqAtakd(PieceList[side][0],xside);
14071407 if (slk) ScoreLoneKing(side,&Xscore);
14081408 }
14091409-14091409+14101410 Pscore[ply] = Xscore - mtl[side] + mtl[xside];
14111411 if (InChk) ChkFlag[ply-1] = Pindex[TOsquare];
14121412 else ChkFlag[ply-1] = 0;
···14171417int ProbeTTable(side,depth,alpha,beta,score)
14181418short side,depth,*alpha,*beta,*score;
1419141914201420-/*
14201420+/*
14211421 Look for the current board position in the transposition table.
14221422*/
14231423···14661466 ptbl = (ttable + hindx);
14671467 ptbl->hashbd = hashbd;
14681468 ptbl->depth = depth;
14691469- ptbl->score = score;
14691469+ ptbl->score = score;
14701470 ptbl->mv = mv;
14711471 ptbl->flags = 0;
14721472 if (score < alpha) ptbl->flags |= upperbound;
···14911491short side,ply;
1492149214931493/*
14941494- Fill the array Tree[] with all available moves for side to play. Array
14951495- TrPnt[ply] contains the index into Tree[] of the first move at a ply.
14941494+ Fill the array Tree[] with all available moves for side to play. Array
14951495+ TrPnt[ply] contains the index into Tree[] of the first move at a ply.
14961496*/
14971497-14971497+14981498{
14991499register short i,xside,f;
15001500···15281528short ply,sq,side,xside;
1529152915301530/*
15311531- Generate moves for a piece. The from square is mapped onto a special
15321532- board and offsets (taken from array Dir[]) are added to the mapped
15331533- location. The newly generated square is tested to see if it falls off
15341534- the board by ANDing the square with 88 HEX. Legal moves are linked
15351535- into the tree.
15311531+ Generate moves for a piece. The from square is mapped onto a special
15321532+ board and offsets (taken from array Dir[]) are added to the mapped
15331533+ location. The newly generated square is tested to see if it falls off
15341534+ the board by ANDing the square with 88 HEX. Legal moves are linked
15351535+ into the tree.
15361536*/
15371537-15371537+15381538{
15391539-register short m,u,d,i,m0,piece;
15391539+register short m,u,d,i,m0,piece;
1540154015411541 piece = board[sq]; m0 = map[sq];
15421542 if (sweep[piece])
···16051605 2. Capture of last moved piece
16061606 3. Other captures (major pieces first)
16071607 4. Killer moves
16081608- 5. "history" killers
16081608+ 5. "history" killers
16091609*/
1610161016111611{
···16881688 }
16891689 PL = PieceList[side];
16901690 for (i = 0; i <= PieceCnt[side]; i++)
16911691- {
16911691+ {
16921692 sq = PL[i];
16931693 m0 = map[sq]; piece = board[sq];
16941694 j1 = Dstart[piece]; j2 = Dstop[piece];
···17241724 }
17251725}
1726172617271727-17271727+17281728int castle(side,kf,kt,iop)
17291729short side,kf,kt,iop;
17301730···17921792 {
17931793 board[l] = no_piece; color[l] = neutral;
17941794 }
17951795- else
17951795+ else
17961796 {
17971797 board[l] = pawn; color[l] = xside;
17981798 }
···18051805struct leaf *node;
1806180618071807/*
18081808- Update Arrays board[], color[], and Pindex[] to reflect the new board
18091809- position obtained after making the move pointed to by node. Also
18101810- update miscellaneous stuff that changes when a move is made.
18081808+ Update Arrays board[], color[], and Pindex[] to reflect the new board
18091809+ position obtained after making the move pointed to by node. Also
18101810+ update miscellaneous stuff that changes when a move is made.
18111811*/
18121812-18121812+18131813{
18141814register short f,t,xside,ct,cf;
18151815···18741874 UpdateHashbd(side,queen,f,-1);
18751875 }
18761876 INCscore -= *tempsf;
18771877- }
18771877+ }
18781878 if (board[t] == king) ++kingmoved[side];
18791879 if (node->flags & epmask) EnPassant(xside,f,t,1);
18801880 else if (hashflag) UpdateHashbd(side,board[t],f,t);
···19131913 UpdateHashbd(side,queen,-1,t);
19141914 UpdateHashbd(side,pawn,-1,t);
19151915 }
19161916- }
19161916+ }
19171917 if (*tempc != neutral)
19181918 {
19191919 UpdatePieceList(*tempc,t,2);
···19381938short side,piece,f,t;
1939193919401940/*
19411941- hashbd contains a 32 bit "signature" of the board position. hashkey
19421942- contains a 16 bit code used to address the hash table. When a move is
19431943- made, XOR'ing the hashcode of moved piece on the from and to squares
19441944- with the hashbd and hashkey values keeps things current.
19411941+ hashbd contains a 32 bit "signature" of the board position. hashkey
19421942+ contains a 16 bit code used to address the hash table. When a move is
19431943+ made, XOR'ing the hashcode of moved piece on the from and to squares
19441944+ with the hashbd and hashkey values keeps things current.
19451945*/
1946194619471947{
···19621962short side,sq,iop;
1963196319641964/*
19651965- Update the PieceList and Pindex arrays when a piece is captured or
19661966- when a capture is unmade.
19651965+ Update the PieceList and Pindex arrays when a piece is captured or
19661966+ when a capture is unmade.
19671967*/
1968196819691969{
···19891989void InitializeStats()
1990199019911991/*
19921992- Scan thru the board seeing what's on each square. If a piece is found,
19931993- update the variables PieceCnt, PawnCnt, Pindex and PieceList. Also
19941994- determine the material for each side and set the hashkey and hashbd
19951995- variables to represent the current board position. Array
19961996- PieceList[side][indx] contains the location of all the pieces of
19971997- either side. Array Pindex[sq] contains the indx into PieceList for a
19981998- given square.
19921992+ Scan thru the board seeing what's on each square. If a piece is found,
19931993+ update the variables PieceCnt, PawnCnt, Pindex and PieceList. Also
19941994+ determine the material for each side and set the hashkey and hashbd
19951995+ variables to represent the current board position. Array
19961996+ PieceList[side][indx] contains the location of all the pieces of
19971997+ either side. Array Pindex[sq] contains the indx into PieceList for a
19981998+ given square.
19991999*/
2000200020012001{
···20272027void pick(p1,p2)
20282028short p1,p2;
2029202920302030-/*
20312031- Find the best move in the tree between indexes p1 and p2. Swap the
20322032- best move into the p1 element.
20302030+/*
20312031+ Find the best move in the tree between indexes p1 and p2. Swap the
20322032+ best move into the p1 element.
20332033*/
2034203420352035{
···20812081/*
20822082 See if any piece with color 'side' ataks sq. First check for pawns
20832083 or king, then try other pieces. Array Dcode is used to check for
20842084- knight attacks or R,B,Q co-linearity.
20842084+ knight attacks or R,B,Q co-linearity.
20852085*/
2086208620872087{
···20952095 if (!(m & 0x88))
20962096 if (board[unmap[m]] == pawn && color[unmap[m]] == side) return(true);
20972097 if (distance(sq,PieceList[side][0]) == 1) return(true);
20982098-20982098+20992099 PL = PieceList[side];
21002100 for (i = 1; i <= PieceCnt[side]; i++)
21012101 {
···21282128{
21292129register short u,m,d,c,m0;
21302130short j,j1,j2,piece,i,sq,*PL;
21312131-21322132- for (u = 0; u < 64; a[u++] = 0);
21312131+21322132+ for (u = 0; u < 64; a[u++] = 0);
21332133 Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1;
21342134 PL = PieceList[side];
21352135 for (i = 0; i <= PieceCnt[side]; i++)
···2164216421652165void ElapsedTime(iop)
2166216621672167-/*
21682168- Determine the time that has passed since the search was started. If
21692169- the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
21702170- timeout to true which will terminate the search.
21672167+/*
21682168+ Determine the time that has passed since the search was started. If
21692169+ the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
21702170+ timeout to true which will terminate the search.
21712171*/
2172217221732173short iop;
···22302230int VerifyMove(short player, char s[],short iop,unsigned short *mv, char *move_buffer)
2231223122322232/*
22332233- Compare the string 's' to the list of legal moves available for the
22332233+ Compare the string 's' to the list of legal moves available for the
22342234 player. If a match is found, make the move on the board. This was originally
22352235 fixed for the opponent, but allowing the player to be specified will make
22362236 possible to use GnuChess as a human vs human game verifier. It also allows
···22772277 /*if (xnode.flags & epmask) UpdateDisplay(0,0,1,0);
22782278 else UpdateDisplay(xnode.f,xnode.t,0,xnode.flags & cstlmask);*/
22792279 if (xnode.flags & cstlmask) Game50 = GameCnt;
22802280- else if (board[xnode.t] == pawn || (xnode.flags & capture))
22802280+ else if (board[xnode.t] == pawn || (xnode.flags & capture))
22812281 Game50 = GameCnt;
22822282 GameList[GameCnt].depth = GameList[GameCnt].score = 0;
22832283 GameList[GameCnt].nodes = 0;
···22982298 }
2299229923002300 return(true);
23012301- }
23012301+ }
23022302 }
23032303 /*if (cnt > 1) ShowMessage("Ambiguous Move!");*/
23042304 return(false);
···23632363 TCminutes = 5;
23642364 TCflag = true;
23652365 NewGame();
23662366- MaxSearchDepth = 29 ;
23662366+ MaxSearchDepth = 29 ;
23672367}
2368236823692369void algbr(f,t,flag)
···23812381 rb->memcpy(mvstr2,"o-o-o", 5);
23822382 }
23832383 }
23842384-23842384+23852385 if (board[f] == pawn) mvstr3[0] = mvstr1[0];
23862386 else mvstr3[0] = qxx[board[f]];
23872387 if (color[t] != neutral)
+1-1
apps/plugins/chessbox/gnuchess.h
···4455#define neutral 2
66#define white 0
77-#define black 1
77+#define black 1
88#define no_piece 0
99#define pawn 1
1010#define knight 2