const char *
-str_CSA_move_plus( tree_t * restrict ptree, unsigned int move, int ply,
- int turn )
-{
- static char str[ 13 ];
- const unsigned int *pmove_last;
- unsigned int amove[ MAX_LEGAL_EVASION ];
- char *p;
- int is_promo, ipiece_cap, ipiece_move, ifrom, ito, turn_next;
-
- is_promo = (int)I2IsPromote(move);
- ipiece_move = (int)I2PieceMove(move);
- ifrom = (int)I2From(move);
- ito = (int)I2To(move);
- ipiece_cap = (int)UToCap(move);
- turn_next = Flip( turn );
-
- if ( is_promo && ipiece_cap )
- {
- snprintf( str, 13, "%d%d%d%d%spx%s",
- 9-aifile[ifrom], airank[ifrom]+1,
- 9-aifile[ito], airank[ito] +1,
- astr_table_piece[ ipiece_move + promote ],
- astr_table_piece[ ipiece_cap ] );
- p = str + 10;
- }
- else if ( ipiece_cap )
- {
- snprintf( str, 13, "%d%d%d%d%sx%s",
- 9-aifile[ifrom], airank[ifrom]+1,
- 9-aifile[ito], airank[ito] +1,
- astr_table_piece[ ipiece_move ],
- astr_table_piece[ ipiece_cap ] );
- p = str + 9;
- }
- else if ( is_promo )
- {
- snprintf( str, 13, "%d%d%d%d%sp",
- 9-aifile[ifrom], airank[ifrom]+1,
- 9-aifile[ito], airank[ito] +1,
- astr_table_piece[ ipiece_move + promote ] );
- p = str + 7;
- }
- else if ( ifrom < nsquare )
- {
- snprintf( str, 13, "%d%d%d%d%s",
- 9-aifile[ifrom], airank[ifrom]+1,
- 9-aifile[ito], airank[ito] +1,
- astr_table_piece[ ipiece_move ] );
- p = str + 6;
- }
- else {
- snprintf( str, 13, "00%d%d%s", 9-aifile[ito], airank[ito]+1,
- astr_table_piece[ From2Drop(ifrom) ] );
- p = str + 6;
- }
-
- MakeMove( turn, move, ply );
- if ( InCheck( turn_next ) )
- {
- pmove_last = GenEvasion( turn_next, amove );
- if ( pmove_last == amove ) { *p++ = '#'; }
- else { *p++ = '!'; }
- *p = '\0';
- }
- UnMakeMove( turn, move, ply );
-
- return str;
-}
-
-
-const char *
str_CSA_move( unsigned int move )
{
static char str[7];
}
+#if defined(USI)
+int CONV
+usi2csa( const tree_t * restrict ptree, const char *str_usi, char *str_csa )
+{
+ int sq_file, sq_rank, sq, pc;
+
+ if ( '1' <= str_usi[0] && str_usi[0] <= '9'
+ && 'a' <= str_usi[1] && str_usi[1] <= 'i'
+ && '1' <= str_usi[2] && str_usi[2] <= '9'
+ && 'a' <= str_usi[3] && str_usi[3] <= 'i' )
+ {
+ str_csa[0] = str_usi[0];
+ str_csa[1] = (char)( str_usi[1] + '1' - 'a' );
+ str_csa[2] = str_usi[2];
+ str_csa[3] = (char)( str_usi[3] + '1' - 'a' );
+
+ sq_file = str_csa[0]-'0';
+ sq_file = 9 - sq_file;
+ sq_rank = str_csa[1]-'0';
+ sq_rank = sq_rank - 1;
+ sq = sq_rank * 9 + sq_file;
+ pc = abs(BOARD[sq]);
+ if ( str_usi[4] == '+' ) { pc += promote; }
+
+ str_csa[4] = astr_table_piece[pc][0];
+ str_csa[5] = astr_table_piece[pc][1];
+ str_csa[6] = '\0';
+
+ return 1;
+ }
+
+ if ( isascii( (int)str_usi[0] )
+ && isalpha( (int)str_usi[0] )
+ && str_usi[1] == '*'
+ && '1' <= str_usi[2] && str_usi[2] <= '9'
+ && 'a' <= str_usi[3] && str_usi[3] <= 'i' )
+ {
+ str_csa[0] = '0';
+ str_csa[1] = '0';
+ str_csa[2] = str_usi[2];
+ str_csa[3] = (char)( str_usi[3] - 'a' + '1' );
+
+ switch ( str_usi[0] )
+ {
+ case 'P': pc = pawn; break;
+ case 'L': pc = lance; break;
+ case 'N': pc = knight; break;
+ case 'S': pc = silver; break;
+ case 'G': pc = gold; break;
+ case 'B': pc = bishop; break;
+ case 'R': pc = rook; break;
+ default: return -1;
+ }
+
+ str_csa[4] = astr_table_piece[pc][0];
+ str_csa[5] = astr_table_piece[pc][1];
+ str_csa[6] = '\0';
+
+ return 1;
+ }
+
+ snprintf( str_message, SIZE_MESSAGE, "%s: %s", str_illegal_move, str_usi );
+ str_error = str_message;
+ return -1;
+}
+
+
+int CONV
+csa2usi( const tree_t * restrict ptree, const char *str_csa, char *str_usi )
+{
+ if ( str_csa[0] == '0' && str_csa[1] == '0'
+ && '1' <= str_csa[2] && str_csa[2] <= '9'
+ && '1' <= str_csa[3] && str_csa[3] <= '9'
+ && 'A' <= str_csa[4] && str_csa[4] <= 'Z'
+ && 'A' <= str_csa[5] && str_csa[5] <= 'Z' )
+ {
+ switch ( str2piece( str_csa + 4 ) )
+ {
+ case pawn: str_usi[0] = 'P'; break;
+ case lance: str_usi[0] = 'L'; break;
+ case knight: str_usi[0] = 'N'; break;
+ case silver: str_usi[0] = 'S'; break;
+ case gold: str_usi[0] = 'G'; break;
+ case bishop: str_usi[0] = 'B'; break;
+ case rook: str_usi[0] = 'R'; break;
+ default: return -1; break;
+ }
+
+ str_usi[1] = '*';
+ str_usi[2] = str_csa[2];
+ str_usi[3] = (char)( str_csa[3] + 'a' - '1' );
+ str_usi[4] = '\0';
+
+ return 1;
+ }
+
+
+ if ( '1' <= str_csa[0] && str_csa[0] <= '9'
+ && '1' <= str_csa[1] && str_csa[1] <= '9'
+ && '1' <= str_csa[2] && str_csa[2] <= '9'
+ && '1' <= str_csa[3] && str_csa[3] <= '9'
+ && 'A' <= str_csa[4] && str_csa[4] <= 'Z'
+ && 'A' <= str_csa[5] && str_csa[5] <= 'Z' )
+ {
+ int sq_file, sq_rank, sq, pc;
+
+
+ str_usi[0] = str_csa[0];
+ str_usi[1] = (char)( str_csa[1] + 'a' - '1' );
+ str_usi[2] = str_csa[2];
+ str_usi[3] = (char)( str_csa[3] + 'a' - '1' );
+
+ sq_file = str_csa[0]-'0';
+ sq_file = 9 - sq_file;
+
+ sq_rank = str_csa[1]-'0';
+ sq_rank = sq_rank - 1;
+ sq = sq_rank * 9 + sq_file;
+ pc = abs(BOARD[sq]);
+
+ if ( pc + promote == str2piece( str_csa + 4 ) )
+ {
+ str_usi[4] = '+';
+ str_usi[5] = '\0';
+ }
+ else { str_usi[4] = '\0'; }
+
+
+ return 1;
+ }
+
+ str_usi[0] = '*';
+ str_usi[1] = '\0';
+ return 1;
+}
+#endif
+
+
static void
out_CSA_header( const tree_t * restrict ptree, record_t *pr )
{