1 /***************************************************************************
2 board_io.cpp - description
4 begin : Wed Mar 13 2002
5 copyright : (C) 2002-2005 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
22 /* print a fancy colored board */
23 void Board::print_board()
25 static const char out_wpiece
[] = "\e[1;33m";
26 static const char out_bpiece
[] = "\e[1;32m";
27 static const char out_wsquare
[]= "\e[1;47m";
28 static const char out_bsquare
[]= "\e[1;43m";
30 find_check_and_pins();
37 unsigned char piece
= data
[POS_XY(i
, j
)];
40 piece
== STONE
? "\e[1;40m" :
41 oth_pins
[POS_XY(i
, j
)] ? "\e[1;44m" :
42 (CAN_MOVE(pins
[POS_XY(i
, j
)]) ? ((j
+i
)&1 ? out_wsquare
: out_bsquare
):
43 (IS_OF_COLOR(piece
,color_to_move
)?"\e[1;45m":"\e[1;41m")),
44 COLOR_OF(piece
)==WHITE
? out_wpiece
: out_bpiece
,
45 piece
==STONE
?' ':piecename
[PIECE_OF(piece
)]);
51 printf("#on move: %s ", color_to_move
==WHITE
?"white":"black");
52 printf("castling: %s%s%s%s ",
53 castle_passing_mask
&WCANCASTLEKS
? "K" : " ",
54 castle_passing_mask
&WCANCASTLEQS
? "Q" : " ",
55 castle_passing_mask
&BCANCASTLEKS
? "k" : " ",
56 castle_passing_mask
&BCANCASTLEQS
? "q" : " " );
57 printf("en-passant: %d\n", castle_passing_mask
&NOT_PASSING
?
58 -1: castle_passing_mask
&0x07);
60 printf("#static value....: %d\n",(int)evaluate(WHITE
,-INF
,INF
));
61 printf("#hash key........: %08x%08x:%08x\n",
62 hash
.check_hi
, hash
.check_lo
, hash
.index
);
65 printf("#fen.............: %s\n", buf
);
70 printf("pawn positions:\n");
74 max
= MAX(max
, line_pawns
[i
][w
].count
);
76 for(int q
=max
-1;q
>=0;q
--)
82 if(q
<line_pawns
[i
][w
].count
)
83 printf("%d", line_pawns
[i
][w
].pos
[q
]);
91 printf("-------- --------\n");
93 static char name
[] = "brqnpkRBQNPK";
94 printf("piece positions:\n");
97 printf("%c:", name
[i
]);
98 for(int j
=0;j
<mat_tracking
[i
].count
;j
++)
100 'a' + X(mat_tracking
[i
].pos
[j
]),
101 '1' + Y(mat_tracking
[i
].pos
[j
]));
107 void Board::write_board(char* str
)
110 for(int i
=7;i
>=0;i
--)
114 unsigned char pc
=data
[POS_XY(j
,i
)];
121 str
+=sprintf(str
,"%d",cn
);
124 char p
= pc
==STONE
? '#' : Board::piecename
[PIECE_OF(pc
)];
125 if(COLOR_OF(pc
)==BLACK
)
127 str
+=sprintf(str
,"%c",p
);
132 str
+=sprintf(str
,"%d",cn
);
136 str
+=sprintf(str
,"/");
139 str
+=sprintf(str
," %c ",color_to_move
==WHITE
? 'w':'b');
141 if(castle_passing_mask
&WCANCASTLEKS
)
142 str
+=sprintf(str
,"K");
143 if(castle_passing_mask
&WCANCASTLEQS
)
144 str
+=sprintf(str
,"Q");
145 if(castle_passing_mask
&BCANCASTLEKS
)
146 str
+=sprintf(str
,"k");
147 if(castle_passing_mask
&BCANCASTLEQS
)
148 str
+=sprintf(str
,"q");
149 if(!(castle_passing_mask
&0xf0))
150 str
+=sprintf(str
,"-");
152 if(!(castle_passing_mask
&NOT_PASSING
))
153 str
+=sprintf(str
," %c%c",(castle_passing_mask
&0x07)+'a',
154 color_to_move
==WHITE
?'6':'3');
156 str
+=sprintf(str
," -");
157 str
+=sprintf(str
," %d %d",fifty
,num_moves
+1);
161 void Board::read_board(char* brd
, char* color
, char* castle
,
162 char* passing
, int moves_to_draw
, int num_mv
)
168 fifty
= moves_to_draw
;
175 if(cc
>='1' && cc
<='8')
183 currl
= 0x70 - i
*0x10;
188 data
[currl
++] = STONE
;
197 data
[currl
++] = i
|WHITE
;
200 else if((piecename
[i
]^0x20)==cc
)
204 data
[currl
++] = i
|BLACK
;
209 color_to_move
= (*color
=='w')?WHITE
:BLACK
;
210 other_color
= OTHER_COLOR(color_to_move
);
213 castle_passing_mask
= 0;
219 castle_passing_mask
|=WCANCASTLEKS
;
222 castle_passing_mask
|=WCANCASTLEQS
;
225 castle_passing_mask
|=BCANCASTLEKS
;
228 castle_passing_mask
|=BCANCASTLEQS
;
234 castle_passing_mask
|= (passing
[0]-'a');
236 castle_passing_mask
|= NOT_PASSING
;
238 num_moves
= MAX(num_mv
-1, 0);
245 recalc_mat_tracking();
249 #endif //TRACK_ATTACKS
252 void Board::read_board(char* str
)
255 char color
[2],castle
[5],passing
[3];
259 sscanf(str
,"%s%s%s%s%d%d",
260 brd
,color
,castle
,passing
,&moves_to_draw
,&numm
);
262 read_board(brd
,color
,castle
,passing
,moves_to_draw
,numm
);