From a9df89c8821304f26bb2d3723049d188a39384b4 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 27 Nov 2013 21:33:23 +0100 Subject: [PATCH] Allow setting up position from scratch The position string in Bonanza's native 'new' command can now have a new format, starting with 'SU' in stead of 'PI', which adds the mentioned pieces to an empty board, rather than deleting them from the standard initial position. Holdings pieces are encoded by '00' for square coordinates. A '+' or '-' embedded in the string can be used to switch between Sente and Gote. (By default it assumes Sente, so all Gote pieces could be mentioned at the end after a single '-'.) --- csa.c | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-) diff --git a/csa.c b/csa.c index cbf1bf6..f1f0479 100644 --- a/csa.c +++ b/csa.c @@ -462,7 +462,13 @@ read_board_rep1( const char *str_line, min_posi_t *pmin_posi ) char str_piece[3]; int piece, ifile, irank, isquare; signed char board[nsquare]; + int add = 0, color = -1; + if( *str_line == 'S' ) { // [HGM] setup: allow 'SU' representation that adds pieces in stead of removing them + add = 1; + for ( isquare = 0; isquare < nsquare; isquare++ ) board[isquare] = empty; + pmin_posi->hand_white = pmin_posi->hand_black = 0; + } else memcpy( board, &min_posi_no_handicap.asquare, nsquare ); for ( p = str_line + 2; p[0] != '\0'; p += 4 ) @@ -472,6 +478,18 @@ read_board_rep1( const char *str_line, min_posi_t *pmin_posi ) str_error = str_bad_board; return -2; } + if( add && p[0] == '+' ) // [HGM] setup: change color + { + color = 1; + p -= 3; + continue; + } + if( add && p[0] == '-' ) + { + color = -1; + p -= 3; + continue; + } str_piece[0] = p[2]; str_piece[1] = p[3]; str_piece[2] = '\0'; @@ -481,12 +499,24 @@ read_board_rep1( const char *str_line, min_posi_t *pmin_posi ) ifile = 9 - ifile; irank = irank - 1; isquare = irank * nfile + ifile; + if ( add && piece != -2 && p[0] == '0' && p[1] == '0' ) + { // [HGM] setup: holdings + static int unit[] = {0, 1, 1<<5, 1<<8, 1<<11, 1<<14, 1<<17, 1<<19}; + if(piece < 1 || piece > 7) { // only unpromoted in hand! + str_error = str_bad_board; + return -2; + } + if(color > 0) pmin_posi->hand_black += unit[piece]; + else pmin_posi->hand_white += unit[piece]; + continue; + } if ( piece == -2 || ifile < file1 || ifile > file9 || irank < rank1 - || irank > rank9 || abs(board[isquare]) != piece ) + || irank > rank9 || abs(board[isquare]) != (add ? empty : piece) ) { str_error = str_bad_board; return -2; } + if( add ) board[isquare] = piece*color; else board[isquare] = empty; } -- 1.7.0.4