pgn_read/core/game.py
def append_start_rav(self, match):
        """Append start recursive annotation variation token to game score and
        update board state.

        Put game in error state if a variation cannot be put at current place
        in game score.

        """
        # The formal syntax for PGN, section 18 in specification, allows text
        # such as, for example:
        # '12 ( 12. e4 )'
        # '. ( 12 e4 )'
        # '...... ( 12 e4 )'
        # '...12... 13 ( 12 e4 )'
        # This program ignores numbers and dots for state and storage of games.
        # The formal syntax also allows recursive annotation variations before
        # the first SAN-move.  Section 8.2.5 in specification implies recursive
        # annotation variations must be preceded by a SAN-move.  Section 8.2.5
        # is implemented here because a variation varies from something.
        if self._movetext_offset is None:
            self.append_token_and_set_error(match)
            return

        if len(self._ravstack[-1]) == 1:
            if self._position_deltas[-1] is None:
                self.append_token_and_set_error(match)
                return
            if len(self._position_deltas[-1]) == 1:
                self.set_position_to_play_right_nested_rav_at_move()
            else:
                self.set_position_to_play_first_rav_at_move()

        # The 'Nf3((Nc3)a3(e3))' cases caught here fail the tests below on
        # self._ravstack[-1][2] because it is None, but are processed in
        # the same way.
        elif self._continue_current_choice():

            # Clear out stuff left over from previous RAV at this level.
            del self._ravstack[-1][1:]

            self.set_position_to_play_first_rav_at_move()
        elif (self._ravstack[-1][2][1] != self._active_color or
              self._ravstack[-1][2][5] != self._fullmove_number):

            # Clear out stuff left over from previous RAV at this level.
            del self._ravstack[-1][1:]

            self.set_position_to_play_first_rav_at_move()
        else:
            self.reset_board_state(
                ((self._ravstack[-1][1],) + self._ravstack[-1][-1][1:],))

            # This is most of set_position_to_play_right_nested_rav_at_move.
            rav_piece_placement_data = self._position_deltas[-1][0][0]
            pieces_on_board = self._pieces_on_board
            for v in pieces_on_board.values():
                v.clear()
            piece_placement_data = self._piece_placement_data
            piece_placement_data.clear()
            for piece, square in rav_piece_placement_data:
                piece_placement_data[square] = piece
                piece.set_square(square)
                if piece.name == FEN_WHITE_PAWN:
                    pieces_on_board[piece.square.file + FEN_WHITE_PAWN
                                    ].append(piece)
                elif piece.name == FEN_BLACK_PAWN:
                    pieces_on_board[piece.square.file + FEN_BLACK_PAWN
                                    ].append(piece)
                else:
                    pieces_on_board[piece.name].append(piece)

            (self._active_color,
             self._castling_availability,
             self._en_passant_target_square,
             self._halfmove_clock,
             self._fullmove_number,
             ) = self._ravstack[-1][-1][1:]
        self._ravstack[-1][0] += 1
        self._ravstack.append([0])
        self._text.append(match.group())
        self._state_stack.append(self._state)
Append start recursive annotation variation token to game score and
        update board state.

        Put game in error state if a variation cannot be put at current place
        in game score.

        
Append start recursive annotation variation token to game score and
update board state.

Put game in error state if a variation cannot be put at current place
in game score.
Append start recursive annotation variation token to game score and update board state . Put game in error state if a variation cannot be put at current place in game score .
def append_start_rav(self, match):
        if self._movetext_offset is None:
            self.append_token_and_set_error(match)
            return
        if len(self._ravstack[-1]) == 1:
            if self._position_deltas[-1] is None:
                self.append_token_and_set_error(match)
                return
            if len(self._position_deltas[-1]) == 1:
                self.set_position_to_play_right_nested_rav_at_move()
            else:
                self.set_position_to_play_first_rav_at_move()
        elif self._continue_current_choice():
            del self._ravstack[-1][1:]
            self.set_position_to_play_first_rav_at_move()
        elif (self._ravstack[-1][2][1] != self._active_color or
              self._ravstack[-1][2][5] != self._fullmove_number):
            del self._ravstack[-1][1:]
            self.set_position_to_play_first_rav_at_move()
        else:
            self.reset_board_state(
                ((self._ravstack[-1][1],) + self._ravstack[-1][-1][1:],))
            rav_piece_placement_data = self._position_deltas[-1][0][0]
            pieces_on_board = self._pieces_on_board
            for v in pieces_on_board.values():
                v.clear()
            piece_placement_data = self._piece_placement_data
            piece_placement_data.clear()
            for piece, square in rav_piece_placement_data:
                piece_placement_data[square] = piece
                piece.set_square(square)
                if piece.name == FEN_WHITE_PAWN:
                    pieces_on_board[piece.square.file + FEN_WHITE_PAWN
                                    ].append(piece)
                elif piece.name == FEN_BLACK_PAWN:
                    pieces_on_board[piece.square.file + FEN_BLACK_PAWN
                                    ].append(piece)
                else:
                    pieces_on_board[piece.name].append(piece)
            (self._active_color,
             self._castling_availability,
             self._en_passant_target_square,
             self._halfmove_clock,
             self._fullmove_number,
             ) = self._ravstack[-1][-1][1:]
        self._ravstack[-1][0] += 1
        self._ravstack.append([0])
        self._text.append(match.group())
        self._state_stack.append(self._state)
def append_start_rav ( self , match ) : if self . _movetext_offset is None : self . append_token_and_set_error ( match ) return if len ( self . _ravstack [ - 1 ] ) == 1 : if self . _position_deltas [ - 1 ] is None : self . append_token_and_set_error ( match ) return if len ( self . _position_deltas [ - 1 ] ) == 1 : self . set_position_to_play_right_nested_rav_at_move ( ) else : self . set_position_to_play_first_rav_at_move ( ) elif self . _continue_current_choice ( ) : del self . _ravstack [ - 1 ] [ 1 : ] self . set_position_to_play_first_rav_at_move ( ) elif ( self . _ravstack [ - 1 ] [ 2 ] [ 1 ] != self . _active_color or self . _ravstack [ - 1 ] [ 2 ] [ 5 ] != self . _fullmove_number ) : del self . _ravstack [ - 1 ] [ 1 : ] self . set_position_to_play_first_rav_at_move ( ) else : self . reset_board_state ( ( ( self . _ravstack [ - 1 ] [ 1 ] , ) + self . _ravstack [ - 1 ] [ - 1 ] [ 1 : ] , ) ) rav_piece_placement_data = self . _position_deltas [ - 1 ] [ 0 ] [ 0 ] pieces_on_board = self . _pieces_on_board for v in pieces_on_board . values ( ) : v . clear ( ) piece_placement_data = self . _piece_placement_data piece_placement_data . clear ( ) for piece , square in rav_piece_placement_data : piece_placement_data [ square ] = piece piece . set_square ( square ) if piece . name == FEN_WHITE_PAWN : pieces_on_board [ piece . square . file + FEN_WHITE_PAWN ] . append ( piece ) elif piece . name == FEN_BLACK_PAWN : pieces_on_board [ piece . square . file + FEN_BLACK_PAWN ] . append ( piece ) else : pieces_on_board [ piece . name ] . append ( piece ) ( self . _active_color , self . _castling_availability , self . _en_passant_target_square , self . _halfmove_clock , self . _fullmove_number , ) = self . _ravstack [ - 1 ] [ - 1 ] [ 1 : ] self . _ravstack [ - 1 ] [ 0 ] += 1 self . _ravstack . append ( [ 0 ] ) self . _text . append ( match . group ( ) ) self . _state_stack . append ( self . _state )
Append start recursive annotation variation token to game score and
update board state.
Append start recursive annotation variation token to game score and update board state .
"""Append start recursive annotation variation token to game score and
        update board state.

        Put game in error state if a variation cannot be put at current place
        in game score.

        """ # The formal syntax for PGN, section 18 in specification, allows text # such as, for example: # '12 ( 12. e4 )' # '. ( 12 e4 )' # '...... ( 12 e4 )' # '...12... 13 ( 12 e4 )' # This program ignores numbers and dots for state and storage of games. # The formal syntax also allows recursive annotation variations before # the first SAN-move.  Section 8.2.5 in specification implies recursive # annotation variations must be preceded by a SAN-move.  Section 8.2.5 # is implemented here because a variation varies from something. # The 'Nf3((Nc3)a3(e3))' cases caught here fail the tests below on # self._ravstack[-1][2] because it is None, but are processed in # the same way. # Clear out stuff left over from previous RAV at this level. # Clear out stuff left over from previous RAV at this level. # This is most of set_position_to_play_right_nested_rav_at_move.
self
match