idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
30,800 | def register_channel_post_handler ( self , callback , * custom_filters , commands = None , regexp = None , content_types = None , state = None , run_task = None , ** kwargs ) : filters_set = self . filters_factory . resolve ( self . channel_post_handlers , * custom_filters , commands = commands , regexp = regexp , cont... | Register handler for channel post |
30,801 | def channel_post_handler ( self , * custom_filters , commands = None , regexp = None , content_types = None , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_channel_post_handler ( callback , * custom_filters , commands = commands , regexp = regexp , content_types = content_t... | Decorator for channel post handler |
30,802 | def register_edited_channel_post_handler ( self , callback , * custom_filters , commands = None , regexp = None , content_types = None , state = None , run_task = None , ** kwargs ) : filters_set = self . filters_factory . resolve ( self . edited_message_handlers , * custom_filters , commands = commands , regexp = rege... | Register handler for edited channel post |
30,803 | def edited_channel_post_handler ( self , * custom_filters , commands = None , regexp = None , content_types = None , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_edited_channel_post_handler ( callback , * custom_filters , commands = commands , regexp = regexp , content_typ... | Decorator for edited channel post handler |
30,804 | def register_inline_handler ( self , callback , * custom_filters , state = None , run_task = None , ** kwargs ) : if custom_filters is None : custom_filters = [ ] filters_set = self . filters_factory . resolve ( self . inline_query_handlers , * custom_filters , state = state , ** kwargs ) self . inline_query_handlers .... | Register handler for inline query |
30,805 | def inline_handler ( self , * custom_filters , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_inline_handler ( callback , * custom_filters , state = state , run_task = run_task , ** kwargs ) return callback return decorator | Decorator for inline query handler |
30,806 | def register_chosen_inline_handler ( self , callback , * custom_filters , state = None , run_task = None , ** kwargs ) : if custom_filters is None : custom_filters = [ ] filters_set = self . filters_factory . resolve ( self . chosen_inline_result_handlers , * custom_filters , state = state , ** kwargs ) self . chosen_i... | Register handler for chosen inline query |
30,807 | def chosen_inline_handler ( self , * custom_filters , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_chosen_inline_handler ( callback , * custom_filters , state = state , run_task = run_task , ** kwargs ) return callback return decorator | Decorator for chosen inline query handler |
30,808 | def register_callback_query_handler ( self , callback , * custom_filters , state = None , run_task = None , ** kwargs ) : filters_set = self . filters_factory . resolve ( self . callback_query_handlers , * custom_filters , state = state , ** kwargs ) self . callback_query_handlers . register ( self . _wrap_async_task (... | Register handler for callback query |
30,809 | def callback_query_handler ( self , * custom_filters , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_callback_query_handler ( callback , * custom_filters , state = state , run_task = run_task , ** kwargs ) return callback return decorator | Decorator for callback query handler |
30,810 | def register_shipping_query_handler ( self , callback , * custom_filters , state = None , run_task = None , ** kwargs ) : filters_set = self . filters_factory . resolve ( self . shipping_query_handlers , * custom_filters , state = state , ** kwargs ) self . shipping_query_handlers . register ( self . _wrap_async_task (... | Register handler for shipping query |
30,811 | def shipping_query_handler ( self , * custom_filters , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_shipping_query_handler ( callback , * custom_filters , state = state , run_task = run_task , ** kwargs ) return callback return decorator | Decorator for shipping query handler |
30,812 | def register_pre_checkout_query_handler ( self , callback , * custom_filters , state = None , run_task = None , ** kwargs ) : filters_set = self . filters_factory . resolve ( self . pre_checkout_query_handlers , * custom_filters , state = state , ** kwargs ) self . pre_checkout_query_handlers . register ( self . _wrap_... | Register handler for pre - checkout query |
30,813 | def pre_checkout_query_handler ( self , * custom_filters , state = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_pre_checkout_query_handler ( callback , * custom_filters , state = state , run_task = run_task , ** kwargs ) return callback return decorator | Decorator for pre - checkout query handler |
30,814 | def register_errors_handler ( self , callback , * custom_filters , exception = None , run_task = None , ** kwargs ) : filters_set = self . filters_factory . resolve ( self . errors_handlers , * custom_filters , exception = exception , ** kwargs ) self . errors_handlers . register ( self . _wrap_async_task ( callback , ... | Register handler for errors |
30,815 | def errors_handler ( self , * custom_filters , exception = None , run_task = None , ** kwargs ) : def decorator ( callback ) : self . register_errors_handler ( self . _wrap_async_task ( callback , run_task ) , * custom_filters , exception = exception , ** kwargs ) return callback return decorator | Decorator for errors handler |
30,816 | def current_state ( self , * , chat : typing . Union [ str , int , None ] = None , user : typing . Union [ str , int , None ] = None ) -> FSMContext : if chat is None : chat_obj = types . Chat . get_current ( ) chat = chat_obj . id if chat_obj else None if user is None : user_obj = types . User . get_current ( ) user =... | Get current state for user in chat as context |
30,817 | async def throttle ( self , key , * , rate = None , user = None , chat = None , no_error = None ) -> bool : if not self . storage . has_bucket ( ) : raise RuntimeError ( 'This storage does not provide Leaky Bucket' ) if no_error is None : no_error = self . no_throttle_error if rate is None : rate = self . throttling_ra... | Execute throttling manager . Returns True if limit has not exceeded otherwise raises ThrottleError or returns False |
30,818 | async def check_key ( self , key , chat = None , user = None ) : if not self . storage . has_bucket ( ) : raise RuntimeError ( 'This storage does not provide Leaky Bucket' ) if user is None and chat is None : user = types . User . get_current ( ) chat = types . Chat . get_current ( ) bucket = await self . storage . get... | Get information about key in bucket |
30,819 | async def release_key ( self , key , chat = None , user = None ) : if not self . storage . has_bucket ( ) : raise RuntimeError ( 'This storage does not provide Leaky Bucket' ) if user is None and chat is None : user = types . User . get_current ( ) chat = types . Chat . get_current ( ) bucket = await self . storage . g... | Release blocked key |
30,820 | def check_token ( token : str ) -> bool : if any ( x . isspace ( ) for x in token ) : raise exceptions . ValidationError ( 'Token is invalid!' ) left , sep , right = token . partition ( ':' ) if ( not sep ) or ( not left . isdigit ( ) ) or ( len ( left ) < 3 ) : raise exceptions . ValidationError ( 'Token is invalid!' ... | Validate BOT token |
30,821 | def compose_data ( params = None , files = None ) : data = aiohttp . formdata . FormData ( quote_fields = False ) if params : for key , value in params . items ( ) : data . add_field ( key , str ( value ) ) if files : for key , f in files . items ( ) : if isinstance ( f , tuple ) : if len ( f ) == 2 : filename , fileob... | Prepare request data |
30,822 | def full_name ( self ) : full_name = self . first_name if self . last_name : full_name += ' ' + self . last_name return full_name | You can get full name of user . |
30,823 | def locale ( self ) -> babel . core . Locale or None : if not self . language_code : return None if not hasattr ( self , '_locale' ) : setattr ( self , '_locale' , babel . core . Locale . parse ( self . language_code , sep = '-' ) ) return getattr ( self , '_locale' ) | Get user s locale |
30,824 | async def get_file ( self ) : if hasattr ( self , 'file_path' ) : return self else : return await self . bot . get_file ( self . file_id ) | Get file information |
30,825 | async def trigger ( self , action : str , args : typing . Iterable ) : for app in self . applications : await app . trigger ( action , args ) | Call action to middlewares with args lilt . |
30,826 | async def trigger ( self , action , args ) : handler_name = f"on_{action}" handler = getattr ( self , handler_name , None ) if not handler : return None await handler ( * args ) | Trigger action . |
30,827 | def quote_html ( content ) : new_content = '' for symbol in content : new_content += HTML_QUOTES_MAP [ symbol ] if symbol in _HQS else symbol return new_content | Quote HTML symbols |
30,828 | async def migrate_redis1_to_redis2 ( storage1 : RedisStorage , storage2 : RedisStorage2 ) : if not isinstance ( storage1 , RedisStorage ) : raise TypeError ( f"{type(storage1)} is not RedisStorage instance." ) if not isinstance ( storage2 , RedisStorage ) : raise TypeError ( f"{type(storage2)} is not RedisStorage insta... | Helper for migrating from RedisStorage to RedisStorage2 |
30,829 | async def get_record ( self , * , chat : typing . Union [ str , int , None ] = None , user : typing . Union [ str , int , None ] = None ) -> typing . Dict : chat , user = self . check_address ( chat = chat , user = user ) addr = f"fsm:{chat}:{user}" conn = await self . redis ( ) data = await conn . execute ( 'GET' , ad... | Get record from storage |
30,830 | async def set_record ( self , * , chat : typing . Union [ str , int , None ] = None , user : typing . Union [ str , int , None ] = None , state = None , data = None , bucket = None ) : if data is None : data = { } if bucket is None : bucket = { } chat , user = self . check_address ( chat = chat , user = user ) addr = f... | Write record to storage |
30,831 | def add_directory ( self , directory : PathLike , * , load_wdl : bool = True , load_dtz : bool = True ) -> int : num = 0 directory = os . path . abspath ( directory ) for filename in os . listdir ( directory ) : path = os . path . join ( directory , filename ) tablename , ext = os . path . splitext ( filename ) if is_t... | Adds tables from a directory . |
30,832 | def probe_dtz ( self , board : chess . Board ) -> int : v = self . probe_dtz_no_ep ( board ) if not board . ep_square or self . variant . captures_compulsory : return v v1 = - 3 for move in board . generate_legal_ep ( ) : board . push ( move ) try : v0_plus , _ = self . probe_ab ( board , - 2 , 2 ) v0 = - v0_plus final... | Probes DTZ tables for distance to zero information . |
30,833 | def board ( self , * , _cache : bool = True ) -> chess . Board : if self . board_cached is not None : board = self . board_cached ( ) if board is not None : return board . copy ( ) board = self . parent . board ( _cache = False ) board . push ( self . move ) if _cache : self . board_cached = weakref . ref ( board ) ret... | Gets a board with the position of the node . |
30,834 | def root ( self ) -> "GameNode" : node = self while node . parent : node = node . parent return node | Gets the root node i . e . the game . |
30,835 | def end ( self ) -> "GameNode" : node = self while node . variations : node = node . variations [ 0 ] return node | Follows the main variation to the end and returns the last node . |
30,836 | def is_mainline ( self ) -> bool : node = self while node . parent : parent = node . parent if not parent . variations or parent . variations [ 0 ] != node : return False node = parent return True | Checks if the node is in the mainline of the game . |
30,837 | def is_main_variation ( self ) -> bool : if not self . parent : return True return not self . parent . variations or self . parent . variations [ 0 ] == self | Checks if this node is the first variation from the point of view of its parent . The root node is also in the main variation . |
30,838 | def promote ( self , move : chess . Move ) -> None : variation = self [ move ] i = self . variations . index ( variation ) if i > 0 : self . variations [ i - 1 ] , self . variations [ i ] = self . variations [ i ] , self . variations [ i - 1 ] | Moves a variation one up in the list of variations . |
30,839 | def demote ( self , move : chess . Move ) -> None : variation = self [ move ] i = self . variations . index ( variation ) if i < len ( self . variations ) - 1 : self . variations [ i + 1 ] , self . variations [ i ] = self . variations [ i ] , self . variations [ i + 1 ] | Moves a variation one down in the list of variations . |
30,840 | def remove_variation ( self , move : chess . Move ) -> None : self . variations . remove ( self . variation ( move ) ) | Removes a variation . |
30,841 | def add_variation ( self , move : chess . Move , * , comment : str = "" , starting_comment : str = "" , nags : Iterable [ int ] = ( ) ) -> "GameNode" : node = type ( self ) . dangling_node ( ) node . move = move node . nags = set ( nags ) node . comment = comment node . starting_comment = starting_comment node . parent... | Creates a child node with the given attributes . |
30,842 | def add_main_variation ( self , move : chess . Move , * , comment : str = "" ) -> "GameNode" : node = self . add_variation ( move , comment = comment ) self . variations . remove ( node ) self . variations . insert ( 0 , node ) return node | Creates a child node with the given attributes and promotes it to the main variation . |
30,843 | def board ( self , * , _cache : bool = False ) -> chess . Board : return self . headers . board ( ) | Gets the starting position of the game . |
30,844 | def parse_san ( self , board : chess . Board , san : str ) -> chess . Move : if san == "0-0" : san = "O-O" elif san == "0-0-0" : san = "O-O-O" return board . parse_san ( san ) | When the visitor is used by a parser this is called to parse a move in standard algebraic notation . |
30,845 | def read_description ( ) : with open ( os . path . join ( os . path . dirname ( __file__ ) , "README.rst" ) , encoding = "utf-8" ) as f : description = f . read ( ) description = description . replace ( "//python-chess.readthedocs.io/en/latest/" , "//python-chess.readthedocs.io/en/v{}/" . format ( chess . __version__ )... | Reads the description from README . rst and substitutes mentions of the latest version with a concrete version number . |
30,846 | async def popen_uci ( command : Union [ str , List [ str ] ] , * , setpgrp : bool = False , loop = None , ** popen_args : Any ) -> Tuple [ asyncio . SubprocessTransport , UciProtocol ] : transport , protocol = await UciProtocol . popen ( command , setpgrp = setpgrp , loop = loop , ** popen_args ) try : await protocol .... | Spawns and initializes an UCI engine . |
30,847 | async def popen_xboard ( command : Union [ str , List [ str ] ] , * , setpgrp : bool = False , ** popen_args : Any ) -> Tuple [ asyncio . SubprocessTransport , XBoardProtocol ] : transport , protocol = await XBoardProtocol . popen ( command , setpgrp = setpgrp , ** popen_args ) try : await protocol . initialize ( ) exc... | Spawns and initializes an XBoard engine . |
30,848 | def debug ( self , on : bool = True ) -> None : if on : self . send_line ( "debug on" ) else : self . send_line ( "debug off" ) | Switches debug mode of the engine on or off . This does not interrupt other ongoing operations . |
30,849 | def stop ( self ) -> None : if self . _stop and not self . _posted_kork : self . _stop ( ) self . _stop = None | Stops the analysis as soon as possible . |
30,850 | async def get ( self ) -> InfoDict : if self . _seen_kork : raise AnalysisComplete ( ) info = await self . _queue . get ( ) if not info : self . _seen_kork = True await self . _finished raise AnalysisComplete ( ) return info | Waits for the next dictionary of information from the engine and returns it . |
30,851 | def empty ( self ) -> bool : return self . _seen_kork or self . _queue . qsize ( ) <= self . _posted_kork | Checks if all information has been consumed . |
30,852 | def close ( self ) -> None : def _shutdown ( ) -> None : self . transport . close ( ) self . shutdown_event . set ( ) with self . _shutdown_lock : if not self . _shutdown : self . _shutdown = True self . protocol . loop . call_soon_threadsafe ( _shutdown ) | Closes the transport and the background event loop as soon as possible . |
30,853 | def open_tablebase_native ( directory : PathLike , * , libgtb : Any = None , LibraryLoader : Any = ctypes . cdll ) -> NativeTablebase : libgtb = libgtb or ctypes . util . find_library ( "gtb" ) or "libgtb.so.1.0.1" tables = NativeTablebase ( LibraryLoader . LoadLibrary ( libgtb ) ) tables . add_directory ( directory ) ... | Opens a collection of tables for probing using libgtb . |
30,854 | def open_tablebase ( directory : PathLike , * , libgtb : Any = None , LibraryLoader : Any = ctypes . cdll ) -> Union [ NativeTablebase , PythonTablebase ] : try : if LibraryLoader : return open_tablebase_native ( directory , libgtb = libgtb , LibraryLoader = LibraryLoader ) except ( OSError , RuntimeError ) as err : LO... | Opens a collection of tables for probing . |
30,855 | def probe_dtm ( self , board : chess . Board ) -> int : if board . castling_rights : raise KeyError ( "gaviota tables do not contain positions with castling rights: {}" . format ( board . fen ( ) ) ) if chess . popcount ( board . occupied ) > 5 : raise KeyError ( "gaviota tables support up to 5 pieces, not {}: {}" . fo... | Probes for depth to mate information . |
30,856 | def symbol ( self ) -> str : symbol = piece_symbol ( self . piece_type ) return symbol . upper ( ) if self . color else symbol | Gets the symbol P N B R Q or K for white pieces or the lower - case variants for the black pieces . |
30,857 | def unicode_symbol ( self , * , invert_color : bool = False ) -> str : symbol = self . symbol ( ) . swapcase ( ) if invert_color else self . symbol ( ) return UNICODE_PIECE_SYMBOLS [ symbol ] | Gets the Unicode character for the piece . |
30,858 | def uci ( self ) -> str : if self . drop : return piece_symbol ( self . drop ) . upper ( ) + "@" + SQUARE_NAMES [ self . to_square ] elif self . promotion : return SQUARE_NAMES [ self . from_square ] + SQUARE_NAMES [ self . to_square ] + piece_symbol ( self . promotion ) elif self : return SQUARE_NAMES [ self . from_sq... | Gets an UCI string for the move . |
30,859 | def from_uci ( cls , uci : str ) -> "Move" : if uci == "0000" : return cls . null ( ) elif len ( uci ) == 4 and "@" == uci [ 1 ] : drop = PIECE_SYMBOLS . index ( uci [ 0 ] . lower ( ) ) square = SQUARE_NAMES . index ( uci [ 2 : ] ) return cls ( square , square , drop = drop ) elif len ( uci ) == 4 : return cls ( SQUARE... | Parses an UCI string . |
30,860 | def pieces ( self , piece_type : PieceType , color : Color ) -> "SquareSet" : return SquareSet ( self . pieces_mask ( piece_type , color ) ) | Gets pieces of the given type and color . |
30,861 | def piece_type_at ( self , square : Square ) -> Optional [ PieceType ] : mask = BB_SQUARES [ square ] if not self . occupied & mask : return None elif self . pawns & mask : return PAWN elif self . knights & mask : return KNIGHT elif self . bishops & mask : return BISHOP elif self . rooks & mask : return ROOK elif self ... | Gets the piece type at the given square . |
30,862 | def king ( self , color : Color ) -> Optional [ Square ] : king_mask = self . occupied_co [ color ] & self . kings & ~ self . promoted return msb ( king_mask ) if king_mask else None | Finds the king square of the given side . Returns None if there is no king of that color . |
30,863 | def is_attacked_by ( self , color : Color , square : Square ) -> bool : return bool ( self . attackers_mask ( color , square ) ) | Checks if the given side attacks the given square . |
30,864 | def attackers ( self , color : Color , square : Square ) -> "SquareSet" : return SquareSet ( self . attackers_mask ( color , square ) ) | Gets a set of attackers of the given color for the given square . |
30,865 | def is_pinned ( self , color : Color , square : Square ) -> bool : return self . pin_mask ( color , square ) != BB_ALL | Detects if the given square is pinned to the king of the given color . |
30,866 | def set_piece_at ( self , square : Square , piece : Optional [ Piece ] , promoted : bool = False ) -> None : if piece is None : self . _remove_piece_at ( square ) else : self . _set_piece_at ( square , piece . piece_type , piece . color , promoted ) | Sets a piece at the given square . |
30,867 | def board_fen ( self , * , promoted : Optional [ bool ] = False ) -> str : builder = [ ] empty = 0 for square in SQUARES_180 : piece = self . piece_at ( square ) if not piece : empty += 1 else : if empty : builder . append ( str ( empty ) ) empty = 0 builder . append ( piece . symbol ( ) ) if promoted and BB_SQUARES [ ... | Gets the board FEN . |
30,868 | def chess960_pos ( self ) -> Optional [ int ] : if self . occupied_co [ WHITE ] != BB_RANK_1 | BB_RANK_2 : return None if self . occupied_co [ BLACK ] != BB_RANK_7 | BB_RANK_8 : return None if self . pawns != BB_RANK_2 | BB_RANK_7 : return None if self . promoted : return None brnqk = [ self . bishops , self . rooks , ... | Gets the Chess960 starting position index between 0 and 959 or None . |
30,869 | def mirror ( self : BaseBoardT ) -> BaseBoardT : board = self . transform ( flip_vertical ) board . occupied_co [ WHITE ] , board . occupied_co [ BLACK ] = board . occupied_co [ BLACK ] , board . occupied_co [ WHITE ] return board | Returns a mirrored copy of the board . |
30,870 | def from_chess960_pos ( cls : Type [ BaseBoardT ] , sharnagl : int ) -> BaseBoardT : board = cls . empty ( ) board . set_chess960_pos ( sharnagl ) return board | Creates a new board initialized with a Chess960 starting position . |
30,871 | def reset ( self ) -> None : self . turn = WHITE self . castling_rights = BB_CORNERS self . ep_square = None self . halfmove_clock = 0 self . fullmove_number = 1 self . reset_board ( ) | Restores the starting position . |
30,872 | def clear ( self ) -> None : self . turn = WHITE self . castling_rights = BB_EMPTY self . ep_square = None self . halfmove_clock = 0 self . fullmove_number = 1 self . clear_board ( ) | Clears the board . |
30,873 | def root ( self : BoardT ) -> BoardT : if self . _stack : board = type ( self ) ( None , chess960 = self . chess960 ) self . _stack [ 0 ] . restore ( board ) return board else : return self . copy ( stack = False ) | Returns a copy of the root position . |
30,874 | def is_check ( self ) -> bool : king = self . king ( self . turn ) return king is not None and self . is_attacked_by ( not self . turn , king ) | Returns if the current side to move is in check . |
30,875 | def is_into_check ( self , move : Move ) -> bool : king = self . king ( self . turn ) if king is None : return False checkers = self . attackers_mask ( not self . turn , king ) if checkers : if move not in self . _generate_evasions ( king , checkers , BB_SQUARES [ move . from_square ] , BB_SQUARES [ move . to_square ] ... | Checks if the given move would leave the king in check or put it into check . The move must be at least pseudo legal . |
30,876 | def was_into_check ( self ) -> bool : king = self . king ( not self . turn ) return king is not None and self . is_attacked_by ( self . turn , king ) | Checks if the king of the other side is attacked . Such a position is not valid and could only be reached by an illegal move . |
30,877 | def result ( self , * , claim_draw : bool = False ) -> str : if self . is_variant_loss ( ) : return "0-1" if self . turn == WHITE else "1-0" elif self . is_variant_win ( ) : return "1-0" if self . turn == WHITE else "0-1" elif self . is_variant_draw ( ) : return "1/2-1/2" if self . is_checkmate ( ) : return "0-1" if se... | Gets the game result . |
30,878 | def is_stalemate ( self ) -> bool : if self . is_check ( ) : return False if self . is_variant_end ( ) : return False return not any ( self . generate_legal_moves ( ) ) | Checks if the current position is a stalemate . |
30,879 | def can_claim_fifty_moves ( self ) -> bool : if self . halfmove_clock >= 100 : if any ( self . generate_legal_moves ( ) ) : return True return False | Draw by the fifty - move rule can be claimed once the clock of halfmoves since the last capture or pawn move becomes equal or greater to 100 and the side to move still has a legal move they can make . |
30,880 | def can_claim_threefold_repetition ( self ) -> bool : transposition_key = self . _transposition_key ( ) transpositions = collections . Counter ( ) transpositions . update ( ( transposition_key , ) ) switchyard = [ ] while self . move_stack : move = self . pop ( ) switchyard . append ( move ) if self . is_irreversible (... | Draw by threefold repetition can be claimed if the position on the board occured for the third time or if such a repetition is reached with one of the possible legal moves . |
30,881 | def pop ( self : BoardT ) -> Move : move = self . move_stack . pop ( ) self . _stack . pop ( ) . restore ( self ) return move | Restores the previous position and returns the last move from the stack . |
30,882 | def fen ( self , * , shredder : bool = False , en_passant : str = "legal" , promoted : Optional [ bool ] = None ) -> str : return " " . join ( [ self . epd ( shredder = shredder , en_passant = en_passant , promoted = promoted ) , str ( self . halfmove_clock ) , str ( self . fullmove_number ) ] ) | Gets a FEN representation of the position . |
30,883 | def set_fen ( self , fen : str ) -> None : parts = fen . split ( ) try : board_part = parts . pop ( 0 ) except IndexError : raise ValueError ( "empty fen" ) try : turn_part = parts . pop ( 0 ) except IndexError : turn = WHITE else : if turn_part == "w" : turn = WHITE elif turn_part == "b" : turn = BLACK else : raise Va... | Parses a FEN and sets the position from it . |
30,884 | def chess960_pos ( self , * , ignore_turn : bool = False , ignore_castling : bool = False , ignore_counters : bool = True ) -> Optional [ int ] : if self . ep_square : return None if not ignore_turn : if self . turn != WHITE : return None if not ignore_castling : if self . clean_castling_rights ( ) != self . rooks : re... | Gets the Chess960 starting position index between 0 and 956 or None if the current position is not a Chess960 starting position . |
30,885 | def epd ( self , * , shredder : bool = False , en_passant : str = "legal" , promoted : Optional [ bool ] = None , ** operations : Union [ None , str , int , float , Move , Iterable [ Move ] ] ) -> str : if en_passant == "fen" : ep_square = self . ep_square elif en_passant == "xfen" : ep_square = self . ep_square if sel... | Gets an EPD representation of the current position . |
30,886 | def lan ( self , move : Move ) -> str : return self . _algebraic ( move , long = True ) | Gets the long algebraic notation of the given move in the context of the current position . |
30,887 | def parse_san ( self , san : str ) -> Move : try : if san in [ "O-O" , "O-O+" , "O-O#" ] : return next ( move for move in self . generate_castling_moves ( ) if self . is_kingside_castling ( move ) ) elif san in [ "O-O-O" , "O-O-O+" , "O-O-O#" ] : return next ( move for move in self . generate_castling_moves ( ) if self... | Uses the current position as the context to parse a move in standard algebraic notation and returns the corresponding move object . |
30,888 | def push_san ( self , san : str ) -> Move : move = self . parse_san ( san ) self . push ( move ) return move | Parses a move in standard algebraic notation makes the move and puts it on the the move stack . |
30,889 | def uci ( self , move : Move , * , chess960 : Optional [ bool ] = None ) -> str : if chess960 is None : chess960 = self . chess960 move = self . _to_chess960 ( move ) move = self . _from_chess960 ( chess960 , move . from_square , move . to_square , move . promotion , move . drop ) return move . uci ( ) | Gets the UCI notation of the move . |
30,890 | def parse_uci ( self , uci : str ) -> Move : move = Move . from_uci ( uci ) if not move : return move move = self . _to_chess960 ( move ) move = self . _from_chess960 ( self . chess960 , move . from_square , move . to_square , move . promotion , move . drop ) if not self . is_legal ( move ) : raise ValueError ( "illega... | Parses the given move in UCI notation . |
30,891 | def push_uci ( self , uci : str ) -> Move : move = self . parse_uci ( uci ) self . push ( move ) return move | Parses a move in UCI notation and puts it on the move stack . |
30,892 | def is_en_passant ( self , move : Move ) -> bool : return ( self . ep_square == move . to_square and bool ( self . pawns & BB_SQUARES [ move . from_square ] ) and abs ( move . to_square - move . from_square ) in [ 7 , 9 ] and not self . occupied & BB_SQUARES [ move . to_square ] ) | Checks if the given pseudo - legal move is an en passant capture . |
30,893 | def is_capture ( self , move : Move ) -> bool : return bool ( BB_SQUARES [ move . to_square ] & self . occupied_co [ not self . turn ] ) or self . is_en_passant ( move ) | Checks if the given pseudo - legal move is a capture . |
30,894 | def is_zeroing ( self , move : Move ) -> bool : return bool ( BB_SQUARES [ move . from_square ] & self . pawns or BB_SQUARES [ move . to_square ] & self . occupied_co [ not self . turn ] ) | Checks if the given pseudo - legal move is a capture or pawn move . |
30,895 | def is_irreversible ( self , move : Move ) -> bool : backrank = BB_RANK_1 if self . turn == WHITE else BB_RANK_8 cr = self . clean_castling_rights ( ) & backrank return bool ( self . is_zeroing ( move ) or cr and BB_SQUARES [ move . from_square ] & self . kings & ~ self . promoted or cr & BB_SQUARES [ move . from_squar... | Checks if the given pseudo - legal move is irreversible . |
30,896 | def is_castling ( self , move : Move ) -> bool : if self . kings & BB_SQUARES [ move . from_square ] : diff = square_file ( move . from_square ) - square_file ( move . to_square ) return abs ( diff ) > 1 or bool ( self . rooks & self . occupied_co [ self . turn ] & BB_SQUARES [ move . to_square ] ) return False | Checks if the given pseudo - legal move is a castling move . |
30,897 | def is_kingside_castling ( self , move : Move ) -> bool : return self . is_castling ( move ) and square_file ( move . to_square ) > square_file ( move . from_square ) | Checks if the given pseudo - legal move is a kingside castling move . |
30,898 | def has_castling_rights ( self , color : Color ) -> bool : backrank = BB_RANK_1 if color == WHITE else BB_RANK_8 return bool ( self . clean_castling_rights ( ) & backrank ) | Checks if the given side has castling rights . |
30,899 | def has_chess960_castling_rights ( self ) -> bool : chess960 = self . chess960 self . chess960 = True castling_rights = self . clean_castling_rights ( ) self . chess960 = chess960 if castling_rights & ~ BB_CORNERS : return True if castling_rights & BB_RANK_1 and not self . occupied_co [ WHITE ] & self . kings & BB_E1 :... | Checks if there are castling rights that are only possible in Chess960 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.