pgn_read/core/game.py
def _append_recovered_bishop_or_bpawn_move(self, match):
        """Return True if match is resolved to a bishop or b-pawn move."""
        mgt = match.group().lower()
        promotion_match = text_format.match(
            LAN_MOVE_SEPARATOR.join((self._bishop_or_bpawn.group().lower(),
                                     mgt[:-1]+mgt[-1].upper())))
        promotion_lastindex = (
            promotion_match and
            promotion_match.lastindex  == IFG_PAWN_PROMOTE_PIECE)
        if not (mgt.startswith(LAN_MOVE_SEPARATOR) or
                mgt.startswith(PGN_CAPTURE_MOVE)):
            mgt = LAN_MOVE_SEPARATOR + mgt
        bishop_match = text_format.match(''.join((
            self._bishop_or_bpawn.group().upper(), mgt)))
        pawn_match = text_format.match(''.join((
            self._bishop_or_bpawn.group().lower(), mgt)))
        bishop_lastindex = (
            bishop_match and bishop_match.lastindex  == IFG_PIECE_DESTINATION)
        pawn_lastindex = (
            pawn_match and
            (pawn_match.lastindex  == IFG_PAWN_TO_RANK or
             pawn_match.lastindex  == IFG_PAWN_PROMOTE_PIECE))

        # Try the available matches.
        if promotion_lastindex:
            self._undo_append_token_and_set_error()
            super().append_pawn_promote_move(promotion_match)
            self._bishop_or_bpawn = None
        elif bishop_lastindex and pawn_lastindex:
            fen = generate_fen_for_position(
                [p for p in self._piece_placement_data.values()],
                self._active_color,
                self._castling_availability,
                self._en_passant_target_square,
                self._halfmove_clock,
                self._fullmove_number)
            setup = import_format.match('[SetUp"1"]')
            fen = import_format.match(fen.join(('[FEN"', '"]')))
            bishop_move = GameTextPGN()
            bishop_move.append_start_tag(setup)
            bishop_move.append_start_tag(fen)
            bishop_move.append_piece_move(bishop_match)
            pawn_move = GameTextPGN()
            pawn_move.append_start_tag(setup)
            pawn_move.append_start_tag(fen)
            pawn_move.append_pawn_move(pawn_match)
            if bishop_move._state is None and pawn_move._state is None:
                if match.group()[0].isupper():
                    self._undo_append_token_and_set_error()
                    super().append_piece_move(bishop_match)
                else:
                    self._undo_append_token_and_set_error()
                    self._append_pawn_move(pawn_match)
            elif bishop_move._state is None:
                self._undo_append_token_and_set_error()
                super().append_piece_move(bishop_match)
            elif pawn_move._state is None:
                self._undo_append_token_and_set_error()
                self._append_pawn_move(pawn_match)

            # This looks equivalent to doing nothing, but if removed leads to
            # an exception in _append_pawn_move at 'if mgl[0] != mgl[3]:'.
            # Without the adjustment to self._text[-1] the text from match
            # appears in two adjacent self._text elements.
            else:
                error_text = self._text[-1]
                self._undo_append_token_and_set_error()
                self.append_token_and_set_error(match)
                self._text[-1] = error_text

        elif pawn_lastindex:
            self._undo_append_token_and_set_error()
            self._append_pawn_move(pawn_match)
        elif bishop_lastindex:
            self._undo_append_token_and_set_error()
            super().append_piece_move(bishop_match)
        else:
            self.append_token_and_set_error(match)
        return bool(self._state is None)
Return True if match is resolved to a bishop or b-pawn move.
Return True if match is resolved to a bishop or b-pawn move.
Return True if match is resolved to a bishop or b - pawn move .
def _append_recovered_bishop_or_bpawn_move(self, match):
        mgt = match.group().lower()
        promotion_match = text_format.match(
            LAN_MOVE_SEPARATOR.join((self._bishop_or_bpawn.group().lower(),
                                     mgt[:-1]+mgt[-1].upper())))
        promotion_lastindex = (
            promotion_match and
            promotion_match.lastindex  == IFG_PAWN_PROMOTE_PIECE)
        if not (mgt.startswith(LAN_MOVE_SEPARATOR) or
                mgt.startswith(PGN_CAPTURE_MOVE)):
            mgt = LAN_MOVE_SEPARATOR + mgt
        bishop_match = text_format.match(''.join((
            self._bishop_or_bpawn.group().upper(), mgt)))
        pawn_match = text_format.match(''.join((
            self._bishop_or_bpawn.group().lower(), mgt)))
        bishop_lastindex = (
            bishop_match and bishop_match.lastindex  == IFG_PIECE_DESTINATION)
        pawn_lastindex = (
            pawn_match and
            (pawn_match.lastindex  == IFG_PAWN_TO_RANK or
             pawn_match.lastindex  == IFG_PAWN_PROMOTE_PIECE))
        if promotion_lastindex:
            self._undo_append_token_and_set_error()
            super().append_pawn_promote_move(promotion_match)
            self._bishop_or_bpawn = None
        elif bishop_lastindex and pawn_lastindex:
            fen = generate_fen_for_position(
                [p for p in self._piece_placement_data.values()],
                self._active_color,
                self._castling_availability,
                self._en_passant_target_square,
                self._halfmove_clock,
                self._fullmove_number)
            setup = import_format.match('[SetUp"1"]')
            fen = import_format.match(fen.join(('[FEN"', '"]')))
            bishop_move = GameTextPGN()
            bishop_move.append_start_tag(setup)
            bishop_move.append_start_tag(fen)
            bishop_move.append_piece_move(bishop_match)
            pawn_move = GameTextPGN()
            pawn_move.append_start_tag(setup)
            pawn_move.append_start_tag(fen)
            pawn_move.append_pawn_move(pawn_match)
            if bishop_move._state is None and pawn_move._state is None:
                if match.group()[0].isupper():
                    self._undo_append_token_and_set_error()
                    super().append_piece_move(bishop_match)
                else:
                    self._undo_append_token_and_set_error()
                    self._append_pawn_move(pawn_match)
            elif bishop_move._state is None:
                self._undo_append_token_and_set_error()
                super().append_piece_move(bishop_match)
            elif pawn_move._state is None:
                self._undo_append_token_and_set_error()
                self._append_pawn_move(pawn_match)
            else:
                error_text = self._text[-1]
                self._undo_append_token_and_set_error()
                self.append_token_and_set_error(match)
                self._text[-1] = error_text
        elif pawn_lastindex:
            self._undo_append_token_and_set_error()
            self._append_pawn_move(pawn_match)
        elif bishop_lastindex:
            self._undo_append_token_and_set_error()
            super().append_piece_move(bishop_match)
        else:
            self.append_token_and_set_error(match)
        return bool(self._state is None)
def _append_recovered_bishop_or_bpawn_move ( self , match ) : mgt = match . group ( ) . lower ( ) promotion_match = text_format . match ( LAN_MOVE_SEPARATOR . join ( ( self . _bishop_or_bpawn . group ( ) . lower ( ) , mgt [ : - 1 ] + mgt [ - 1 ] . upper ( ) ) ) ) promotion_lastindex = ( promotion_match and promotion_match . lastindex == IFG_PAWN_PROMOTE_PIECE ) if not ( mgt . startswith ( LAN_MOVE_SEPARATOR ) or mgt . startswith ( PGN_CAPTURE_MOVE ) ) : mgt = LAN_MOVE_SEPARATOR + mgt bishop_match = text_format . match ( '' . join ( ( self . _bishop_or_bpawn . group ( ) . upper ( ) , mgt ) ) ) pawn_match = text_format . match ( '' . join ( ( self . _bishop_or_bpawn . group ( ) . lower ( ) , mgt ) ) ) bishop_lastindex = ( bishop_match and bishop_match . lastindex == IFG_PIECE_DESTINATION ) pawn_lastindex = ( pawn_match and ( pawn_match . lastindex == IFG_PAWN_TO_RANK or pawn_match . lastindex == IFG_PAWN_PROMOTE_PIECE ) ) if promotion_lastindex : self . _undo_append_token_and_set_error ( ) super ( ) . append_pawn_promote_move ( promotion_match ) self . _bishop_or_bpawn = None elif bishop_lastindex and pawn_lastindex : fen = generate_fen_for_position ( [ p for p in self . _piece_placement_data . values ( ) ] , self . _active_color , self . _castling_availability , self . _en_passant_target_square , self . _halfmove_clock , self . _fullmove_number ) setup = import_format . match ( '[SetUp"1"]' ) fen = import_format . match ( fen . join ( ( '[FEN"' , '"]' ) ) ) bishop_move = GameTextPGN ( ) bishop_move . append_start_tag ( setup ) bishop_move . append_start_tag ( fen ) bishop_move . append_piece_move ( bishop_match ) pawn_move = GameTextPGN ( ) pawn_move . append_start_tag ( setup ) pawn_move . append_start_tag ( fen ) pawn_move . append_pawn_move ( pawn_match ) if bishop_move . _state is None and pawn_move . _state is None : if match . group ( ) [ 0 ] . isupper ( ) : self . _undo_append_token_and_set_error ( ) super ( ) . append_piece_move ( bishop_match ) else : self . _undo_append_token_and_set_error ( ) self . _append_pawn_move ( pawn_match ) elif bishop_move . _state is None : self . _undo_append_token_and_set_error ( ) super ( ) . append_piece_move ( bishop_match ) elif pawn_move . _state is None : self . _undo_append_token_and_set_error ( ) self . _append_pawn_move ( pawn_match ) else : error_text = self . _text [ - 1 ] self . _undo_append_token_and_set_error ( ) self . append_token_and_set_error ( match ) self . _text [ - 1 ] = error_text elif pawn_lastindex : self . _undo_append_token_and_set_error ( ) self . _append_pawn_move ( pawn_match ) elif bishop_lastindex : self . _undo_append_token_and_set_error ( ) super ( ) . append_piece_move ( bishop_match ) else : self . append_token_and_set_error ( match ) return bool ( self . _state is None )
Return True if match is resolved to a bishop or b-pawn move.
Return True if match is resolved to a bishop or b - pawn move .
"""Return True if match is resolved to a bishop or b-pawn move.""" # Try the available matches. # This looks equivalent to doing nothing, but if removed leads to # an exception in _append_pawn_move at 'if mgl[0] != mgl[3]:'. # Without the adjustment to self._text[-1] the text from match # appears in two adjacent self._text elements.
self
match