pgn_read/core/game.py
def append_piece_move(self, match):
        """Decide if match best fits piece or pawn move and delegate to
        appropriate superclass method.

        """
        group = match.group
        pm = group().lower()
        piece_match = text_format.match(
            pm[0].upper() + pm[1:] + match.string[match.end():match.end()+10])
        if (pm[0] in 'kqrn' or
            group(IFG_PIECE_DESTINATION)[0].lower() in 'defgh' or
            (PGN_CAPTURE_MOVE in pm and
             group(IFG_PIECE_DESTINATION)[0].lower() == 'b') or
            (PGN_CAPTURE_MOVE not in pm and
             group(IFG_PIECE_DESTINATION)[0].lower() in 'ac')):
            if piece_match.group(IFG_PIECE_MOVE) is None:
                self.append_token_and_set_error(match)
                return
            super(GameTextPGN, self).append_piece_move(piece_match)
            self._bishop_or_bpawn = None
            return
        pawn_match = text_format.match(pm)
        if pawn_match and pawn_match.lastindex != IFG_PAWN_TO_RANK:
            pawn_match = None
        if group(IFG_PIECE_DESTINATION)[1] in '18':
            peek_start = match.span(match.lastindex)[-1]
            if peek_start == len(match.string):
                pawn_promotion_match = None
            elif match.string[peek_start] != PGN_PROMOTION:
                pawn_promotion_match = None
            else:
                pawn_promotion_match = text_promotion_format.match(
                    pm + match.string[peek_start:peek_start+6].lower())
                if pawn_promotion_match:
                    pawn_promotion_match = text_format.match(
                        ''.join((pawn_promotion_match.group(TP_MOVE),
                                 pawn_promotion_match.group(
                                     TP_PROMOTE_TO_PIECE).upper(),
                                 )))
                    if (pawn_promotion_match and
                        (pawn_promotion_match.lastindex !=
                         IFG_PAWN_PROMOTE_PIECE)):
                        pawn_promotion_match = None
        else:
            pawn_promotion_match = None
        if self._movetext_offset is None:
            if not self.set_initial_position():
                self.append_token_and_set_error(match)
                return
            self._movetext_offset = len(self._text)
        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(piece_match)
        if pawn_match:
            pawn_move = GameTextPGN()
            pawn_move.append_start_tag(setup)
            pawn_move.append_start_tag(fen)
            pawn_move.append_pawn_move(pawn_match)
        if pawn_promotion_match:
            pawn_promotion_move = GameTextPGN()
            pawn_promotion_move.append_start_tag(setup)
            pawn_promotion_move.append_start_tag(fen)
            pawn_promotion_move.append_pawn_promote_move(pawn_promotion_match)
        if bishop_move.state is None:
            if not (pawn_match or pawn_promotion_match):
                super(GameTextPGN, self).append_piece_move(piece_match)
                self._bishop_or_bpawn = None
                return
            elif match[0].isupper():
                super(GameTextPGN, self).append_piece_move(piece_match)
                self._bishop_or_bpawn = None
                return
            else:

                # All tests passed with this commented code.
                # However I am not convinced it is safe to collapse the
                # conditionals under 'if bishop_move.state is None:' yet,
                # nor that the original code below is sound in the new
                # more limited scope.
                #super(GameTextPGN, self).append_piece_move(piece_match)
                #self._bishop_or_bpawn = None
                #return

                pass
        else:
            if (pawn_match and
                pawn_match.lastindex == IFG_PAWN_TO_RANK):
                super(GameTextPGN, self).append_pawn_move(pawn_match)
                self._bishop_or_bpawn = None
            elif (pawn_promotion_match and
                pawn_promotion_match.lastindex == IFG_PAWN_PROMOTE_PIECE):
                super(GameTextPGN, self
                      ).append_pawn_promote_move(pawn_promotion_match)
                self._bishop_or_bpawn = None
            else:
                self.append_token_and_set_error(match)
            return

        # Following code is mostly not used at version 2.1 compared with
        # previous version.  One route above falls through to here but it
        # seems 'self.is_move_interpreted_as_piece_move(match)' always
        # evalutes True.
        # Implication might be that move is always a bishop move, never a
        # pawn move, if bishop_move.state is None in the code above.
        if self.is_move_interpreted_as_piece_move(match):
            if piece_match.group(IFG_PIECE_MOVE) is None:
                self.append_token_and_set_error(match)
                return
            super(GameTextPGN, self).append_piece_move(piece_match)
            self._bishop_or_bpawn = None
            return
        if match.group(IFG_PIECE_DESTINATION)[1] in '18':
            peek_start = match.span(match.lastindex)[-1]
            if peek_start == len(match.string):
                self.append_token_and_set_error(match)
            elif match.string[peek_start] != PGN_PROMOTION:
                self.append_token_and_set_error(match)
            else:
                promotion_match = text_promotion_format.match(
                    pm + match.string[peek_start:peek_start+6].lower())
                if promotion_match is None:
                    self.append_token_and_set_error(match)
                    return
                promotion_match = text_format.match(
                    ''.join((promotion_match.group(TP_MOVE),
                             promotion_match.group(TP_PROMOTE_TO_PIECE).upper(),
                             )))
                if promotion_match is None:
                    self.append_token_and_set_error(match)
                    return
                super(GameTextPGN, self
                      ).append_pawn_promote_move(promotion_match)
                self._promotion_disambiguation_detected = True
                self._bishop_or_bpawn = None
            return
        piece_match = text_format.match(pm)
        if piece_match.group(IFG_PAWN_FROM_FILE) is None:
            self.append_token_and_set_error(match)
            return
        super(GameTextPGN, self).append_pawn_move(piece_match)
        self._bishop_or_bpawn = None
Decide if match best fits piece or pawn move and delegate to
        appropriate superclass method.

        
Decide if match best fits piece or pawn move and delegate to
appropriate superclass method.
Decide if match best fits piece or pawn move and delegate to appropriate superclass method .
def append_piece_move(self, match):
        group = match.group
        pm = group().lower()
        piece_match = text_format.match(
            pm[0].upper() + pm[1:] + match.string[match.end():match.end()+10])
        if (pm[0] in 'kqrn' or
            group(IFG_PIECE_DESTINATION)[0].lower() in 'defgh' or
            (PGN_CAPTURE_MOVE in pm and
             group(IFG_PIECE_DESTINATION)[0].lower() == 'b') or
            (PGN_CAPTURE_MOVE not in pm and
             group(IFG_PIECE_DESTINATION)[0].lower() in 'ac')):
            if piece_match.group(IFG_PIECE_MOVE) is None:
                self.append_token_and_set_error(match)
                return
            super(GameTextPGN, self).append_piece_move(piece_match)
            self._bishop_or_bpawn = None
            return
        pawn_match = text_format.match(pm)
        if pawn_match and pawn_match.lastindex != IFG_PAWN_TO_RANK:
            pawn_match = None
        if group(IFG_PIECE_DESTINATION)[1] in '18':
            peek_start = match.span(match.lastindex)[-1]
            if peek_start == len(match.string):
                pawn_promotion_match = None
            elif match.string[peek_start] != PGN_PROMOTION:
                pawn_promotion_match = None
            else:
                pawn_promotion_match = text_promotion_format.match(
                    pm + match.string[peek_start:peek_start+6].lower())
                if pawn_promotion_match:
                    pawn_promotion_match = text_format.match(
                        ''.join((pawn_promotion_match.group(TP_MOVE),
                                 pawn_promotion_match.group(
                                     TP_PROMOTE_TO_PIECE).upper(),
                                 )))
                    if (pawn_promotion_match and
                        (pawn_promotion_match.lastindex !=
                         IFG_PAWN_PROMOTE_PIECE)):
                        pawn_promotion_match = None
        else:
            pawn_promotion_match = None
        if self._movetext_offset is None:
            if not self.set_initial_position():
                self.append_token_and_set_error(match)
                return
            self._movetext_offset = len(self._text)
        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(piece_match)
        if pawn_match:
            pawn_move = GameTextPGN()
            pawn_move.append_start_tag(setup)
            pawn_move.append_start_tag(fen)
            pawn_move.append_pawn_move(pawn_match)
        if pawn_promotion_match:
            pawn_promotion_move = GameTextPGN()
            pawn_promotion_move.append_start_tag(setup)
            pawn_promotion_move.append_start_tag(fen)
            pawn_promotion_move.append_pawn_promote_move(pawn_promotion_match)
        if bishop_move.state is None:
            if not (pawn_match or pawn_promotion_match):
                super(GameTextPGN, self).append_piece_move(piece_match)
                self._bishop_or_bpawn = None
                return
            elif match[0].isupper():
                super(GameTextPGN, self).append_piece_move(piece_match)
                self._bishop_or_bpawn = None
                return
            else:
                pass
        else:
            if (pawn_match and
                pawn_match.lastindex == IFG_PAWN_TO_RANK):
                super(GameTextPGN, self).append_pawn_move(pawn_match)
                self._bishop_or_bpawn = None
            elif (pawn_promotion_match and
                pawn_promotion_match.lastindex == IFG_PAWN_PROMOTE_PIECE):
                super(GameTextPGN, self
                      ).append_pawn_promote_move(pawn_promotion_match)
                self._bishop_or_bpawn = None
            else:
                self.append_token_and_set_error(match)
            return
        if self.is_move_interpreted_as_piece_move(match):
            if piece_match.group(IFG_PIECE_MOVE) is None:
                self.append_token_and_set_error(match)
                return
            super(GameTextPGN, self).append_piece_move(piece_match)
            self._bishop_or_bpawn = None
            return
        if match.group(IFG_PIECE_DESTINATION)[1] in '18':
            peek_start = match.span(match.lastindex)[-1]
            if peek_start == len(match.string):
                self.append_token_and_set_error(match)
            elif match.string[peek_start] != PGN_PROMOTION:
                self.append_token_and_set_error(match)
            else:
                promotion_match = text_promotion_format.match(
                    pm + match.string[peek_start:peek_start+6].lower())
                if promotion_match is None:
                    self.append_token_and_set_error(match)
                    return
                promotion_match = text_format.match(
                    ''.join((promotion_match.group(TP_MOVE),
                             promotion_match.group(TP_PROMOTE_TO_PIECE).upper(),
                             )))
                if promotion_match is None:
                    self.append_token_and_set_error(match)
                    return
                super(GameTextPGN, self
                      ).append_pawn_promote_move(promotion_match)
                self._promotion_disambiguation_detected = True
                self._bishop_or_bpawn = None
            return
        piece_match = text_format.match(pm)
        if piece_match.group(IFG_PAWN_FROM_FILE) is None:
            self.append_token_and_set_error(match)
            return
        super(GameTextPGN, self).append_pawn_move(piece_match)
        self._bishop_or_bpawn = None
def append_piece_move ( self , match ) : group = match . group pm = group ( ) . lower ( ) piece_match = text_format . match ( pm [ 0 ] . upper ( ) + pm [ 1 : ] + match . string [ match . end ( ) : match . end ( ) + 10 ] ) if ( pm [ 0 ] in 'kqrn' or group ( IFG_PIECE_DESTINATION ) [ 0 ] . lower ( ) in 'defgh' or ( PGN_CAPTURE_MOVE in pm and group ( IFG_PIECE_DESTINATION ) [ 0 ] . lower ( ) == 'b' ) or ( PGN_CAPTURE_MOVE not in pm and group ( IFG_PIECE_DESTINATION ) [ 0 ] . lower ( ) in 'ac' ) ) : if piece_match . group ( IFG_PIECE_MOVE ) is None : self . append_token_and_set_error ( match ) return super ( GameTextPGN , self ) . append_piece_move ( piece_match ) self . _bishop_or_bpawn = None return pawn_match = text_format . match ( pm ) if pawn_match and pawn_match . lastindex != IFG_PAWN_TO_RANK : pawn_match = None if group ( IFG_PIECE_DESTINATION ) [ 1 ] in '18' : peek_start = match . span ( match . lastindex ) [ - 1 ] if peek_start == len ( match . string ) : pawn_promotion_match = None elif match . string [ peek_start ] != PGN_PROMOTION : pawn_promotion_match = None else : pawn_promotion_match = text_promotion_format . match ( pm + match . string [ peek_start : peek_start + 6 ] . lower ( ) ) if pawn_promotion_match : pawn_promotion_match = text_format . match ( '' . join ( ( pawn_promotion_match . group ( TP_MOVE ) , pawn_promotion_match . group ( TP_PROMOTE_TO_PIECE ) . upper ( ) , ) ) ) if ( pawn_promotion_match and ( pawn_promotion_match . lastindex != IFG_PAWN_PROMOTE_PIECE ) ) : pawn_promotion_match = None else : pawn_promotion_match = None if self . _movetext_offset is None : if not self . set_initial_position ( ) : self . append_token_and_set_error ( match ) return self . _movetext_offset = len ( self . _text ) 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 ( piece_match ) if pawn_match : pawn_move = GameTextPGN ( ) pawn_move . append_start_tag ( setup ) pawn_move . append_start_tag ( fen ) pawn_move . append_pawn_move ( pawn_match ) if pawn_promotion_match : pawn_promotion_move = GameTextPGN ( ) pawn_promotion_move . append_start_tag ( setup ) pawn_promotion_move . append_start_tag ( fen ) pawn_promotion_move . append_pawn_promote_move ( pawn_promotion_match ) if bishop_move . state is None : if not ( pawn_match or pawn_promotion_match ) : super ( GameTextPGN , self ) . append_piece_move ( piece_match ) self . _bishop_or_bpawn = None return elif match [ 0 ] . isupper ( ) : super ( GameTextPGN , self ) . append_piece_move ( piece_match ) self . _bishop_or_bpawn = None return else : pass else : if ( pawn_match and pawn_match . lastindex == IFG_PAWN_TO_RANK ) : super ( GameTextPGN , self ) . append_pawn_move ( pawn_match ) self . _bishop_or_bpawn = None elif ( pawn_promotion_match and pawn_promotion_match . lastindex == IFG_PAWN_PROMOTE_PIECE ) : super ( GameTextPGN , self ) . append_pawn_promote_move ( pawn_promotion_match ) self . _bishop_or_bpawn = None else : self . append_token_and_set_error ( match ) return if self . is_move_interpreted_as_piece_move ( match ) : if piece_match . group ( IFG_PIECE_MOVE ) is None : self . append_token_and_set_error ( match ) return super ( GameTextPGN , self ) . append_piece_move ( piece_match ) self . _bishop_or_bpawn = None return if match . group ( IFG_PIECE_DESTINATION ) [ 1 ] in '18' : peek_start = match . span ( match . lastindex ) [ - 1 ] if peek_start == len ( match . string ) : self . append_token_and_set_error ( match ) elif match . string [ peek_start ] != PGN_PROMOTION : self . append_token_and_set_error ( match ) else : promotion_match = text_promotion_format . match ( pm + match . string [ peek_start : peek_start + 6 ] . lower ( ) ) if promotion_match is None : self . append_token_and_set_error ( match ) return promotion_match = text_format . match ( '' . join ( ( promotion_match . group ( TP_MOVE ) , promotion_match . group ( TP_PROMOTE_TO_PIECE ) . upper ( ) , ) ) ) if promotion_match is None : self . append_token_and_set_error ( match ) return super ( GameTextPGN , self ) . append_pawn_promote_move ( promotion_match ) self . _promotion_disambiguation_detected = True self . _bishop_or_bpawn = None return piece_match = text_format . match ( pm ) if piece_match . group ( IFG_PAWN_FROM_FILE ) is None : self . append_token_and_set_error ( match ) return super ( GameTextPGN , self ) . append_pawn_move ( piece_match ) self . _bishop_or_bpawn = None
Decide if match best fits piece or pawn move and delegate to
appropriate superclass method.
Decide if match best fits piece or pawn move and delegate to appropriate superclass method .
"""Decide if match best fits piece or pawn move and delegate to
        appropriate superclass method.

        """ # All tests passed with this commented code. # However I am not convinced it is safe to collapse the # conditionals under 'if bishop_move.state is None:' yet, # nor that the original code below is sound in the new # more limited scope. #super(GameTextPGN, self).append_piece_move(piece_match) #self._bishop_or_bpawn = None #return # Following code is mostly not used at version 2.1 compared with # previous version.  One route above falls through to here but it # seems 'self.is_move_interpreted_as_piece_move(match)' always # evalutes True. # Implication might be that move is always a bishop move, never a # pawn move, if bishop_move.state is None in the code above.
self
match