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

        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)
        piece_placement_data = self._piece_placement_data
        if self._active_color == FEN_WHITE_ACTIVE:
            king_square = FILE_NAMES[4] + RANK_NAMES[-1]
            fullmove_number_for_next_halfmove = self._fullmove_number
        else:
            king_square = FILE_NAMES[4] + RANK_NAMES[0]
            fullmove_number_for_next_halfmove = self._fullmove_number + 1
        if king_square not in piece_placement_data:
            self.append_token_and_set_error(match)
            return
        castling_move = match.group(IFG_CASTLES)
        if CASTLING_MOVE_RIGHTS[self._active_color, castling_move
                                ] not in self._castling_availability:
            self.append_token_and_set_error(match)
            return
        if castling_move == PGN_O_O:
            if self._active_color == FEN_WHITE_ACTIVE:
                rook_square = FILE_NAMES[7] + RANK_NAMES[-1]
                king_destination = FILE_NAMES[6] + RANK_NAMES[-1]
                rook_destination = FILE_NAMES[5] + RANK_NAMES[-1]
            else:
                rook_square = FILE_NAMES[7] + RANK_NAMES[0]
                king_destination = FILE_NAMES[6] + RANK_NAMES[0]
                rook_destination = FILE_NAMES[5] + RANK_NAMES[0]
        elif self._active_color == FEN_WHITE_ACTIVE:
            rook_square = FILE_NAMES[0] + RANK_NAMES[-1]
            king_destination = FILE_NAMES[2] + RANK_NAMES[-1]
            rook_destination = FILE_NAMES[3] + RANK_NAMES[-1]
        else:
            rook_square = FILE_NAMES[0] + RANK_NAMES[0]
            king_destination = FILE_NAMES[2] + RANK_NAMES[0]
            rook_destination = FILE_NAMES[3] + RANK_NAMES[0]
        if rook_square not in piece_placement_data:
            self.append_token_and_set_error(match)
            return
        if not self.line_empty(king_square, rook_square):
            self.append_token_and_set_error(match)
            return

        # Cannot castle if king is in check, king would be in check if move
        # completed, or the square between the source and destination is
        # attacked by the other side.
        # No need to test if king is in check after applying remove and place
        # instructions to board.
        ptp = POINT_TO_POINT[king_square, king_destination]
        for square in king_square, king_destination, ptp[2][ptp[0]:ptp[1]][0]:
            if self.is_square_attacked_by_other_side(square):
                self.append_token_and_set_error(match)
                return

        king = piece_placement_data[king_square]
        rook = piece_placement_data[rook_square]
        remove = ((king_square, king), (rook_square, rook))
        self.remove_piece_on_square(remove[0])
        self.remove_piece_on_square(remove[1])
        place = ((king_destination, king), (rook_destination, rook))
        self.place_piece_on_square(place[0])
        self.place_piece_on_square(place[1])
        self._text.append(match.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,
              self._halfmove_clock + 1,
              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 castling move token to game score and update board state.

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

        
Append castling move token to game score and update board state.
Put game in error state if the token represents an illegal move.
Append castling move token to game score and update board state . Put game in error state if the token represents an illegal move .
def append_castles(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)
        piece_placement_data = self._piece_placement_data
        if self._active_color == FEN_WHITE_ACTIVE:
            king_square = FILE_NAMES[4] + RANK_NAMES[-1]
            fullmove_number_for_next_halfmove = self._fullmove_number
        else:
            king_square = FILE_NAMES[4] + RANK_NAMES[0]
            fullmove_number_for_next_halfmove = self._fullmove_number + 1
        if king_square not in piece_placement_data:
            self.append_token_and_set_error(match)
            return
        castling_move = match.group(IFG_CASTLES)
        if CASTLING_MOVE_RIGHTS[self._active_color, castling_move
                                ] not in self._castling_availability:
            self.append_token_and_set_error(match)
            return
        if castling_move == PGN_O_O:
            if self._active_color == FEN_WHITE_ACTIVE:
                rook_square = FILE_NAMES[7] + RANK_NAMES[-1]
                king_destination = FILE_NAMES[6] + RANK_NAMES[-1]
                rook_destination = FILE_NAMES[5] + RANK_NAMES[-1]
            else:
                rook_square = FILE_NAMES[7] + RANK_NAMES[0]
                king_destination = FILE_NAMES[6] + RANK_NAMES[0]
                rook_destination = FILE_NAMES[5] + RANK_NAMES[0]
        elif self._active_color == FEN_WHITE_ACTIVE:
            rook_square = FILE_NAMES[0] + RANK_NAMES[-1]
            king_destination = FILE_NAMES[2] + RANK_NAMES[-1]
            rook_destination = FILE_NAMES[3] + RANK_NAMES[-1]
        else:
            rook_square = FILE_NAMES[0] + RANK_NAMES[0]
            king_destination = FILE_NAMES[2] + RANK_NAMES[0]
            rook_destination = FILE_NAMES[3] + RANK_NAMES[0]
        if rook_square not in piece_placement_data:
            self.append_token_and_set_error(match)
            return
        if not self.line_empty(king_square, rook_square):
            self.append_token_and_set_error(match)
            return
        ptp = POINT_TO_POINT[king_square, king_destination]
        for square in king_square, king_destination, ptp[2][ptp[0]:ptp[1]][0]:
            if self.is_square_attacked_by_other_side(square):
                self.append_token_and_set_error(match)
                return
        king = piece_placement_data[king_square]
        rook = piece_placement_data[rook_square]
        remove = ((king_square, king), (rook_square, rook))
        self.remove_piece_on_square(remove[0])
        self.remove_piece_on_square(remove[1])
        place = ((king_destination, king), (rook_destination, rook))
        self.place_piece_on_square(place[0])
        self.place_piece_on_square(place[1])
        self._text.append(match.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,
              self._halfmove_clock + 1,
              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_castles ( 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 ) piece_placement_data = self . _piece_placement_data if self . _active_color == FEN_WHITE_ACTIVE : king_square = FILE_NAMES [ 4 ] + RANK_NAMES [ - 1 ] fullmove_number_for_next_halfmove = self . _fullmove_number else : king_square = FILE_NAMES [ 4 ] + RANK_NAMES [ 0 ] fullmove_number_for_next_halfmove = self . _fullmove_number + 1 if king_square not in piece_placement_data : self . append_token_and_set_error ( match ) return castling_move = match . group ( IFG_CASTLES ) if CASTLING_MOVE_RIGHTS [ self . _active_color , castling_move ] not in self . _castling_availability : self . append_token_and_set_error ( match ) return if castling_move == PGN_O_O : if self . _active_color == FEN_WHITE_ACTIVE : rook_square = FILE_NAMES [ 7 ] + RANK_NAMES [ - 1 ] king_destination = FILE_NAMES [ 6 ] + RANK_NAMES [ - 1 ] rook_destination = FILE_NAMES [ 5 ] + RANK_NAMES [ - 1 ] else : rook_square = FILE_NAMES [ 7 ] + RANK_NAMES [ 0 ] king_destination = FILE_NAMES [ 6 ] + RANK_NAMES [ 0 ] rook_destination = FILE_NAMES [ 5 ] + RANK_NAMES [ 0 ] elif self . _active_color == FEN_WHITE_ACTIVE : rook_square = FILE_NAMES [ 0 ] + RANK_NAMES [ - 1 ] king_destination = FILE_NAMES [ 2 ] + RANK_NAMES [ - 1 ] rook_destination = FILE_NAMES [ 3 ] + RANK_NAMES [ - 1 ] else : rook_square = FILE_NAMES [ 0 ] + RANK_NAMES [ 0 ] king_destination = FILE_NAMES [ 2 ] + RANK_NAMES [ 0 ] rook_destination = FILE_NAMES [ 3 ] + RANK_NAMES [ 0 ] if rook_square not in piece_placement_data : self . append_token_and_set_error ( match ) return if not self . line_empty ( king_square , rook_square ) : self . append_token_and_set_error ( match ) return ptp = POINT_TO_POINT [ king_square , king_destination ] for square in king_square , king_destination , ptp [ 2 ] [ ptp [ 0 ] : ptp [ 1 ] ] [ 0 ] : if self . is_square_attacked_by_other_side ( square ) : self . append_token_and_set_error ( match ) return king = piece_placement_data [ king_square ] rook = piece_placement_data [ rook_square ] remove = ( ( king_square , king ) , ( rook_square , rook ) ) self . remove_piece_on_square ( remove [ 0 ] ) self . remove_piece_on_square ( remove [ 1 ] ) place = ( ( king_destination , king ) , ( rook_destination , rook ) ) self . place_piece_on_square ( place [ 0 ] ) self . place_piece_on_square ( place [ 1 ] ) self . _text . append ( match . 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 , self . _halfmove_clock + 1 , 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 castling move token to game score and update board state.
Append castling move token to game score and update board state .
"""Append castling move token to game score and update board state.

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

        """ # Cannot castle if king is in check, king would be in check if move # completed, or the square between the source and destination is # attacked by the other side. # No need to test if king is in check after applying remove and place # instructions to board.
self
match