pgn_read/core/game.py
def append_pawn_move(self, match):
        """Append pawn move token to game score and update board state.

        Pawn promotion moves are handled by append_pawn_promote_move.

        Put game in error state if the token represents an illegal move.

        """
        if self._movetext_offset is None:
            if not self.set_initial_position():
                self.append_token_and_set_error(match)
                return
            self._ravstack.append([0])
            self._movetext_offset = len(self._text)
        group = match.group
        piece_placement_data = self._piece_placement_data

        # Pawn move and capture.

        if group(IFG_PAWN_CAPTURE_TO_FILE):
            destination = (group(IFG_PAWN_CAPTURE_TO_FILE) +
                           group(IFG_PAWN_TO_RANK))
            pawn_capture_from_file = group(IFG_PAWN_FROM_FILE)
            if self._active_color == FEN_WHITE_ACTIVE:
                fullmove_number_for_next_halfmove = self._fullmove_number
                source_squares_index = FEN_WHITE_PAWN + PGN_CAPTURE_MOVE
            else:
                fullmove_number_for_next_halfmove = self._fullmove_number + 1
                source_squares_index = FEN_BLACK_PAWN + PGN_CAPTURE_MOVE
            try:
                source_squares = SOURCE_SQUARES[source_squares_index
                                                ][destination]
            except KeyError:
                self.append_token_and_set_error(match)
                return
            for source in source_squares:
                if source.startswith(pawn_capture_from_file):
                    try:
                        if FEN_PAWNS.get(piece_placement_data[source].name
                                         ) == self._active_color:
                            piece = piece_placement_data[source]
                            break
                    except KeyError:
                        self.append_token_and_set_error(match)
                        return
            else:
                self.append_token_and_set_error(match)
                return
            if destination not in piece_placement_data:
                if self._en_passant_target_square == FEN_NULL:
                    self.append_token_and_set_error(match)
                    return
                capture_square = EN_PASSANT_TARGET_SQUARES.get(group()[:4])
                if not capture_square:
                    self.append_token_and_set_error(match)
                    return
                if capture_square not in piece_placement_data:
                    self.append_token_and_set_error(match)
                    return
                if FEN_PAWNS.get(piece_placement_data[capture_square].name
                                 ) == self._active_color:
                    self.append_token_and_set_error(match)
                    return
            elif piece_placement_data[source
                                      ].color == piece_placement_data[
                                          destination].color:
                self.append_token_and_set_error(match)
                return
            else:
                capture_square = destination
            remove = ((capture_square,
                       piece_placement_data[capture_square]),
                      (piece.square.name, piece))
            self.remove_piece_from_board(remove[0])
            self.remove_piece_from_board(remove[1])
            place = destination, piece
            self.place_piece_on_board(place)
            if self.is_square_attacked_by_other_side(
                self._pieces_on_board[PIECE_TO_KING[piece.name]
                                      ][0].square.name):
                self.remove_piece_from_board(place)
                self.place_piece_on_board(remove[0])
                self.place_piece_on_board(remove[1])
                self.append_token_and_set_error(match)
                return
            self._text.append(group())
            self.modify_board_state(
                ((remove,
                  self._active_color,
                  self._castling_availability,
                  self._en_passant_target_square,
                  self._halfmove_clock,
                  self._fullmove_number),
                 ((place,),
                  OTHER_SIDE[self._active_color],
                  self.get_castling_options_after_move_applied(remove),
                  FEN_NULL,
                  0,
                  fullmove_number_for_next_halfmove),
                 ))
            (self._active_color,
             self._castling_availability,
             self._en_passant_target_square,
             self._halfmove_clock,
             self._fullmove_number,
             ) = self._position_deltas[-1][1][1:]
            self.append_check_indicator()
            return

        # Pawn move without capture.

        destination = group(IFG_PAWN_FROM_FILE) + group(IFG_PAWN_TO_RANK)
        if destination in piece_placement_data:

            # The pawn-like move has been processed as part of a fully
            # disambiguated piece move.
            if self._full_disambiguation_detected:
                del self._full_disambiguation_detected
                return

            # Allow all movetext like 'e3e4' or 'e3xd4' when _strict_pgn
            # is not enforced, and perhaps even 'e3-e4'.  'exd4' is handled
            # in the 'Pawn move and capture' section, being within the PGN
            # specification.  Pawn promotions such as 'e7e8=Q' or 'e7xf8=Q'
            # are handled here, not by the append_pawn_promote_move method
            # which handles 'e8=Q' and 'exf8=Q'.
            if self._strict_pgn:
                self.append_token_and_set_error(match)
            else:
                self._long_algebraic_notation_pawn_move(match)
            return

        if self._active_color == FEN_WHITE_ACTIVE:
            fullmove_number_for_next_halfmove = self._fullmove_number
            source_squares_index = FEN_WHITE_PAWN
        else:
            fullmove_number_for_next_halfmove = self._fullmove_number + 1
            source_squares_index = FEN_BLACK_PAWN
        try:
            source_squares = SOURCE_SQUARES[source_squares_index][destination]
        except KeyError:
            self.append_token_and_set_error(match)
            return
        for source in source_squares:
            if source in piece_placement_data:
                piece = piece_placement_data[source]
                if FEN_PAWNS.get(piece.name) == self._active_color:
                    if self.line_empty(destination, source):
                        break
        else:
            self.append_token_and_set_error(match)
            return
        remove = piece.square.name, piece
        self.remove_piece_on_square(remove)
        new_en_passant_target_square = (
            EN_PASSANT_TARGET_SQUARES[
                OTHER_SIDE[self._active_color]].get(
                    (destination, piece.square.name),
                    FEN_NULL))
        place = destination, piece
        self.place_piece_on_square(place)
        if self.is_square_attacked_by_other_side(
            self._pieces_on_board[PIECE_TO_KING[piece.name]][0].square.name):
            self.remove_piece_on_square(place)
            self.place_piece_on_square(remove)
            self.append_token_and_set_error(match)
            return
        self._text.append(group())
        self.modify_board_state(
            (((remove,),
              self._active_color,
              self._castling_availability,
              self._en_passant_target_square,
              self._halfmove_clock,
              self._fullmove_number),
             ((place,),
              OTHER_SIDE[self._active_color],
              self.get_castling_options_after_move_applied((remove,)),
              new_en_passant_target_square,
              0,
              fullmove_number_for_next_halfmove),
             ))
        (self._active_color,
         self._castling_availability,
         self._en_passant_target_square,
         self._halfmove_clock,
         self._fullmove_number,
         ) = self._position_deltas[-1][1][1:]
        self.append_check_indicator()
Append pawn move token to game score and update board state.

        Pawn promotion moves are handled by append_pawn_promote_move.

        Put game in error state if the token represents an illegal move.

        
Append pawn move token to game score and update board state.
Pawn promotion moves are handled by append_pawn_promote_move.

Put game in error state if the token represents an illegal move.
Append pawn move token to game score and update board state . Pawn promotion moves are handled by append_pawn_promote_move . Put game in error state if the token represents an illegal move .
def append_pawn_move(self, match):
        if self._movetext_offset is None:
            if not self.set_initial_position():
                self.append_token_and_set_error(match)
                return
            self._ravstack.append([0])
            self._movetext_offset = len(self._text)
        group = match.group
        piece_placement_data = self._piece_placement_data
        if group(IFG_PAWN_CAPTURE_TO_FILE):
            destination = (group(IFG_PAWN_CAPTURE_TO_FILE) +
                           group(IFG_PAWN_TO_RANK))
            pawn_capture_from_file = group(IFG_PAWN_FROM_FILE)
            if self._active_color == FEN_WHITE_ACTIVE:
                fullmove_number_for_next_halfmove = self._fullmove_number
                source_squares_index = FEN_WHITE_PAWN + PGN_CAPTURE_MOVE
            else:
                fullmove_number_for_next_halfmove = self._fullmove_number + 1
                source_squares_index = FEN_BLACK_PAWN + PGN_CAPTURE_MOVE
            try:
                source_squares = SOURCE_SQUARES[source_squares_index
                                                ][destination]
            except KeyError:
                self.append_token_and_set_error(match)
                return
            for source in source_squares:
                if source.startswith(pawn_capture_from_file):
                    try:
                        if FEN_PAWNS.get(piece_placement_data[source].name
                                         ) == self._active_color:
                            piece = piece_placement_data[source]
                            break
                    except KeyError:
                        self.append_token_and_set_error(match)
                        return
            else:
                self.append_token_and_set_error(match)
                return
            if destination not in piece_placement_data:
                if self._en_passant_target_square == FEN_NULL:
                    self.append_token_and_set_error(match)
                    return
                capture_square = EN_PASSANT_TARGET_SQUARES.get(group()[:4])
                if not capture_square:
                    self.append_token_and_set_error(match)
                    return
                if capture_square not in piece_placement_data:
                    self.append_token_and_set_error(match)
                    return
                if FEN_PAWNS.get(piece_placement_data[capture_square].name
                                 ) == self._active_color:
                    self.append_token_and_set_error(match)
                    return
            elif piece_placement_data[source
                                      ].color == piece_placement_data[
                                          destination].color:
                self.append_token_and_set_error(match)
                return
            else:
                capture_square = destination
            remove = ((capture_square,
                       piece_placement_data[capture_square]),
                      (piece.square.name, piece))
            self.remove_piece_from_board(remove[0])
            self.remove_piece_from_board(remove[1])
            place = destination, piece
            self.place_piece_on_board(place)
            if self.is_square_attacked_by_other_side(
                self._pieces_on_board[PIECE_TO_KING[piece.name]
                                      ][0].square.name):
                self.remove_piece_from_board(place)
                self.place_piece_on_board(remove[0])
                self.place_piece_on_board(remove[1])
                self.append_token_and_set_error(match)
                return
            self._text.append(group())
            self.modify_board_state(
                ((remove,
                  self._active_color,
                  self._castling_availability,
                  self._en_passant_target_square,
                  self._halfmove_clock,
                  self._fullmove_number),
                 ((place,),
                  OTHER_SIDE[self._active_color],
                  self.get_castling_options_after_move_applied(remove),
                  FEN_NULL,
                  0,
                  fullmove_number_for_next_halfmove),
                 ))
            (self._active_color,
             self._castling_availability,
             self._en_passant_target_square,
             self._halfmove_clock,
             self._fullmove_number,
             ) = self._position_deltas[-1][1][1:]
            self.append_check_indicator()
            return
        destination = group(IFG_PAWN_FROM_FILE) + group(IFG_PAWN_TO_RANK)
        if destination in piece_placement_data:
            if self._full_disambiguation_detected:
                del self._full_disambiguation_detected
                return
            if self._strict_pgn:
                self.append_token_and_set_error(match)
            else:
                self._long_algebraic_notation_pawn_move(match)
            return
        if self._active_color == FEN_WHITE_ACTIVE:
            fullmove_number_for_next_halfmove = self._fullmove_number
            source_squares_index = FEN_WHITE_PAWN
        else:
            fullmove_number_for_next_halfmove = self._fullmove_number + 1
            source_squares_index = FEN_BLACK_PAWN
        try:
            source_squares = SOURCE_SQUARES[source_squares_index][destination]
        except KeyError:
            self.append_token_and_set_error(match)
            return
        for source in source_squares:
            if source in piece_placement_data:
                piece = piece_placement_data[source]
                if FEN_PAWNS.get(piece.name) == self._active_color:
                    if self.line_empty(destination, source):
                        break
        else:
            self.append_token_and_set_error(match)
            return
        remove = piece.square.name, piece
        self.remove_piece_on_square(remove)
        new_en_passant_target_square = (
            EN_PASSANT_TARGET_SQUARES[
                OTHER_SIDE[self._active_color]].get(
                    (destination, piece.square.name),
                    FEN_NULL))
        place = destination, piece
        self.place_piece_on_square(place)
        if self.is_square_attacked_by_other_side(
            self._pieces_on_board[PIECE_TO_KING[piece.name]][0].square.name):
            self.remove_piece_on_square(place)
            self.place_piece_on_square(remove)
            self.append_token_and_set_error(match)
            return
        self._text.append(group())
        self.modify_board_state(
            (((remove,),
              self._active_color,
              self._castling_availability,
              self._en_passant_target_square,
              self._halfmove_clock,
              self._fullmove_number),
             ((place,),
              OTHER_SIDE[self._active_color],
              self.get_castling_options_after_move_applied((remove,)),
              new_en_passant_target_square,
              0,
              fullmove_number_for_next_halfmove),
             ))
        (self._active_color,
         self._castling_availability,
         self._en_passant_target_square,
         self._halfmove_clock,
         self._fullmove_number,
         ) = self._position_deltas[-1][1][1:]
        self.append_check_indicator()
def append_pawn_move ( self , match ) : if self . _movetext_offset is None : if not self . set_initial_position ( ) : self . append_token_and_set_error ( match ) return self . _ravstack . append ( [ 0 ] ) self . _movetext_offset = len ( self . _text ) group = match . group piece_placement_data = self . _piece_placement_data if group ( IFG_PAWN_CAPTURE_TO_FILE ) : destination = ( group ( IFG_PAWN_CAPTURE_TO_FILE ) + group ( IFG_PAWN_TO_RANK ) ) pawn_capture_from_file = group ( IFG_PAWN_FROM_FILE ) if self . _active_color == FEN_WHITE_ACTIVE : fullmove_number_for_next_halfmove = self . _fullmove_number source_squares_index = FEN_WHITE_PAWN + PGN_CAPTURE_MOVE else : fullmove_number_for_next_halfmove = self . _fullmove_number + 1 source_squares_index = FEN_BLACK_PAWN + PGN_CAPTURE_MOVE try : source_squares = SOURCE_SQUARES [ source_squares_index ] [ destination ] except KeyError : self . append_token_and_set_error ( match ) return for source in source_squares : if source . startswith ( pawn_capture_from_file ) : try : if FEN_PAWNS . get ( piece_placement_data [ source ] . name ) == self . _active_color : piece = piece_placement_data [ source ] break except KeyError : self . append_token_and_set_error ( match ) return else : self . append_token_and_set_error ( match ) return if destination not in piece_placement_data : if self . _en_passant_target_square == FEN_NULL : self . append_token_and_set_error ( match ) return capture_square = EN_PASSANT_TARGET_SQUARES . get ( group ( ) [ : 4 ] ) if not capture_square : self . append_token_and_set_error ( match ) return if capture_square not in piece_placement_data : self . append_token_and_set_error ( match ) return if FEN_PAWNS . get ( piece_placement_data [ capture_square ] . name ) == self . _active_color : self . append_token_and_set_error ( match ) return elif piece_placement_data [ source ] . color == piece_placement_data [ destination ] . color : self . append_token_and_set_error ( match ) return else : capture_square = destination remove = ( ( capture_square , piece_placement_data [ capture_square ] ) , ( piece . square . name , piece ) ) self . remove_piece_from_board ( remove [ 0 ] ) self . remove_piece_from_board ( remove [ 1 ] ) place = destination , piece self . place_piece_on_board ( place ) if self . is_square_attacked_by_other_side ( self . _pieces_on_board [ PIECE_TO_KING [ piece . name ] ] [ 0 ] . square . name ) : self . remove_piece_from_board ( place ) self . place_piece_on_board ( remove [ 0 ] ) self . place_piece_on_board ( remove [ 1 ] ) self . append_token_and_set_error ( match ) return self . _text . append ( group ( ) ) self . modify_board_state ( ( ( remove , self . _active_color , self . _castling_availability , self . _en_passant_target_square , self . _halfmove_clock , self . _fullmove_number ) , ( ( place , ) , OTHER_SIDE [ self . _active_color ] , self . get_castling_options_after_move_applied ( remove ) , FEN_NULL , 0 , fullmove_number_for_next_halfmove ) , ) ) ( self . _active_color , self . _castling_availability , self . _en_passant_target_square , self . _halfmove_clock , self . _fullmove_number , ) = self . _position_deltas [ - 1 ] [ 1 ] [ 1 : ] self . append_check_indicator ( ) return destination = group ( IFG_PAWN_FROM_FILE ) + group ( IFG_PAWN_TO_RANK ) if destination in piece_placement_data : if self . _full_disambiguation_detected : del self . _full_disambiguation_detected return if self . _strict_pgn : self . append_token_and_set_error ( match ) else : self . _long_algebraic_notation_pawn_move ( match ) return if self . _active_color == FEN_WHITE_ACTIVE : fullmove_number_for_next_halfmove = self . _fullmove_number source_squares_index = FEN_WHITE_PAWN else : fullmove_number_for_next_halfmove = self . _fullmove_number + 1 source_squares_index = FEN_BLACK_PAWN try : source_squares = SOURCE_SQUARES [ source_squares_index ] [ destination ] except KeyError : self . append_token_and_set_error ( match ) return for source in source_squares : if source in piece_placement_data : piece = piece_placement_data [ source ] if FEN_PAWNS . get ( piece . name ) == self . _active_color : if self . line_empty ( destination , source ) : break else : self . append_token_and_set_error ( match ) return remove = piece . square . name , piece self . remove_piece_on_square ( remove ) new_en_passant_target_square = ( EN_PASSANT_TARGET_SQUARES [ OTHER_SIDE [ self . _active_color ] ] . get ( ( destination , piece . square . name ) , FEN_NULL ) ) place = destination , piece self . place_piece_on_square ( place ) if self . is_square_attacked_by_other_side ( self . _pieces_on_board [ PIECE_TO_KING [ piece . name ] ] [ 0 ] . square . name ) : self . remove_piece_on_square ( place ) self . place_piece_on_square ( remove ) self . append_token_and_set_error ( match ) return self . _text . append ( group ( ) ) self . modify_board_state ( ( ( ( remove , ) , self . _active_color , self . _castling_availability , self . _en_passant_target_square , self . _halfmove_clock , self . _fullmove_number ) , ( ( place , ) , OTHER_SIDE [ self . _active_color ] , self . get_castling_options_after_move_applied ( ( remove , ) ) , new_en_passant_target_square , 0 , fullmove_number_for_next_halfmove ) , ) ) ( self . _active_color , self . _castling_availability , self . _en_passant_target_square , self . _halfmove_clock , self . _fullmove_number , ) = self . _position_deltas [ - 1 ] [ 1 ] [ 1 : ] self . append_check_indicator ( )
Append pawn move token to game score and update board state.
Append pawn move token to game score and update board state .
"""Append pawn move token to game score and update board state.

        Pawn promotion moves are handled by append_pawn_promote_move.

        Put game in error state if the token represents an illegal move.

        """ # Pawn move and capture. # Pawn move without capture. # The pawn-like move has been processed as part of a fully # disambiguated piece move. # Allow all movetext like 'e3e4' or 'e3xd4' when _strict_pgn # is not enforced, and perhaps even 'e3-e4'.  'exd4' is handled # in the 'Pawn move and capture' section, being within the PGN # specification.  Pawn promotions such as 'e7e8=Q' or 'e7xf8=Q' # are handled here, not by the append_pawn_promote_move method # which handles 'e8=Q' and 'exf8=Q'.
self
match