@@ -347,7 +347,7 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,
347347 }
348348
349349 // Promoted shogi pieces
350- else if (token == ' +' )
350+ else if (token == ' +' && var-> shogiStylePromotions )
351351 {
352352 if (Variant::is_piece_id_start (ss.peek ()))
353353 {
@@ -467,33 +467,55 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,
467467 // 4. En passant square.
468468 // Ignore if square is invalid or not on side to move relative rank 6.
469469 else
470- while ( ((ss >> col) && (col >= ' a' && col <= ' a' + max_file ()))
471- && ((ss >> row) && (row >= ' 1' && row <= ' 1' + max_rank ())))
470+ {
471+ std::string epInfo;
472+ ss >> std::skipws >> epInfo;
473+ ss >> std::noskipws;
474+ if (!epInfo.empty () && epInfo != " -" )
472475 {
473- Square epSquare = make_square (File (col - ' a' ), Rank (row - ' 1' ));
476+ size_t i = 0 ;
477+ while (i < epInfo.size ())
478+ {
479+ char fileChar = epInfo[i];
480+ if (fileChar < ' a' || fileChar > ' a' + max_file ())
481+ break ;
482+ ++i;
483+ if (i >= epInfo.size () || !isdigit (epInfo[i]))
484+ break ;
485+ int rankNum = 0 ;
486+ while (i < epInfo.size () && isdigit (epInfo[i]))
487+ {
488+ rankNum = rankNum * 10 + (epInfo[i] - ' 0' );
489+ ++i;
490+ }
491+ if (rankNum < 1 || rankNum > int (max_rank ()) + 1 )
492+ continue ;
493+ Square epSquare = make_square (File (fileChar - ' a' ), Rank (rankNum - 1 ));
474494#ifdef LARGEBOARDS
475- // Consider different rank numbering in CECP
476- if (max_rank () == RANK_10 && CurrentProtocol == XBOARD)
477- epSquare += NORTH;
495+ // Consider different rank numbering in CECP
496+ if (max_rank () == RANK_10 && CurrentProtocol == XBOARD)
497+ epSquare += NORTH;
478498#endif
479499
480- // En passant square will be considered only if
481- // epSquare is within enPassantRegion and
482- // 1) variant has non-standard rules
483- // or
484- // 2)
485- // a) side to move have a pawn threatening epSquare
486- // b) there is an enemy pawn one or two (for triple steps) squares in front of epSquare
487- // c) there is no (non-wall) piece on epSquare or behind epSquare
488- if ( (var->enPassantRegion [sideToMove] & epSquare)
489- && ( !var->fastAttacks
490- || (var->enPassantTypes [sideToMove] & ~piece_set (PAWN))
491- || ( pawn_attacks_bb (~sideToMove, epSquare) & pieces (sideToMove, PAWN)
492- && ( (pieces (~sideToMove, PAWN) & (epSquare + pawn_push (~sideToMove)))
493- || (pieces (~sideToMove, PAWN) & (epSquare + 2 * pawn_push (~sideToMove))))
494- && !((pieces (WHITE) | pieces (BLACK)) & (epSquare | (epSquare + pawn_push (sideToMove)))))))
495- st->epSquares |= epSquare;
500+ // En passant square will be considered only if
501+ // epSquare is within enPassantRegion and
502+ // 1) variant has non-standard rules
503+ // or
504+ // 2)
505+ // a) side to move have a pawn threatening epSquare
506+ // b) there is an enemy pawn one or two (for triple steps) squares in front of epSquare
507+ // c) there is no (non-wall) piece on epSquare or behind epSquare
508+ if ( (var->enPassantRegion [sideToMove] & epSquare)
509+ && ( !var->fastAttacks
510+ || (var->enPassantTypes [sideToMove] & ~piece_set (PAWN))
511+ || ( pawn_attacks_bb (~sideToMove, epSquare) & pieces (sideToMove, PAWN)
512+ && ( (pieces (~sideToMove, PAWN) & (epSquare + pawn_push (~sideToMove)))
513+ || (pieces (~sideToMove, PAWN) & (epSquare + 2 * pawn_push (~sideToMove))))
514+ && !((pieces (WHITE) | pieces (BLACK)) & (epSquare | (epSquare + pawn_push (sideToMove)))))))
515+ st->epSquares |= epSquare;
516+ }
496517 }
518+ }
497519 }
498520
499521 // Check counter for nCheck
0 commit comments