char xboard_mode;
int root_pos[nsquare];
-void
-xboard_to_CSA( tree_t * restrict ptree, char *in, char *out )
+int
+bonanza_piece( char p )
{
- char fromX=in[0], fromY=in[1], toX=in[2], toY=in[3], promo=in[4];
- int piece=0;
- if(fromY == '@') { // drop (contains all info needed to convert it)
- if(fromX >= 'a') fromX += 'A' - 'a';
- switch(fromX) { // encode piece
+ int piece = 0;
+ if(p >= 'a') p += 'A' - 'a';
+ switch(p) { // encode piece
case 'P': piece = pawn; break;
case 'L': piece = lance; break;
case 'N': piece = knight; break;
case 'G': piece = gold; break;
case 'B': piece = bishop; break;
case 'R': piece = rook; break;
+ case 'K': piece = king; break;
+ }
+ return piece;
+}
+
+void
+read_fen( char *p )
+{
+ static char fen[128];
+ int r, f, gote = 1;
+ char *q = fen, *start = p;
+ strncpy( fen, p+9 , 127);
+ strcpy( p, "new SU" ); p += 6;
+ for ( r = 1; r <= 9; r++) {
+ for ( f = 0; *q; q++ ) {
+ int promoted = 0;
+ if( *q == '+' ) promoted = promote, q++;
+ if( isdigit( *q ) ) f += atoi( q ); else
+ if( isalpha( *q ) ) {
+ int piece = bonanza_piece( *q );
+ if( ( *q >= 'a' && *q <= 'z' ) != gote ) {
+ gote = !gote; // switch color
+ *p++ = ( gote ? '-' : '+' );
+ }
+ sprintf( p, "%d%d%s", 9-f, r, astr_table_piece[piece + promoted] );
+ p += 4; f++;
+ } else { q++; break; }
}
+ }
+ while( q[-1] == ' ' ) q++;
+ if( q[-1] == '[' ) { // holdings
+ while( isalpha( *q ) ) {
+ int piece = bonanza_piece( *q );
+ if( ( *q >= 'a' && *q <= 'z' ) != gote ) {
+ gote = !gote; // switch color
+ *p++ = ( gote ? '-' : '+' );
+ }
+ sprintf( p, "00%s", astr_table_piece[piece] );
+ p += 4; q++;
+ }
+ if( *q == '-' ) q++;
+ if( *q == ']' ) q++;
+ while( *q == ' ' ) q++;
+ } else q--;
+ sprintf(p, " %c", *q == 'w' ? '+' : '-' ); // side to move
+}
+
+void
+xboard_to_CSA( tree_t * restrict ptree, char *in, char *out )
+{
+ char fromX=in[0], fromY=in[1], toX=in[2], toY=in[3], promo=in[4];
+ int piece=0;
+ if(fromY == '@') { // drop (contains all info needed to convert it)
+ piece = bonanza_piece( fromX );
sprintf(out, "00%c%c%s", 'a'+'9'-toX, '1'+'9'-toY, astr_table_piece[piece]);
} else { // board move (need to figure out moved piece)
int from = ('9' - fromY)*9 + (fromX - 'a');
IF("analyze") { return 0; }
IF("exit") { return 0; }
IF("variant") { /* ignore, since it must be Shogi */; }
- IF("setboard") { ; }
+ IF("setboard") { forceMode = plyNr = 0; read_fen( line ); return 0; }
IF("option") {
if(sscanf(line+7, "MultiPV=%d", &value) == 1) { sprintf(line, "mpv num %d", value); return 0; }
if(sscanf(line+7, "centi-Pawn margin=%d", &value) == 1) { sprintf(line, "mpv width %d", value); return 0; }