repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
niklasf/python-chess | chess/pgn.py | GameNode.end | def end(self) -> "GameNode":
"""Follows the main variation to the end and returns the last node."""
node = self
while node.variations:
node = node.variations[0]
return node | python | def end(self) -> "GameNode":
"""Follows the main variation to the end and returns the last node."""
node = self
while node.variations:
node = node.variations[0]
return node | [
"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. | [
"Follows",
"the",
"main",
"variation",
"to",
"the",
"end",
"and",
"returns",
"the",
"last",
"node",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L186-L193 | train |
niklasf/python-chess | chess/pgn.py | GameNode.is_mainline | def is_mainline(self) -> bool:
"""Checks if the node is in the mainline of the game."""
node = self
while node.parent:
parent = node.parent
if not parent.variations or parent.variations[0] != node:
return False
node = parent
return ... | python | def is_mainline(self) -> bool:
"""Checks if the node is in the mainline of the game."""
node = self
while node.parent:
parent = node.parent
if not parent.variations or parent.variations[0] != node:
return False
node = parent
return ... | [
"def",
"is_mainline",
"(",
"self",
")",
"->",
"bool",
":",
"node",
"=",
"self",
"while",
"node",
".",
"parent",
":",
"parent",
"=",
"node",
".",
"parent",
"if",
"not",
"parent",
".",
"variations",
"or",
"parent",
".",
"variations",
"[",
"0",
"]",
"!=... | Checks if the node is in the mainline of the game. | [
"Checks",
"if",
"the",
"node",
"is",
"in",
"the",
"mainline",
"of",
"the",
"game",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L213-L225 | train |
niklasf/python-chess | chess/pgn.py | GameNode.is_main_variation | def is_main_variation(self) -> bool:
"""
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.
"""
if not self.parent:
return True
return not self.parent.variations or self.parent.variati... | python | def is_main_variation(self) -> bool:
"""
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.
"""
if not self.parent:
return True
return not self.parent.variations or self.parent.variati... | [
"def",
"is_main_variation",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"not",
"self",
".",
"parent",
":",
"return",
"True",
"return",
"not",
"self",
".",
"parent",
".",
"variations",
"or",
"self",
".",
"parent",
".",
"variations",
"[",
"0",
"]",
"==",
... | 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. | [
"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",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L227-L235 | train |
niklasf/python-chess | chess/pgn.py | GameNode.promote | def promote(self, move: chess.Move) -> None:
"""Moves a variation one up in the list of variations."""
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] | python | def promote(self, move: chess.Move) -> None:
"""Moves a variation one up in the list of variations."""
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] | [
"def",
"promote",
"(",
"self",
",",
"move",
":",
"chess",
".",
"Move",
")",
"->",
"None",
":",
"variation",
"=",
"self",
"[",
"move",
"]",
"i",
"=",
"self",
".",
"variations",
".",
"index",
"(",
"variation",
")",
"if",
"i",
">",
"0",
":",
"self",... | Moves a variation one up in the list of variations. | [
"Moves",
"a",
"variation",
"one",
"up",
"in",
"the",
"list",
"of",
"variations",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L263-L268 | train |
niklasf/python-chess | chess/pgn.py | GameNode.demote | def demote(self, move: chess.Move) -> None:
"""Moves a variation one down in the list of variations."""
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.variation... | python | def demote(self, move: chess.Move) -> None:
"""Moves a variation one down in the list of variations."""
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.variation... | [
"def",
"demote",
"(",
"self",
",",
"move",
":",
"chess",
".",
"Move",
")",
"->",
"None",
":",
"variation",
"=",
"self",
"[",
"move",
"]",
"i",
"=",
"self",
".",
"variations",
".",
"index",
"(",
"variation",
")",
"if",
"i",
"<",
"len",
"(",
"self"... | Moves a variation one down in the list of variations. | [
"Moves",
"a",
"variation",
"one",
"down",
"in",
"the",
"list",
"of",
"variations",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L270-L275 | train |
niklasf/python-chess | chess/pgn.py | GameNode.remove_variation | def remove_variation(self, move: chess.Move) -> None:
"""Removes a variation."""
self.variations.remove(self.variation(move)) | python | def remove_variation(self, move: chess.Move) -> None:
"""Removes a variation."""
self.variations.remove(self.variation(move)) | [
"def",
"remove_variation",
"(",
"self",
",",
"move",
":",
"chess",
".",
"Move",
")",
"->",
"None",
":",
"self",
".",
"variations",
".",
"remove",
"(",
"self",
".",
"variation",
"(",
"move",
")",
")"
] | Removes a variation. | [
"Removes",
"a",
"variation",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L277-L279 | train |
niklasf/python-chess | chess/pgn.py | GameNode.add_variation | def add_variation(self, move: chess.Move, *, comment: str = "", starting_comment: str = "", nags: Iterable[int] = ()) -> "GameNode":
"""Creates a child node with the given attributes."""
node = type(self).dangling_node()
node.move = move
node.nags = set(nags)
node.comment = comme... | python | def add_variation(self, move: chess.Move, *, comment: str = "", starting_comment: str = "", nags: Iterable[int] = ()) -> "GameNode":
"""Creates a child node with the given attributes."""
node = type(self).dangling_node()
node.move = move
node.nags = set(nags)
node.comment = comme... | [
"def",
"add_variation",
"(",
"self",
",",
"move",
":",
"chess",
".",
"Move",
",",
"*",
",",
"comment",
":",
"str",
"=",
"\"\"",
",",
"starting_comment",
":",
"str",
"=",
"\"\"",
",",
"nags",
":",
"Iterable",
"[",
"int",
"]",
"=",
"(",
")",
")",
"... | Creates a child node with the given attributes. | [
"Creates",
"a",
"child",
"node",
"with",
"the",
"given",
"attributes",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L281-L291 | train |
niklasf/python-chess | chess/pgn.py | GameNode.add_main_variation | def add_main_variation(self, move: chess.Move, *, comment: str = "") -> "GameNode":
"""
Creates a child node with the given attributes and promotes it to the
main variation.
"""
node = self.add_variation(move, comment=comment)
self.variations.remove(node)
self.var... | python | def add_main_variation(self, move: chess.Move, *, comment: str = "") -> "GameNode":
"""
Creates a child node with the given attributes and promotes it to the
main variation.
"""
node = self.add_variation(move, comment=comment)
self.variations.remove(node)
self.var... | [
"def",
"add_main_variation",
"(",
"self",
",",
"move",
":",
"chess",
".",
"Move",
",",
"*",
",",
"comment",
":",
"str",
"=",
"\"\"",
")",
"->",
"\"GameNode\"",
":",
"node",
"=",
"self",
".",
"add_variation",
"(",
"move",
",",
"comment",
"=",
"comment",... | Creates a child node with the given attributes and promotes it to the
main variation. | [
"Creates",
"a",
"child",
"node",
"with",
"the",
"given",
"attributes",
"and",
"promotes",
"it",
"to",
"the",
"main",
"variation",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L293-L301 | train |
niklasf/python-chess | chess/pgn.py | Game.board | def board(self, *, _cache: bool = False) -> chess.Board:
"""
Gets the starting position of the game.
Unless the ``FEN`` header tag is set, this is the default starting
position (for the ``Variant``).
"""
return self.headers.board() | python | def board(self, *, _cache: bool = False) -> chess.Board:
"""
Gets the starting position of the game.
Unless the ``FEN`` header tag is set, this is the default starting
position (for the ``Variant``).
"""
return self.headers.board() | [
"def",
"board",
"(",
"self",
",",
"*",
",",
"_cache",
":",
"bool",
"=",
"False",
")",
"->",
"chess",
".",
"Board",
":",
"return",
"self",
".",
"headers",
".",
"board",
"(",
")"
] | Gets the starting position of the game.
Unless the ``FEN`` header tag is set, this is the default starting
position (for the ``Variant``). | [
"Gets",
"the",
"starting",
"position",
"of",
"the",
"game",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L432-L439 | train |
niklasf/python-chess | chess/pgn.py | BaseVisitor.parse_san | def parse_san(self, board: chess.Board, san: str) -> chess.Move:
"""
When the visitor is used by a parser, this is called to parse a move
in standard algebraic notation.
You can override the default implementation to work around specific
quirks of your input format.
"""
... | python | def parse_san(self, board: chess.Board, san: str) -> chess.Move:
"""
When the visitor is used by a parser, this is called to parse a move
in standard algebraic notation.
You can override the default implementation to work around specific
quirks of your input format.
"""
... | [
"def",
"parse_san",
"(",
"self",
",",
"board",
":",
"chess",
".",
"Board",
",",
"san",
":",
"str",
")",
"->",
"chess",
".",
"Move",
":",
"# Replace zeros with correct castling notation.",
"if",
"san",
"==",
"\"0-0\"",
":",
"san",
"=",
"\"O-O\"",
"elif",
"s... | When the visitor is used by a parser, this is called to parse a move
in standard algebraic notation.
You can override the default implementation to work around specific
quirks of your input format. | [
"When",
"the",
"visitor",
"is",
"used",
"by",
"a",
"parser",
"this",
"is",
"called",
"to",
"parse",
"a",
"move",
"in",
"standard",
"algebraic",
"notation",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/pgn.py#L710-L724 | train |
niklasf/python-chess | setup.py | read_description | def read_description():
"""
Reads the description from README.rst and substitutes mentions of the
latest version with a concrete version number.
"""
with open(os.path.join(os.path.dirname(__file__), "README.rst"), encoding="utf-8") as f:
description = f.read()
# Link to the documentatio... | python | def read_description():
"""
Reads the description from README.rst and substitutes mentions of the
latest version with a concrete version number.
"""
with open(os.path.join(os.path.dirname(__file__), "README.rst"), encoding="utf-8") as f:
description = f.read()
# Link to the documentatio... | [
"def",
"read_description",
"(",
")",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"\"README.rst\"",
")",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"f",
":",
"descript... | Reads the description from README.rst and substitutes mentions of the
latest version with a concrete version number. | [
"Reads",
"the",
"description",
"from",
"README",
".",
"rst",
"and",
"substitutes",
"mentions",
"of",
"the",
"latest",
"version",
"with",
"a",
"concrete",
"version",
"number",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/setup.py#L40-L71 | train |
niklasf/python-chess | chess/engine.py | popen_uci | async def popen_uci(command: Union[str, List[str]], *, setpgrp: bool = False, loop=None, **popen_args: Any) -> Tuple[asyncio.SubprocessTransport, UciProtocol]:
"""
Spawns and initializes an UCI engine.
:param command: Path of the engine executable, or a list including the
path and arguments.
:p... | python | async def popen_uci(command: Union[str, List[str]], *, setpgrp: bool = False, loop=None, **popen_args: Any) -> Tuple[asyncio.SubprocessTransport, UciProtocol]:
"""
Spawns and initializes an UCI engine.
:param command: Path of the engine executable, or a list including the
path and arguments.
:p... | [
"async",
"def",
"popen_uci",
"(",
"command",
":",
"Union",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
",",
"*",
",",
"setpgrp",
":",
"bool",
"=",
"False",
",",
"loop",
"=",
"None",
",",
"*",
"*",
"popen_args",
":",
"Any",
")",
"->",
"Tuple",
... | Spawns and initializes an UCI engine.
:param command: Path of the engine executable, or a list including the
path and arguments.
:param setpgrp: Open the engine process in a new process group. This will
stop signals (such as keyboard interrupts) from propagating from the
parent process.... | [
"Spawns",
"and",
"initializes",
"an",
"UCI",
"engine",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L2158-L2180 | train |
niklasf/python-chess | chess/engine.py | popen_xboard | async def popen_xboard(command: Union[str, List[str]], *, setpgrp: bool = False, **popen_args: Any) -> Tuple[asyncio.SubprocessTransport, XBoardProtocol]:
"""
Spawns and initializes an XBoard engine.
:param command: Path of the engine executable, or a list including the
path and arguments.
:par... | python | async def popen_xboard(command: Union[str, List[str]], *, setpgrp: bool = False, **popen_args: Any) -> Tuple[asyncio.SubprocessTransport, XBoardProtocol]:
"""
Spawns and initializes an XBoard engine.
:param command: Path of the engine executable, or a list including the
path and arguments.
:par... | [
"async",
"def",
"popen_xboard",
"(",
"command",
":",
"Union",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
",",
"*",
",",
"setpgrp",
":",
"bool",
"=",
"False",
",",
"*",
"*",
"popen_args",
":",
"Any",
")",
"->",
"Tuple",
"[",
"asyncio",
".",
"S... | Spawns and initializes an XBoard engine.
:param command: Path of the engine executable, or a list including the
path and arguments.
:param setpgrp: Open the engine process in a new process group. This will
stop signals (such as keyboard interrupts) from propagating from the
parent proce... | [
"Spawns",
"and",
"initializes",
"an",
"XBoard",
"engine",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L2183-L2205 | train |
niklasf/python-chess | chess/engine.py | UciProtocol.debug | def debug(self, on: bool = True) -> None:
"""
Switches debug mode of the engine on or off. This does not interrupt
other ongoing operations.
"""
if on:
self.send_line("debug on")
else:
self.send_line("debug off") | python | def debug(self, on: bool = True) -> None:
"""
Switches debug mode of the engine on or off. This does not interrupt
other ongoing operations.
"""
if on:
self.send_line("debug on")
else:
self.send_line("debug off") | [
"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. | [
"Switches",
"debug",
"mode",
"of",
"the",
"engine",
"on",
"or",
"off",
".",
"This",
"does",
"not",
"interrupt",
"other",
"ongoing",
"operations",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L1024-L1032 | train |
niklasf/python-chess | chess/engine.py | AnalysisResult.stop | def stop(self) -> None:
"""Stops the analysis as soon as possible."""
if self._stop and not self._posted_kork:
self._stop()
self._stop = None | python | def stop(self) -> None:
"""Stops the analysis as soon as possible."""
if self._stop and not self._posted_kork:
self._stop()
self._stop = None | [
"def",
"stop",
"(",
"self",
")",
"->",
"None",
":",
"if",
"self",
".",
"_stop",
"and",
"not",
"self",
".",
"_posted_kork",
":",
"self",
".",
"_stop",
"(",
")",
"self",
".",
"_stop",
"=",
"None"
] | Stops the analysis as soon as possible. | [
"Stops",
"the",
"analysis",
"as",
"soon",
"as",
"possible",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L2090-L2094 | train |
niklasf/python-chess | chess/engine.py | AnalysisResult.get | async def get(self) -> InfoDict:
"""
Waits for the next dictionary of information from the engine and
returns it.
It might be more convenient to use ``async for info in analysis: ...``.
:raises: :exc:`chess.engine.AnalysisComplete` if the analysis is
complete (or ha... | python | async def get(self) -> InfoDict:
"""
Waits for the next dictionary of information from the engine and
returns it.
It might be more convenient to use ``async for info in analysis: ...``.
:raises: :exc:`chess.engine.AnalysisComplete` if the analysis is
complete (or ha... | [
"async",
"def",
"get",
"(",
"self",
")",
"->",
"InfoDict",
":",
"if",
"self",
".",
"_seen_kork",
":",
"raise",
"AnalysisComplete",
"(",
")",
"info",
"=",
"await",
"self",
".",
"_queue",
".",
"get",
"(",
")",
"if",
"not",
"info",
":",
"# Empty dictionar... | Waits for the next dictionary of information from the engine and
returns it.
It might be more convenient to use ``async for info in analysis: ...``.
:raises: :exc:`chess.engine.AnalysisComplete` if the analysis is
complete (or has been stopped) and all information has been
... | [
"Waits",
"for",
"the",
"next",
"dictionary",
"of",
"information",
"from",
"the",
"engine",
"and",
"returns",
"it",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L2100-L2122 | train |
niklasf/python-chess | chess/engine.py | AnalysisResult.empty | def empty(self) -> bool:
"""
Checks if all information has been consumed.
If the queue is empty, but the analysis is still ongoing, then further
information can become available in the future.
If the queue is not empty, then the next call to
:func:`~chess.engine.Analysi... | python | def empty(self) -> bool:
"""
Checks if all information has been consumed.
If the queue is empty, but the analysis is still ongoing, then further
information can become available in the future.
If the queue is not empty, then the next call to
:func:`~chess.engine.Analysi... | [
"def",
"empty",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_seen_kork",
"or",
"self",
".",
"_queue",
".",
"qsize",
"(",
")",
"<=",
"self",
".",
"_posted_kork"
] | Checks if all information has been consumed.
If the queue is empty, but the analysis is still ongoing, then further
information can become available in the future.
If the queue is not empty, then the next call to
:func:`~chess.engine.AnalysisResult.get()` will return instantly. | [
"Checks",
"if",
"all",
"information",
"has",
"been",
"consumed",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L2124-L2134 | train |
niklasf/python-chess | chess/engine.py | SimpleEngine.close | def close(self) -> None:
"""
Closes the transport and the background event loop as soon as possible.
"""
def _shutdown() -> None:
self.transport.close()
self.shutdown_event.set()
with self._shutdown_lock:
if not self._shutdown:
... | python | def close(self) -> None:
"""
Closes the transport and the background event loop as soon as possible.
"""
def _shutdown() -> None:
self.transport.close()
self.shutdown_event.set()
with self._shutdown_lock:
if not self._shutdown:
... | [
"def",
"close",
"(",
"self",
")",
"->",
"None",
":",
"def",
"_shutdown",
"(",
")",
"->",
"None",
":",
"self",
".",
"transport",
".",
"close",
"(",
")",
"self",
".",
"shutdown_event",
".",
"set",
"(",
")",
"with",
"self",
".",
"_shutdown_lock",
":",
... | Closes the transport and the background event loop as soon as possible. | [
"Closes",
"the",
"transport",
"and",
"the",
"background",
"event",
"loop",
"as",
"soon",
"as",
"possible",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/engine.py#L2314-L2325 | train |
niklasf/python-chess | chess/gaviota.py | open_tablebase_native | def open_tablebase_native(directory: PathLike, *, libgtb: Any = None, LibraryLoader: Any = ctypes.cdll) -> NativeTablebase:
"""
Opens a collection of tables for probing using libgtb.
In most cases :func:`~chess.gaviota.open_tablebase()` should be used.
Use this function only if you do not want to downg... | python | def open_tablebase_native(directory: PathLike, *, libgtb: Any = None, LibraryLoader: Any = ctypes.cdll) -> NativeTablebase:
"""
Opens a collection of tables for probing using libgtb.
In most cases :func:`~chess.gaviota.open_tablebase()` should be used.
Use this function only if you do not want to downg... | [
"def",
"open_tablebase_native",
"(",
"directory",
":",
"PathLike",
",",
"*",
",",
"libgtb",
":",
"Any",
"=",
"None",
",",
"LibraryLoader",
":",
"Any",
"=",
"ctypes",
".",
"cdll",
")",
"->",
"NativeTablebase",
":",
"libgtb",
"=",
"libgtb",
"or",
"ctypes",
... | Opens a collection of tables for probing using libgtb.
In most cases :func:`~chess.gaviota.open_tablebase()` should be used.
Use this function only if you do not want to downgrade to pure Python
tablebase probing.
:raises: :exc:`RuntimeError` or :exc:`OSError` when libgtb can not be used. | [
"Opens",
"a",
"collection",
"of",
"tables",
"for",
"probing",
"using",
"libgtb",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/gaviota.py#L2083-L2096 | train |
niklasf/python-chess | chess/gaviota.py | open_tablebase | def open_tablebase(directory: PathLike, *, libgtb: Any = None, LibraryLoader: Any = ctypes.cdll) -> Union[NativeTablebase, PythonTablebase]:
"""
Opens a collection of tables for probing.
First native access via the shared library libgtb is tried. You can
optionally provide a specific library name or a ... | python | def open_tablebase(directory: PathLike, *, libgtb: Any = None, LibraryLoader: Any = ctypes.cdll) -> Union[NativeTablebase, PythonTablebase]:
"""
Opens a collection of tables for probing.
First native access via the shared library libgtb is tried. You can
optionally provide a specific library name or a ... | [
"def",
"open_tablebase",
"(",
"directory",
":",
"PathLike",
",",
"*",
",",
"libgtb",
":",
"Any",
"=",
"None",
",",
"LibraryLoader",
":",
"Any",
"=",
"ctypes",
".",
"cdll",
")",
"->",
"Union",
"[",
"NativeTablebase",
",",
"PythonTablebase",
"]",
":",
"try... | Opens a collection of tables for probing.
First native access via the shared library libgtb is tried. You can
optionally provide a specific library name or a library loader.
The shared library has global state and caches, so only one instance can
be open at a time.
Second, pure Python probing code... | [
"Opens",
"a",
"collection",
"of",
"tables",
"for",
"probing",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/gaviota.py#L2099-L2118 | train |
niklasf/python-chess | chess/gaviota.py | PythonTablebase.probe_dtm | def probe_dtm(self, board: chess.Board) -> int:
"""
Probes for depth to mate information.
The absolute value is the number of half-moves until forced mate
(or ``0`` in drawn positions). The value is positive if the
side to move is winning, otherwise it is negative.
In t... | python | def probe_dtm(self, board: chess.Board) -> int:
"""
Probes for depth to mate information.
The absolute value is the number of half-moves until forced mate
(or ``0`` in drawn positions). The value is positive if the
side to move is winning, otherwise it is negative.
In t... | [
"def",
"probe_dtm",
"(",
"self",
",",
"board",
":",
"chess",
".",
"Board",
")",
"->",
"int",
":",
"# Can not probe positions with castling rights.",
"if",
"board",
".",
"castling_rights",
":",
"raise",
"KeyError",
"(",
"\"gaviota tables do not contain positions with cas... | Probes for depth to mate information.
The absolute value is the number of half-moves until forced mate
(or ``0`` in drawn positions). The value is positive if the
side to move is winning, otherwise it is negative.
In the example position white to move will get mated in 10 half-moves:
... | [
"Probes",
"for",
"depth",
"to",
"mate",
"information",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/gaviota.py#L1556-L1633 | train |
niklasf/python-chess | chess/__init__.py | Piece.symbol | def symbol(self) -> str:
"""
Gets the symbol ``P``, ``N``, ``B``, ``R``, ``Q`` or ``K`` for white
pieces or the lower-case variants for the black pieces.
"""
symbol = piece_symbol(self.piece_type)
return symbol.upper() if self.color else symbol | python | def symbol(self) -> str:
"""
Gets the symbol ``P``, ``N``, ``B``, ``R``, ``Q`` or ``K`` for white
pieces or the lower-case variants for the black pieces.
"""
symbol = piece_symbol(self.piece_type)
return symbol.upper() if self.color else symbol | [
"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. | [
"Gets",
"the",
"symbol",
"P",
"N",
"B",
"R",
"Q",
"or",
"K",
"for",
"white",
"pieces",
"or",
"the",
"lower",
"-",
"case",
"variants",
"for",
"the",
"black",
"pieces",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L394-L400 | train |
niklasf/python-chess | chess/__init__.py | Piece.unicode_symbol | def unicode_symbol(self, *, invert_color: bool = False) -> str:
"""
Gets the Unicode character for the piece.
"""
symbol = self.symbol().swapcase() if invert_color else self.symbol()
return UNICODE_PIECE_SYMBOLS[symbol] | python | def unicode_symbol(self, *, invert_color: bool = False) -> str:
"""
Gets the Unicode character for the piece.
"""
symbol = self.symbol().swapcase() if invert_color else self.symbol()
return UNICODE_PIECE_SYMBOLS[symbol] | [
"def",
"unicode_symbol",
"(",
"self",
",",
"*",
",",
"invert_color",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"symbol",
"=",
"self",
".",
"symbol",
"(",
")",
".",
"swapcase",
"(",
")",
"if",
"invert_color",
"else",
"self",
".",
"symbol",
"("... | Gets the Unicode character for the piece. | [
"Gets",
"the",
"Unicode",
"character",
"for",
"the",
"piece",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L402-L407 | train |
niklasf/python-chess | chess/__init__.py | Move.uci | def uci(self) -> str:
"""
Gets an UCI string for the move.
For example, a move from a7 to a8 would be ``a7a8`` or ``a7a8q``
(if the latter is a promotion to a queen).
The UCI representation of a null move is ``0000``.
"""
if self.drop:
return piece_s... | python | def uci(self) -> str:
"""
Gets an UCI string for the move.
For example, a move from a7 to a8 would be ``a7a8`` or ``a7a8q``
(if the latter is a promotion to a queen).
The UCI representation of a null move is ``0000``.
"""
if self.drop:
return piece_s... | [
"def",
"uci",
"(",
"self",
")",
"->",
"str",
":",
"if",
"self",
".",
"drop",
":",
"return",
"piece_symbol",
"(",
"self",
".",
"drop",
")",
".",
"upper",
"(",
")",
"+",
"\"@\"",
"+",
"SQUARE_NAMES",
"[",
"self",
".",
"to_square",
"]",
"elif",
"self"... | Gets an UCI string for the move.
For example, a move from a7 to a8 would be ``a7a8`` or ``a7a8q``
(if the latter is a promotion to a queen).
The UCI representation of a null move is ``0000``. | [
"Gets",
"an",
"UCI",
"string",
"for",
"the",
"move",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L452-L468 | train |
niklasf/python-chess | chess/__init__.py | Move.from_uci | def from_uci(cls, uci: str) -> "Move":
"""
Parses an UCI string.
:raises: :exc:`ValueError` if the UCI string is invalid.
"""
if uci == "0000":
return cls.null()
elif len(uci) == 4 and "@" == uci[1]:
drop = PIECE_SYMBOLS.index(uci[0].lower())
... | python | def from_uci(cls, uci: str) -> "Move":
"""
Parses an UCI string.
:raises: :exc:`ValueError` if the UCI string is invalid.
"""
if uci == "0000":
return cls.null()
elif len(uci) == 4 and "@" == uci[1]:
drop = PIECE_SYMBOLS.index(uci[0].lower())
... | [
"def",
"from_uci",
"(",
"cls",
",",
"uci",
":",
"str",
")",
"->",
"\"Move\"",
":",
"if",
"uci",
"==",
"\"0000\"",
":",
"return",
"cls",
".",
"null",
"(",
")",
"elif",
"len",
"(",
"uci",
")",
"==",
"4",
"and",
"\"@\"",
"==",
"uci",
"[",
"1",
"]"... | Parses an UCI string.
:raises: :exc:`ValueError` if the UCI string is invalid. | [
"Parses",
"an",
"UCI",
"string",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L504-L522 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.pieces | def pieces(self, piece_type: PieceType, color: Color) -> "SquareSet":
"""
Gets pieces of the given type and color.
Returns a :class:`set of squares <chess.SquareSet>`.
"""
return SquareSet(self.pieces_mask(piece_type, color)) | python | def pieces(self, piece_type: PieceType, color: Color) -> "SquareSet":
"""
Gets pieces of the given type and color.
Returns a :class:`set of squares <chess.SquareSet>`.
"""
return SquareSet(self.pieces_mask(piece_type, color)) | [
"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.
Returns a :class:`set of squares <chess.SquareSet>`. | [
"Gets",
"pieces",
"of",
"the",
"given",
"type",
"and",
"color",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L614-L620 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.piece_type_at | def piece_type_at(self, square: Square) -> Optional[PieceType]:
"""Gets the piece type at the given square."""
mask = BB_SQUARES[square]
if not self.occupied & mask:
return None # Early return
elif self.pawns & mask:
return PAWN
elif self.knights & mask:... | python | def piece_type_at(self, square: Square) -> Optional[PieceType]:
"""Gets the piece type at the given square."""
mask = BB_SQUARES[square]
if not self.occupied & mask:
return None # Early return
elif self.pawns & mask:
return PAWN
elif self.knights & mask:... | [
"def",
"piece_type_at",
"(",
"self",
",",
"square",
":",
"Square",
")",
"->",
"Optional",
"[",
"PieceType",
"]",
":",
"mask",
"=",
"BB_SQUARES",
"[",
"square",
"]",
"if",
"not",
"self",
".",
"occupied",
"&",
"mask",
":",
"return",
"None",
"# Early return... | Gets the piece type at the given square. | [
"Gets",
"the",
"piece",
"type",
"at",
"the",
"given",
"square",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L632-L649 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.king | def king(self, color: Color) -> Optional[Square]:
"""
Finds the king square of the given side. Returns ``None`` if there
is no king of that color.
In variants with king promotions, only non-promoted kings are
considered.
"""
king_mask = self.occupied_co[color] & ... | python | def king(self, color: Color) -> Optional[Square]:
"""
Finds the king square of the given side. Returns ``None`` if there
is no king of that color.
In variants with king promotions, only non-promoted kings are
considered.
"""
king_mask = self.occupied_co[color] & ... | [
"def",
"king",
"(",
"self",
",",
"color",
":",
"Color",
")",
"->",
"Optional",
"[",
"Square",
"]",
":",
"king_mask",
"=",
"self",
".",
"occupied_co",
"[",
"color",
"]",
"&",
"self",
".",
"kings",
"&",
"~",
"self",
".",
"promoted",
"return",
"msb",
... | Finds the king square of the given side. Returns ``None`` if there
is no king of that color.
In variants with king promotions, only non-promoted kings are
considered. | [
"Finds",
"the",
"king",
"square",
"of",
"the",
"given",
"side",
".",
"Returns",
"None",
"if",
"there",
"is",
"no",
"king",
"of",
"that",
"color",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L651-L660 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.is_attacked_by | def is_attacked_by(self, color: Color, square: Square) -> bool:
"""
Checks if the given side attacks the given square.
Pinned pieces still count as attackers. Pawns that can be captured
en passant are **not** considered attacked.
"""
return bool(self.attackers_mask(color... | python | def is_attacked_by(self, color: Color, square: Square) -> bool:
"""
Checks if the given side attacks the given square.
Pinned pieces still count as attackers. Pawns that can be captured
en passant are **not** considered attacked.
"""
return bool(self.attackers_mask(color... | [
"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.
Pinned pieces still count as attackers. Pawns that can be captured
en passant are **not** considered attacked. | [
"Checks",
"if",
"the",
"given",
"side",
"attacks",
"the",
"given",
"square",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L713-L720 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.attackers | def attackers(self, color: Color, square: Square) -> "SquareSet":
"""
Gets a set of attackers of the given color for the given square.
Pinned pieces still count as attackers.
Returns a :class:`set of squares <chess.SquareSet>`.
"""
return SquareSet(self.attackers_mask(c... | python | def attackers(self, color: Color, square: Square) -> "SquareSet":
"""
Gets a set of attackers of the given color for the given square.
Pinned pieces still count as attackers.
Returns a :class:`set of squares <chess.SquareSet>`.
"""
return SquareSet(self.attackers_mask(c... | [
"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.
Pinned pieces still count as attackers.
Returns a :class:`set of squares <chess.SquareSet>`. | [
"Gets",
"a",
"set",
"of",
"attackers",
"of",
"the",
"given",
"color",
"for",
"the",
"given",
"square",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L722-L730 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.is_pinned | def is_pinned(self, color: Color, square: Square) -> bool:
"""
Detects if the given square is pinned to the king of the given color.
"""
return self.pin_mask(color, square) != BB_ALL | python | def is_pinned(self, color: Color, square: Square) -> bool:
"""
Detects if the given square is pinned to the king of the given color.
"""
return self.pin_mask(color, square) != BB_ALL | [
"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. | [
"Detects",
"if",
"the",
"given",
"square",
"is",
"pinned",
"to",
"the",
"king",
"of",
"the",
"given",
"color",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L782-L786 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.set_piece_at | def set_piece_at(self, square: Square, piece: Optional[Piece], promoted: bool = False) -> None:
"""
Sets a piece at the given square.
An existing piece is replaced. Setting *piece* to ``None`` is
equivalent to :func:`~chess.Board.remove_piece_at()`.
"""
if piece is None:... | python | def set_piece_at(self, square: Square, piece: Optional[Piece], promoted: bool = False) -> None:
"""
Sets a piece at the given square.
An existing piece is replaced. Setting *piece* to ``None`` is
equivalent to :func:`~chess.Board.remove_piece_at()`.
"""
if piece is None:... | [
"def",
"set_piece_at",
"(",
"self",
",",
"square",
":",
"Square",
",",
"piece",
":",
"Optional",
"[",
"Piece",
"]",
",",
"promoted",
":",
"bool",
"=",
"False",
")",
"->",
"None",
":",
"if",
"piece",
"is",
"None",
":",
"self",
".",
"_remove_piece_at",
... | Sets a piece at the given square.
An existing piece is replaced. Setting *piece* to ``None`` is
equivalent to :func:`~chess.Board.remove_piece_at()`. | [
"Sets",
"a",
"piece",
"at",
"the",
"given",
"square",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L850-L860 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.board_fen | def board_fen(self, *, promoted: Optional[bool] = False) -> str:
"""
Gets the board FEN.
"""
builder = []
empty = 0
for square in SQUARES_180:
piece = self.piece_at(square)
if not piece:
empty += 1
else:
... | python | def board_fen(self, *, promoted: Optional[bool] = False) -> str:
"""
Gets the board FEN.
"""
builder = []
empty = 0
for square in SQUARES_180:
piece = self.piece_at(square)
if not piece:
empty += 1
else:
... | [
"def",
"board_fen",
"(",
"self",
",",
"*",
",",
"promoted",
":",
"Optional",
"[",
"bool",
"]",
"=",
"False",
")",
"->",
"str",
":",
"builder",
"=",
"[",
"]",
"empty",
"=",
"0",
"for",
"square",
"in",
"SQUARES_180",
":",
"piece",
"=",
"self",
".",
... | Gets the board FEN. | [
"Gets",
"the",
"board",
"FEN",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L862-L890 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.chess960_pos | def chess960_pos(self) -> Optional[int]:
"""
Gets the Chess960 starting position index between 0 and 959
or ``None``.
"""
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 N... | python | def chess960_pos(self) -> Optional[int]:
"""
Gets the Chess960 starting position index between 0 and 959
or ``None``.
"""
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 N... | [
"def",
"chess960_pos",
"(",
"self",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"if",
"self",
".",
"occupied_co",
"[",
"WHITE",
"]",
"!=",
"BB_RANK_1",
"|",
"BB_RANK_2",
":",
"return",
"None",
"if",
"self",
".",
"occupied_co",
"[",
"BLACK",
"]",
"!=",... | Gets the Chess960 starting position index between 0 and 959
or ``None``. | [
"Gets",
"the",
"Chess960",
"starting",
"position",
"index",
"between",
"0",
"and",
"959",
"or",
"None",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1043-L1119 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.mirror | def mirror(self: BaseBoardT) -> BaseBoardT:
"""
Returns a mirrored copy of the board.
The board is mirrored vertically and piece colors are swapped, so that
the position is equivalent modulo color.
"""
board = self.transform(flip_vertical)
board.occupied_co[WHITE... | python | def mirror(self: BaseBoardT) -> BaseBoardT:
"""
Returns a mirrored copy of the board.
The board is mirrored vertically and piece colors are swapped, so that
the position is equivalent modulo color.
"""
board = self.transform(flip_vertical)
board.occupied_co[WHITE... | [
"def",
"mirror",
"(",
"self",
":",
"BaseBoardT",
")",
"->",
"BaseBoardT",
":",
"board",
"=",
"self",
".",
"transform",
"(",
"flip_vertical",
")",
"board",
".",
"occupied_co",
"[",
"WHITE",
"]",
",",
"board",
".",
"occupied_co",
"[",
"BLACK",
"]",
"=",
... | Returns a mirrored copy of the board.
The board is mirrored vertically and piece colors are swapped, so that
the position is equivalent modulo color. | [
"Returns",
"a",
"mirrored",
"copy",
"of",
"the",
"board",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1226-L1235 | train |
niklasf/python-chess | chess/__init__.py | BaseBoard.from_chess960_pos | def from_chess960_pos(cls: Type[BaseBoardT], sharnagl: int) -> BaseBoardT:
"""
Creates a new board, initialized with a Chess960 starting position.
>>> import chess
>>> import random
>>>
>>> board = chess.Board.from_chess960_pos(random.randint(0, 959))
"""
... | python | def from_chess960_pos(cls: Type[BaseBoardT], sharnagl: int) -> BaseBoardT:
"""
Creates a new board, initialized with a Chess960 starting position.
>>> import chess
>>> import random
>>>
>>> board = chess.Board.from_chess960_pos(random.randint(0, 959))
"""
... | [
"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.
>>> import chess
>>> import random
>>>
>>> board = chess.Board.from_chess960_pos(random.randint(0, 959)) | [
"Creates",
"a",
"new",
"board",
"initialized",
"with",
"a",
"Chess960",
"starting",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1272-L1283 | train |
niklasf/python-chess | chess/__init__.py | Board.reset | def reset(self) -> None:
"""Restores the starting position."""
self.turn = WHITE
self.castling_rights = BB_CORNERS
self.ep_square = None
self.halfmove_clock = 0
self.fullmove_number = 1
self.reset_board() | python | def reset(self) -> None:
"""Restores the starting position."""
self.turn = WHITE
self.castling_rights = BB_CORNERS
self.ep_square = None
self.halfmove_clock = 0
self.fullmove_number = 1
self.reset_board() | [
"def",
"reset",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"turn",
"=",
"WHITE",
"self",
".",
"castling_rights",
"=",
"BB_CORNERS",
"self",
".",
"ep_square",
"=",
"None",
"self",
".",
"halfmove_clock",
"=",
"0",
"self",
".",
"fullmove_number",
"="... | Restores the starting position. | [
"Restores",
"the",
"starting",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1394-L1402 | train |
niklasf/python-chess | chess/__init__.py | Board.clear | def clear(self) -> None:
"""
Clears the board.
Resets move stack and move counters. The side to move is white. There
are no rooks or kings, so castling rights are removed.
In order to be in a valid :func:`~chess.Board.status()` at least kings
need to be put on the board... | python | def clear(self) -> None:
"""
Clears the board.
Resets move stack and move counters. The side to move is white. There
are no rooks or kings, so castling rights are removed.
In order to be in a valid :func:`~chess.Board.status()` at least kings
need to be put on the board... | [
"def",
"clear",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"turn",
"=",
"WHITE",
"self",
".",
"castling_rights",
"=",
"BB_EMPTY",
"self",
".",
"ep_square",
"=",
"None",
"self",
".",
"halfmove_clock",
"=",
"0",
"self",
".",
"fullmove_number",
"=",
... | Clears the board.
Resets move stack and move counters. The side to move is white. There
are no rooks or kings, so castling rights are removed.
In order to be in a valid :func:`~chess.Board.status()` at least kings
need to be put on the board. | [
"Clears",
"the",
"board",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1408-L1424 | train |
niklasf/python-chess | chess/__init__.py | Board.root | def root(self: BoardT) -> BoardT:
"""Returns a copy of the root position."""
if self._stack:
board = type(self)(None, chess960=self.chess960)
self._stack[0].restore(board)
return board
else:
return self.copy(stack=False) | python | def root(self: BoardT) -> BoardT:
"""Returns a copy of the root position."""
if self._stack:
board = type(self)(None, chess960=self.chess960)
self._stack[0].restore(board)
return board
else:
return self.copy(stack=False) | [
"def",
"root",
"(",
"self",
":",
"BoardT",
")",
"->",
"BoardT",
":",
"if",
"self",
".",
"_stack",
":",
"board",
"=",
"type",
"(",
"self",
")",
"(",
"None",
",",
"chess960",
"=",
"self",
".",
"chess960",
")",
"self",
".",
"_stack",
"[",
"0",
"]",
... | Returns a copy of the root position. | [
"Returns",
"a",
"copy",
"of",
"the",
"root",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1435-L1442 | train |
niklasf/python-chess | chess/__init__.py | Board.is_check | def is_check(self) -> bool:
"""Returns if the current side to move is in check."""
king = self.king(self.turn)
return king is not None and self.is_attacked_by(not self.turn, king) | python | def is_check(self) -> bool:
"""Returns if the current side to move is in check."""
king = self.king(self.turn)
return king is not None and self.is_attacked_by(not self.turn, king) | [
"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. | [
"Returns",
"if",
"the",
"current",
"side",
"to",
"move",
"is",
"in",
"check",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1540-L1543 | train |
niklasf/python-chess | chess/__init__.py | Board.is_into_check | def is_into_check(self, move: Move) -> bool:
"""
Checks if the given move would leave the king in check or put it into
check. The move must be at least pseudo legal.
"""
king = self.king(self.turn)
if king is None:
return False
checkers = self.attacke... | python | def is_into_check(self, move: Move) -> bool:
"""
Checks if the given move would leave the king in check or put it into
check. The move must be at least pseudo legal.
"""
king = self.king(self.turn)
if king is None:
return False
checkers = self.attacke... | [
"def",
"is_into_check",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"king",
"=",
"self",
".",
"king",
"(",
"self",
".",
"turn",
")",
"if",
"king",
"is",
"None",
":",
"return",
"False",
"checkers",
"=",
"self",
".",
"attackers_mask"... | Checks if the given move would leave the king in check or put it into
check. The move must be at least pseudo legal. | [
"Checks",
"if",
"the",
"given",
"move",
"would",
"leave",
"the",
"king",
"in",
"check",
"or",
"put",
"it",
"into",
"check",
".",
"The",
"move",
"must",
"be",
"at",
"least",
"pseudo",
"legal",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1545-L1560 | train |
niklasf/python-chess | chess/__init__.py | Board.was_into_check | def was_into_check(self) -> bool:
"""
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.
"""
king = self.king(not self.turn)
return king is not None and self.is_attacked_by(self.turn, king) | python | def was_into_check(self) -> bool:
"""
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.
"""
king = self.king(not self.turn)
return king is not None and self.is_attacked_by(self.turn, king) | [
"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. | [
"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",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1562-L1568 | train |
niklasf/python-chess | chess/__init__.py | Board.result | def result(self, *, claim_draw: bool = False) -> str:
"""
Gets the game result.
``1-0``, ``0-1`` or ``1/2-1/2`` if the
:func:`game is over <chess.Board.is_game_over()>`. Otherwise, the
result is undetermined: ``*``.
"""
# Chess variant support.
if self.is... | python | def result(self, *, claim_draw: bool = False) -> str:
"""
Gets the game result.
``1-0``, ``0-1`` or ``1/2-1/2`` if the
:func:`game is over <chess.Board.is_game_over()>`. Otherwise, the
result is undetermined: ``*``.
"""
# Chess variant support.
if self.is... | [
"def",
"result",
"(",
"self",
",",
"*",
",",
"claim_draw",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"# Chess variant support.",
"if",
"self",
".",
"is_variant_loss",
"(",
")",
":",
"return",
"\"0-1\"",
"if",
"self",
".",
"turn",
"==",
"WHITE",
... | Gets the game result.
``1-0``, ``0-1`` or ``1/2-1/2`` if the
:func:`game is over <chess.Board.is_game_over()>`. Otherwise, the
result is undetermined: ``*``. | [
"Gets",
"the",
"game",
"result",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1686-L1723 | train |
niklasf/python-chess | chess/__init__.py | Board.is_stalemate | def is_stalemate(self) -> bool:
"""Checks if the current position is a stalemate."""
if self.is_check():
return False
if self.is_variant_end():
return False
return not any(self.generate_legal_moves()) | python | def is_stalemate(self) -> bool:
"""Checks if the current position is a stalemate."""
if self.is_check():
return False
if self.is_variant_end():
return False
return not any(self.generate_legal_moves()) | [
"def",
"is_stalemate",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"self",
".",
"is_check",
"(",
")",
":",
"return",
"False",
"if",
"self",
".",
"is_variant_end",
"(",
")",
":",
"return",
"False",
"return",
"not",
"any",
"(",
"self",
".",
"generate_lega... | Checks if the current position is a stalemate. | [
"Checks",
"if",
"the",
"current",
"position",
"is",
"a",
"stalemate",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1732-L1740 | train |
niklasf/python-chess | chess/__init__.py | Board.can_claim_fifty_moves | def can_claim_fifty_moves(self) -> bool:
"""
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.
"""
# Fifty-move rule.
... | python | def can_claim_fifty_moves(self) -> bool:
"""
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.
"""
# Fifty-move rule.
... | [
"def",
"can_claim_fifty_moves",
"(",
"self",
")",
"->",
"bool",
":",
"# Fifty-move rule.",
"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. | [
"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",
... | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1832-L1843 | train |
niklasf/python-chess | chess/__init__.py | Board.can_claim_threefold_repetition | def can_claim_threefold_repetition(self) -> bool:
"""
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.
Note that checking this can be slow: In the worst ca... | python | def can_claim_threefold_repetition(self) -> bool:
"""
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.
Note that checking this can be slow: In the worst ca... | [
"def",
"can_claim_threefold_repetition",
"(",
"self",
")",
"->",
"bool",
":",
"transposition_key",
"=",
"self",
".",
"_transposition_key",
"(",
")",
"transpositions",
"=",
"collections",
".",
"Counter",
"(",
")",
"# type: typing.Counter[Hashable]",
"transpositions",
"... | 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.
Note that checking this can be slow: In the worst case
scenario every legal move has to be tested and the entire g... | [
"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... | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L1845-L1886 | train |
niklasf/python-chess | chess/__init__.py | Board.pop | def pop(self: BoardT) -> Move:
"""
Restores the previous position and returns the last move from the stack.
:raises: :exc:`IndexError` if the stack is empty.
"""
move = self.move_stack.pop()
self._stack.pop().restore(self)
return move | python | def pop(self: BoardT) -> Move:
"""
Restores the previous position and returns the last move from the stack.
:raises: :exc:`IndexError` if the stack is empty.
"""
move = self.move_stack.pop()
self._stack.pop().restore(self)
return move | [
"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.
:raises: :exc:`IndexError` if the stack is empty. | [
"Restores",
"the",
"previous",
"position",
"and",
"returns",
"the",
"last",
"move",
"from",
"the",
"stack",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2048-L2056 | train |
niklasf/python-chess | chess/__init__.py | Board.fen | def fen(self, *, shredder: bool = False, en_passant: str = "legal", promoted: Optional[bool] = None) -> str:
"""
Gets a FEN representation of the position.
A FEN string (e.g.,
``rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1``) consists
of the position part :func:`~che... | python | def fen(self, *, shredder: bool = False, en_passant: str = "legal", promoted: Optional[bool] = None) -> str:
"""
Gets a FEN representation of the position.
A FEN string (e.g.,
``rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1``) consists
of the position part :func:`~che... | [
"def",
"fen",
"(",
"self",
",",
"*",
",",
"shredder",
":",
"bool",
"=",
"False",
",",
"en_passant",
":",
"str",
"=",
"\"legal\"",
",",
"promoted",
":",
"Optional",
"[",
"bool",
"]",
"=",
"None",
")",
"->",
"str",
":",
"return",
"\" \"",
".",
"join"... | Gets a FEN representation of the position.
A FEN string (e.g.,
``rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1``) consists
of the position part :func:`~chess.Board.board_fen()`, the
:data:`~chess.Board.turn`, the castling part
(:data:`~chess.Board.castling_rights`),
... | [
"Gets",
"a",
"FEN",
"representation",
"of",
"the",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2118-L2148 | train |
niklasf/python-chess | chess/__init__.py | Board.set_fen | def set_fen(self, fen: str) -> None:
"""
Parses a FEN and sets the position from it.
:raises: :exc:`ValueError` if the FEN string is invalid.
"""
parts = fen.split()
# Board part.
try:
board_part = parts.pop(0)
except IndexError:
... | python | def set_fen(self, fen: str) -> None:
"""
Parses a FEN and sets the position from it.
:raises: :exc:`ValueError` if the FEN string is invalid.
"""
parts = fen.split()
# Board part.
try:
board_part = parts.pop(0)
except IndexError:
... | [
"def",
"set_fen",
"(",
"self",
",",
"fen",
":",
"str",
")",
"->",
"None",
":",
"parts",
"=",
"fen",
".",
"split",
"(",
")",
"# Board part.",
"try",
":",
"board_part",
"=",
"parts",
".",
"pop",
"(",
"0",
")",
"except",
"IndexError",
":",
"raise",
"V... | Parses a FEN and sets the position from it.
:raises: :exc:`ValueError` if the FEN string is invalid. | [
"Parses",
"a",
"FEN",
"and",
"sets",
"the",
"position",
"from",
"it",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2157-L2248 | train |
niklasf/python-chess | chess/__init__.py | Board.chess960_pos | def chess960_pos(self, *, ignore_turn: bool = False, ignore_castling: bool = False, ignore_counters: bool = True) -> Optional[int]:
"""
Gets the Chess960 starting position index between 0 and 956
or ``None`` if the current position is not a Chess960 starting
position.
By default... | python | def chess960_pos(self, *, ignore_turn: bool = False, ignore_castling: bool = False, ignore_counters: bool = True) -> Optional[int]:
"""
Gets the Chess960 starting position index between 0 and 956
or ``None`` if the current position is not a Chess960 starting
position.
By default... | [
"def",
"chess960_pos",
"(",
"self",
",",
"*",
",",
"ignore_turn",
":",
"bool",
"=",
"False",
",",
"ignore_castling",
":",
"bool",
"=",
"False",
",",
"ignore_counters",
":",
"bool",
"=",
"True",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"if",
"self",... | Gets the Chess960 starting position index between 0 and 956
or ``None`` if the current position is not a Chess960 starting
position.
By default white to move (**ignore_turn**) and full castling rights
(**ignore_castling**) are required, but move counters
(**ignore_counters**) ar... | [
"Gets",
"the",
"Chess960",
"starting",
"position",
"index",
"between",
"0",
"and",
"956",
"or",
"None",
"if",
"the",
"current",
"position",
"is",
"not",
"a",
"Chess960",
"starting",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2312-L2337 | train |
niklasf/python-chess | chess/__init__.py | Board.epd | def epd(self, *, shredder: bool = False, en_passant: str = "legal", promoted: Optional[bool] = None, **operations: Union[None, str, int, float, Move, Iterable[Move]]) -> str:
"""
Gets an EPD representation of the current position.
See :func:`~chess.Board.fen()` for FEN formatting options (*shre... | python | def epd(self, *, shredder: bool = False, en_passant: str = "legal", promoted: Optional[bool] = None, **operations: Union[None, str, int, float, Move, Iterable[Move]]) -> str:
"""
Gets an EPD representation of the current position.
See :func:`~chess.Board.fen()` for FEN formatting options (*shre... | [
"def",
"epd",
"(",
"self",
",",
"*",
",",
"shredder",
":",
"bool",
"=",
"False",
",",
"en_passant",
":",
"str",
"=",
"\"legal\"",
",",
"promoted",
":",
"Optional",
"[",
"bool",
"]",
"=",
"None",
",",
"*",
"*",
"operations",
":",
"Union",
"[",
"None... | Gets an EPD representation of the current position.
See :func:`~chess.Board.fen()` for FEN formatting options (*shredder*,
*ep_square* and *promoted*).
EPD operations can be given as keyword arguments. Supported operands
are strings, integers, floats, moves, lists of moves and ``None``... | [
"Gets",
"an",
"EPD",
"representation",
"of",
"the",
"current",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2398-L2435 | train |
niklasf/python-chess | chess/__init__.py | Board.lan | def lan(self, move: Move) -> str:
"""
Gets the long algebraic notation of the given move in the context of
the current position.
"""
return self._algebraic(move, long=True) | python | def lan(self, move: Move) -> str:
"""
Gets the long algebraic notation of the given move in the context of
the current position.
"""
return self._algebraic(move, long=True) | [
"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. | [
"Gets",
"the",
"long",
"algebraic",
"notation",
"of",
"the",
"given",
"move",
"in",
"the",
"context",
"of",
"the",
"current",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2568-L2573 | train |
niklasf/python-chess | chess/__init__.py | Board.parse_san | def parse_san(self, san: str) -> Move:
"""
Uses the current position as the context to parse a move in standard
algebraic notation and returns the corresponding move object.
The returned move is guaranteed to be either legal or a null move.
:raises: :exc:`ValueError` if the SAN... | python | def parse_san(self, san: str) -> Move:
"""
Uses the current position as the context to parse a move in standard
algebraic notation and returns the corresponding move object.
The returned move is guaranteed to be either legal or a null move.
:raises: :exc:`ValueError` if the SAN... | [
"def",
"parse_san",
"(",
"self",
",",
"san",
":",
"str",
")",
"->",
"Move",
":",
"# Castling.",
"try",
":",
"if",
"san",
"in",
"[",
"\"O-O\"",
",",
"\"O-O+\"",
",",
"\"O-O#\"",
"]",
":",
"return",
"next",
"(",
"move",
"for",
"move",
"in",
"self",
"... | Uses the current position as the context to parse a move in standard
algebraic notation and returns the corresponding move object.
The returned move is guaranteed to be either legal or a null move.
:raises: :exc:`ValueError` if the SAN is invalid or ambiguous. | [
"Uses",
"the",
"current",
"position",
"as",
"the",
"context",
"to",
"parse",
"a",
"move",
"in",
"standard",
"algebraic",
"notation",
"and",
"returns",
"the",
"corresponding",
"move",
"object",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2698-L2762 | train |
niklasf/python-chess | chess/__init__.py | Board.push_san | def push_san(self, san: str) -> Move:
"""
Parses a move in standard algebraic notation, makes the move and puts
it on the the move stack.
Returns the move.
:raises: :exc:`ValueError` if neither legal nor a null move.
"""
move = self.parse_san(san)
self.p... | python | def push_san(self, san: str) -> Move:
"""
Parses a move in standard algebraic notation, makes the move and puts
it on the the move stack.
Returns the move.
:raises: :exc:`ValueError` if neither legal nor a null move.
"""
move = self.parse_san(san)
self.p... | [
"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.
Returns the move.
:raises: :exc:`ValueError` if neither legal nor a null move. | [
"Parses",
"a",
"move",
"in",
"standard",
"algebraic",
"notation",
"makes",
"the",
"move",
"and",
"puts",
"it",
"on",
"the",
"the",
"move",
"stack",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2764-L2775 | train |
niklasf/python-chess | chess/__init__.py | Board.uci | def uci(self, move: Move, *, chess960: Optional[bool] = None) -> str:
"""
Gets the UCI notation of the move.
*chess960* defaults to the mode of the board. Pass ``True`` to force
Chess960 mode.
"""
if chess960 is None:
chess960 = self.chess960
move = ... | python | def uci(self, move: Move, *, chess960: Optional[bool] = None) -> str:
"""
Gets the UCI notation of the move.
*chess960* defaults to the mode of the board. Pass ``True`` to force
Chess960 mode.
"""
if chess960 is None:
chess960 = self.chess960
move = ... | [
"def",
"uci",
"(",
"self",
",",
"move",
":",
"Move",
",",
"*",
",",
"chess960",
":",
"Optional",
"[",
"bool",
"]",
"=",
"None",
")",
"->",
"str",
":",
"if",
"chess960",
"is",
"None",
":",
"chess960",
"=",
"self",
".",
"chess960",
"move",
"=",
"se... | Gets the UCI notation of the move.
*chess960* defaults to the mode of the board. Pass ``True`` to force
Chess960 mode. | [
"Gets",
"the",
"UCI",
"notation",
"of",
"the",
"move",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2777-L2789 | train |
niklasf/python-chess | chess/__init__.py | Board.parse_uci | def parse_uci(self, uci: str) -> Move:
"""
Parses the given move in UCI notation.
Supports both Chess960 and standard UCI notation.
The returned move is guaranteed to be either legal or a null move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
... | python | def parse_uci(self, uci: str) -> Move:
"""
Parses the given move in UCI notation.
Supports both Chess960 and standard UCI notation.
The returned move is guaranteed to be either legal or a null move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
... | [
"def",
"parse_uci",
"(",
"self",
",",
"uci",
":",
"str",
")",
"->",
"Move",
":",
"move",
"=",
"Move",
".",
"from_uci",
"(",
"uci",
")",
"if",
"not",
"move",
":",
"return",
"move",
"move",
"=",
"self",
".",
"_to_chess960",
"(",
"move",
")",
"move",
... | Parses the given move in UCI notation.
Supports both Chess960 and standard UCI notation.
The returned move is guaranteed to be either legal or a null move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
current position (but not a null move). | [
"Parses",
"the",
"given",
"move",
"in",
"UCI",
"notation",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2791-L2813 | train |
niklasf/python-chess | chess/__init__.py | Board.push_uci | def push_uci(self, uci: str) -> Move:
"""
Parses a move in UCI notation and puts it on the move stack.
Returns the move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
current position (but not a null move).
"""
move = self.parse_uci(uci... | python | def push_uci(self, uci: str) -> Move:
"""
Parses a move in UCI notation and puts it on the move stack.
Returns the move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
current position (but not a null move).
"""
move = self.parse_uci(uci... | [
"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.
Returns the move.
:raises: :exc:`ValueError` if the move is invalid or illegal in the
current position (but not a null move). | [
"Parses",
"a",
"move",
"in",
"UCI",
"notation",
"and",
"puts",
"it",
"on",
"the",
"move",
"stack",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2815-L2826 | train |
niklasf/python-chess | chess/__init__.py | Board.is_en_passant | def is_en_passant(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is an en passant capture."""
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
... | python | def is_en_passant(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is an en passant capture."""
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
... | [
"def",
"is_en_passant",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"return",
"(",
"self",
".",
"ep_square",
"==",
"move",
".",
"to_square",
"and",
"bool",
"(",
"self",
".",
"pawns",
"&",
"BB_SQUARES",
"[",
"move",
".",
"from_square"... | Checks if the given pseudo-legal move is an en passant capture. | [
"Checks",
"if",
"the",
"given",
"pseudo",
"-",
"legal",
"move",
"is",
"an",
"en",
"passant",
"capture",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2865-L2870 | train |
niklasf/python-chess | chess/__init__.py | Board.is_capture | def is_capture(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is a capture."""
return bool(BB_SQUARES[move.to_square] & self.occupied_co[not self.turn]) or self.is_en_passant(move) | python | def is_capture(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is a capture."""
return bool(BB_SQUARES[move.to_square] & self.occupied_co[not self.turn]) or self.is_en_passant(move) | [
"def",
"is_capture",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"return",
"bool",
"(",
"BB_SQUARES",
"[",
"move",
".",
"to_square",
"]",
"&",
"self",
".",
"occupied_co",
"[",
"not",
"self",
".",
"turn",
"]",
")",
"or",
"self",
"... | Checks if the given pseudo-legal move is a capture. | [
"Checks",
"if",
"the",
"given",
"pseudo",
"-",
"legal",
"move",
"is",
"a",
"capture",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2872-L2874 | train |
niklasf/python-chess | chess/__init__.py | Board.is_zeroing | def is_zeroing(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is a capture or pawn move."""
return bool(BB_SQUARES[move.from_square] & self.pawns or BB_SQUARES[move.to_square] & self.occupied_co[not self.turn]) | python | def is_zeroing(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is a capture or pawn move."""
return bool(BB_SQUARES[move.from_square] & self.pawns or BB_SQUARES[move.to_square] & self.occupied_co[not self.turn]) | [
"def",
"is_zeroing",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"return",
"bool",
"(",
"BB_SQUARES",
"[",
"move",
".",
"from_square",
"]",
"&",
"self",
".",
"pawns",
"or",
"BB_SQUARES",
"[",
"move",
".",
"to_square",
"]",
"&",
"se... | Checks if the given pseudo-legal move is a capture or pawn move. | [
"Checks",
"if",
"the",
"given",
"pseudo",
"-",
"legal",
"move",
"is",
"a",
"capture",
"or",
"pawn",
"move",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2876-L2878 | train |
niklasf/python-chess | chess/__init__.py | Board.is_irreversible | def is_irreversible(self, move: Move) -> bool:
"""
Checks if the given pseudo-legal move is irreversible.
In standard chess, pawn moves, captures and moves that destroy castling
rights are irreversible.
"""
backrank = BB_RANK_1 if self.turn == WHITE else BB_RANK_8
... | python | def is_irreversible(self, move: Move) -> bool:
"""
Checks if the given pseudo-legal move is irreversible.
In standard chess, pawn moves, captures and moves that destroy castling
rights are irreversible.
"""
backrank = BB_RANK_1 if self.turn == WHITE else BB_RANK_8
... | [
"def",
"is_irreversible",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"backrank",
"=",
"BB_RANK_1",
"if",
"self",
".",
"turn",
"==",
"WHITE",
"else",
"BB_RANK_8",
"cr",
"=",
"self",
".",
"clean_castling_rights",
"(",
")",
"&",
"backran... | Checks if the given pseudo-legal move is irreversible.
In standard chess, pawn moves, captures and moves that destroy castling
rights are irreversible. | [
"Checks",
"if",
"the",
"given",
"pseudo",
"-",
"legal",
"move",
"is",
"irreversible",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2880-L2892 | train |
niklasf/python-chess | chess/__init__.py | Board.is_castling | def is_castling(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is a castling move."""
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[s... | python | def is_castling(self, move: Move) -> bool:
"""Checks if the given pseudo-legal move is a castling move."""
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[s... | [
"def",
"is_castling",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"if",
"self",
".",
"kings",
"&",
"BB_SQUARES",
"[",
"move",
".",
"from_square",
"]",
":",
"diff",
"=",
"square_file",
"(",
"move",
".",
"from_square",
")",
"-",
"squ... | Checks if the given pseudo-legal move is a castling move. | [
"Checks",
"if",
"the",
"given",
"pseudo",
"-",
"legal",
"move",
"is",
"a",
"castling",
"move",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2894-L2899 | train |
niklasf/python-chess | chess/__init__.py | Board.is_kingside_castling | def is_kingside_castling(self, move: Move) -> bool:
"""
Checks if the given pseudo-legal move is a kingside castling move.
"""
return self.is_castling(move) and square_file(move.to_square) > square_file(move.from_square) | python | def is_kingside_castling(self, move: Move) -> bool:
"""
Checks if the given pseudo-legal move is a kingside castling move.
"""
return self.is_castling(move) and square_file(move.to_square) > square_file(move.from_square) | [
"def",
"is_kingside_castling",
"(",
"self",
",",
"move",
":",
"Move",
")",
"->",
"bool",
":",
"return",
"self",
".",
"is_castling",
"(",
"move",
")",
"and",
"square_file",
"(",
"move",
".",
"to_square",
")",
">",
"square_file",
"(",
"move",
".",
"from_sq... | Checks if the given pseudo-legal move is a kingside castling move. | [
"Checks",
"if",
"the",
"given",
"pseudo",
"-",
"legal",
"move",
"is",
"a",
"kingside",
"castling",
"move",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2901-L2905 | train |
niklasf/python-chess | chess/__init__.py | Board.has_castling_rights | def has_castling_rights(self, color: Color) -> bool:
"""Checks if the given side has castling rights."""
backrank = BB_RANK_1 if color == WHITE else BB_RANK_8
return bool(self.clean_castling_rights() & backrank) | python | def has_castling_rights(self, color: Color) -> bool:
"""Checks if the given side has castling rights."""
backrank = BB_RANK_1 if color == WHITE else BB_RANK_8
return bool(self.clean_castling_rights() & backrank) | [
"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",
"(",
")",
"&",
"bac... | Checks if the given side has castling rights. | [
"Checks",
"if",
"the",
"given",
"side",
"has",
"castling",
"rights",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L2969-L2972 | train |
niklasf/python-chess | chess/__init__.py | Board.has_chess960_castling_rights | def has_chess960_castling_rights(self) -> bool:
"""
Checks if there are castling rights that are only possible in Chess960.
"""
# Get valid Chess960 castling rights.
chess960 = self.chess960
self.chess960 = True
castling_rights = self.clean_castling_rights()
... | python | def has_chess960_castling_rights(self) -> bool:
"""
Checks if there are castling rights that are only possible in Chess960.
"""
# Get valid Chess960 castling rights.
chess960 = self.chess960
self.chess960 = True
castling_rights = self.clean_castling_rights()
... | [
"def",
"has_chess960_castling_rights",
"(",
"self",
")",
"->",
"bool",
":",
"# Get valid Chess960 castling rights.",
"chess960",
"=",
"self",
".",
"chess960",
"self",
".",
"chess960",
"=",
"True",
"castling_rights",
"=",
"self",
".",
"clean_castling_rights",
"(",
")... | Checks if there are castling rights that are only possible in Chess960. | [
"Checks",
"if",
"there",
"are",
"castling",
"rights",
"that",
"are",
"only",
"possible",
"in",
"Chess960",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L3016-L3038 | train |
niklasf/python-chess | chess/__init__.py | Board.status | def status(self) -> Status:
"""
Gets a bitmask of possible problems with the position.
Move making, generation and validation are only guaranteed to work on
a completely valid board.
:data:`~chess.STATUS_VALID` for a completely valid board.
Otherwise, bitwise combinati... | python | def status(self) -> Status:
"""
Gets a bitmask of possible problems with the position.
Move making, generation and validation are only guaranteed to work on
a completely valid board.
:data:`~chess.STATUS_VALID` for a completely valid board.
Otherwise, bitwise combinati... | [
"def",
"status",
"(",
"self",
")",
"->",
"Status",
":",
"errors",
"=",
"STATUS_VALID",
"# There must be at least one piece.",
"if",
"not",
"self",
".",
"occupied",
":",
"errors",
"|=",
"STATUS_EMPTY",
"# There must be exactly one king of each color.",
"if",
"not",
"se... | Gets a bitmask of possible problems with the position.
Move making, generation and validation are only guaranteed to work on
a completely valid board.
:data:`~chess.STATUS_VALID` for a completely valid board.
Otherwise, bitwise combinations of:
:data:`~chess.STATUS_NO_WHITE_KI... | [
"Gets",
"a",
"bitmask",
"of",
"possible",
"problems",
"with",
"the",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L3040-L3108 | train |
niklasf/python-chess | chess/__init__.py | SquareSet.remove | def remove(self, square: Square) -> None:
"""
Removes a square from the set.
:raises: :exc:`KeyError` if the given square was not in the set.
"""
mask = BB_SQUARES[square]
if self.mask & mask:
self.mask ^= mask
else:
raise KeyError(square) | python | def remove(self, square: Square) -> None:
"""
Removes a square from the set.
:raises: :exc:`KeyError` if the given square was not in the set.
"""
mask = BB_SQUARES[square]
if self.mask & mask:
self.mask ^= mask
else:
raise KeyError(square) | [
"def",
"remove",
"(",
"self",
",",
"square",
":",
"Square",
")",
"->",
"None",
":",
"mask",
"=",
"BB_SQUARES",
"[",
"square",
"]",
"if",
"self",
".",
"mask",
"&",
"mask",
":",
"self",
".",
"mask",
"^=",
"mask",
"else",
":",
"raise",
"KeyError",
"("... | Removes a square from the set.
:raises: :exc:`KeyError` if the given square was not in the set. | [
"Removes",
"a",
"square",
"from",
"the",
"set",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L3695-L3705 | train |
niklasf/python-chess | chess/__init__.py | SquareSet.pop | def pop(self) -> Square:
"""
Removes a square from the set and returns it.
:raises: :exc:`KeyError` on an empty set.
"""
if not self.mask:
raise KeyError("pop from empty SquareSet")
square = lsb(self.mask)
self.mask &= (self.mask - 1)
return ... | python | def pop(self) -> Square:
"""
Removes a square from the set and returns it.
:raises: :exc:`KeyError` on an empty set.
"""
if not self.mask:
raise KeyError("pop from empty SquareSet")
square = lsb(self.mask)
self.mask &= (self.mask - 1)
return ... | [
"def",
"pop",
"(",
"self",
")",
"->",
"Square",
":",
"if",
"not",
"self",
".",
"mask",
":",
"raise",
"KeyError",
"(",
"\"pop from empty SquareSet\"",
")",
"square",
"=",
"lsb",
"(",
"self",
".",
"mask",
")",
"self",
".",
"mask",
"&=",
"(",
"self",
".... | Removes a square from the set and returns it.
:raises: :exc:`KeyError` on an empty set. | [
"Removes",
"a",
"square",
"from",
"the",
"set",
"and",
"returns",
"it",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L3707-L3718 | train |
niklasf/python-chess | chess/__init__.py | SquareSet.tolist | def tolist(self) -> List[bool]:
"""Convert the set to a list of 64 bools."""
result = [False] * 64
for square in self:
result[square] = True
return result | python | def tolist(self) -> List[bool]:
"""Convert the set to a list of 64 bools."""
result = [False] * 64
for square in self:
result[square] = True
return result | [
"def",
"tolist",
"(",
"self",
")",
"->",
"List",
"[",
"bool",
"]",
":",
"result",
"=",
"[",
"False",
"]",
"*",
"64",
"for",
"square",
"in",
"self",
":",
"result",
"[",
"square",
"]",
"=",
"True",
"return",
"result"
] | Convert the set to a list of 64 bools. | [
"Convert",
"the",
"set",
"to",
"a",
"list",
"of",
"64",
"bools",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/__init__.py#L3734-L3739 | train |
niklasf/python-chess | chess/variant.py | find_variant | def find_variant(name: str) -> Type[chess.Board]:
"""Looks for a variant board class by variant name."""
for variant in VARIANTS:
if any(alias.lower() == name.lower() for alias in variant.aliases):
return variant
raise ValueError("unsupported variant: {}".format(name)) | python | def find_variant(name: str) -> Type[chess.Board]:
"""Looks for a variant board class by variant name."""
for variant in VARIANTS:
if any(alias.lower() == name.lower() for alias in variant.aliases):
return variant
raise ValueError("unsupported variant: {}".format(name)) | [
"def",
"find_variant",
"(",
"name",
":",
"str",
")",
"->",
"Type",
"[",
"chess",
".",
"Board",
"]",
":",
"for",
"variant",
"in",
"VARIANTS",
":",
"if",
"any",
"(",
"alias",
".",
"lower",
"(",
")",
"==",
"name",
".",
"lower",
"(",
")",
"for",
"ali... | Looks for a variant board class by variant name. | [
"Looks",
"for",
"a",
"variant",
"board",
"class",
"by",
"variant",
"name",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/variant.py#L862-L867 | train |
niklasf/python-chess | chess/polyglot.py | zobrist_hash | def zobrist_hash(board: chess.Board, *, _hasher: Callable[[chess.Board], int] = ZobristHasher(POLYGLOT_RANDOM_ARRAY)) -> int:
"""
Calculates the Polyglot Zobrist hash of the position.
A Zobrist hash is an XOR of pseudo-random values picked from
an array. Which values are picked is decided by features o... | python | def zobrist_hash(board: chess.Board, *, _hasher: Callable[[chess.Board], int] = ZobristHasher(POLYGLOT_RANDOM_ARRAY)) -> int:
"""
Calculates the Polyglot Zobrist hash of the position.
A Zobrist hash is an XOR of pseudo-random values picked from
an array. Which values are picked is decided by features o... | [
"def",
"zobrist_hash",
"(",
"board",
":",
"chess",
".",
"Board",
",",
"*",
",",
"_hasher",
":",
"Callable",
"[",
"[",
"chess",
".",
"Board",
"]",
",",
"int",
"]",
"=",
"ZobristHasher",
"(",
"POLYGLOT_RANDOM_ARRAY",
")",
")",
"->",
"int",
":",
"return",... | Calculates the Polyglot Zobrist hash of the position.
A Zobrist hash is an XOR of pseudo-random values picked from
an array. Which values are picked is decided by features of the
position, such as piece positions, castling rights and en passant
squares. | [
"Calculates",
"the",
"Polyglot",
"Zobrist",
"hash",
"of",
"the",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/polyglot.py#L291-L300 | train |
niklasf/python-chess | chess/polyglot.py | MemoryMappedReader.find_all | def find_all(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = ()) -> Iterator[Entry]:
"""Seeks a specific position and yields corresponding entries."""
try:
key = int(board) # type: ignore
context = None # type: Optional[c... | python | def find_all(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = ()) -> Iterator[Entry]:
"""Seeks a specific position and yields corresponding entries."""
try:
key = int(board) # type: ignore
context = None # type: Optional[c... | [
"def",
"find_all",
"(",
"self",
",",
"board",
":",
"Union",
"[",
"chess",
".",
"Board",
",",
"int",
"]",
",",
"*",
",",
"minimum_weight",
":",
"int",
"=",
"1",
",",
"exclude_moves",
":",
"Container",
"[",
"chess",
".",
"Move",
"]",
"=",
"(",
")",
... | Seeks a specific position and yields corresponding entries. | [
"Seeks",
"a",
"specific",
"position",
"and",
"yields",
"corresponding",
"entries",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/polyglot.py#L387-L419 | train |
niklasf/python-chess | chess/polyglot.py | MemoryMappedReader.find | def find(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = ()) -> Entry:
"""
Finds the main entry for the given position or Zobrist hash.
The main entry is the (first) entry with the highest weight.
By default, entries with weight ... | python | def find(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = ()) -> Entry:
"""
Finds the main entry for the given position or Zobrist hash.
The main entry is the (first) entry with the highest weight.
By default, entries with weight ... | [
"def",
"find",
"(",
"self",
",",
"board",
":",
"Union",
"[",
"chess",
".",
"Board",
",",
"int",
"]",
",",
"*",
",",
"minimum_weight",
":",
"int",
"=",
"1",
",",
"exclude_moves",
":",
"Container",
"[",
"chess",
".",
"Move",
"]",
"=",
"(",
")",
")"... | Finds the main entry for the given position or Zobrist hash.
The main entry is the (first) entry with the highest weight.
By default, entries with weight ``0`` are excluded. This is a common
way to delete entries from an opening book without compacting it. Pass
*minimum_weight* ``0`` t... | [
"Finds",
"the",
"main",
"entry",
"for",
"the",
"given",
"position",
"or",
"Zobrist",
"hash",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/polyglot.py#L421-L438 | train |
niklasf/python-chess | chess/polyglot.py | MemoryMappedReader.choice | def choice(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
"""
Uniformly selects a random entry for the given position.
:raises: :exc:`IndexError` if no entries are found.
"""
chosen_entry = No... | python | def choice(self, board: Union[chess.Board, int], *, minimum_weight: int = 1, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
"""
Uniformly selects a random entry for the given position.
:raises: :exc:`IndexError` if no entries are found.
"""
chosen_entry = No... | [
"def",
"choice",
"(",
"self",
",",
"board",
":",
"Union",
"[",
"chess",
".",
"Board",
",",
"int",
"]",
",",
"*",
",",
"minimum_weight",
":",
"int",
"=",
"1",
",",
"exclude_moves",
":",
"Container",
"[",
"chess",
".",
"Move",
"]",
"=",
"(",
")",
"... | Uniformly selects a random entry for the given position.
:raises: :exc:`IndexError` if no entries are found. | [
"Uniformly",
"selects",
"a",
"random",
"entry",
"for",
"the",
"given",
"position",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/polyglot.py#L446-L461 | train |
niklasf/python-chess | chess/polyglot.py | MemoryMappedReader.weighted_choice | def weighted_choice(self, board: Union[chess.Board, int], *, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
"""
Selects a random entry for the given position, distributed by the
weights of the entries.
:raises: :exc:`IndexError` if no entries are found.
"""
... | python | def weighted_choice(self, board: Union[chess.Board, int], *, exclude_moves: Container[chess.Move] = (), random=random) -> Entry:
"""
Selects a random entry for the given position, distributed by the
weights of the entries.
:raises: :exc:`IndexError` if no entries are found.
"""
... | [
"def",
"weighted_choice",
"(",
"self",
",",
"board",
":",
"Union",
"[",
"chess",
".",
"Board",
",",
"int",
"]",
",",
"*",
",",
"exclude_moves",
":",
"Container",
"[",
"chess",
".",
"Move",
"]",
"=",
"(",
")",
",",
"random",
"=",
"random",
")",
"->"... | Selects a random entry for the given position, distributed by the
weights of the entries.
:raises: :exc:`IndexError` if no entries are found. | [
"Selects",
"a",
"random",
"entry",
"for",
"the",
"given",
"position",
"distributed",
"by",
"the",
"weights",
"of",
"the",
"entries",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/polyglot.py#L463-L482 | train |
niklasf/python-chess | chess/polyglot.py | MemoryMappedReader.close | def close(self) -> None:
"""Closes the reader."""
if self.mmap is not None:
self.mmap.close()
try:
os.close(self.fd)
except OSError:
pass | python | def close(self) -> None:
"""Closes the reader."""
if self.mmap is not None:
self.mmap.close()
try:
os.close(self.fd)
except OSError:
pass | [
"def",
"close",
"(",
"self",
")",
"->",
"None",
":",
"if",
"self",
".",
"mmap",
"is",
"not",
"None",
":",
"self",
".",
"mmap",
".",
"close",
"(",
")",
"try",
":",
"os",
".",
"close",
"(",
"self",
".",
"fd",
")",
"except",
"OSError",
":",
"pass"... | Closes the reader. | [
"Closes",
"the",
"reader",
"."
] | d91f986ca3e046b300a0d7d9ee2a13b07610fe1a | https://github.com/niklasf/python-chess/blob/d91f986ca3e046b300a0d7d9ee2a13b07610fe1a/chess/polyglot.py#L484-L492 | train |
mapbox/mapbox-sdk-py | mapbox/encoding.py | _geom_points | def _geom_points(geom):
"""GeoJSON geometry to a sequence of point tuples
"""
if geom['type'] == 'Point':
yield tuple(geom['coordinates'])
elif geom['type'] in ('MultiPoint', 'LineString'):
for position in geom['coordinates']:
yield tuple(position)
else:
raise Inv... | python | def _geom_points(geom):
"""GeoJSON geometry to a sequence of point tuples
"""
if geom['type'] == 'Point':
yield tuple(geom['coordinates'])
elif geom['type'] in ('MultiPoint', 'LineString'):
for position in geom['coordinates']:
yield tuple(position)
else:
raise Inv... | [
"def",
"_geom_points",
"(",
"geom",
")",
":",
"if",
"geom",
"[",
"'type'",
"]",
"==",
"'Point'",
":",
"yield",
"tuple",
"(",
"geom",
"[",
"'coordinates'",
"]",
")",
"elif",
"geom",
"[",
"'type'",
"]",
"in",
"(",
"'MultiPoint'",
",",
"'LineString'",
")"... | GeoJSON geometry to a sequence of point tuples | [
"GeoJSON",
"geometry",
"to",
"a",
"sequence",
"of",
"point",
"tuples"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/encoding.py#L7-L17 | train |
mapbox/mapbox-sdk-py | mapbox/encoding.py | read_points | def read_points(features):
""" Iterable of features to a sequence of point tuples
Where "features" can be either GeoJSON mappings
or objects implementing the geo_interface
"""
for feature in features:
if isinstance(feature, (tuple, list)) and len(feature) == 2:
yield feature
... | python | def read_points(features):
""" Iterable of features to a sequence of point tuples
Where "features" can be either GeoJSON mappings
or objects implementing the geo_interface
"""
for feature in features:
if isinstance(feature, (tuple, list)) and len(feature) == 2:
yield feature
... | [
"def",
"read_points",
"(",
"features",
")",
":",
"for",
"feature",
"in",
"features",
":",
"if",
"isinstance",
"(",
"feature",
",",
"(",
"tuple",
",",
"list",
")",
")",
"and",
"len",
"(",
"feature",
")",
"==",
"2",
":",
"yield",
"feature",
"elif",
"ha... | Iterable of features to a sequence of point tuples
Where "features" can be either GeoJSON mappings
or objects implementing the geo_interface | [
"Iterable",
"of",
"features",
"to",
"a",
"sequence",
"of",
"point",
"tuples",
"Where",
"features",
"can",
"be",
"either",
"GeoJSON",
"mappings",
"or",
"objects",
"implementing",
"the",
"geo_interface"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/encoding.py#L20-L56 | train |
mapbox/mapbox-sdk-py | mapbox/encoding.py | encode_polyline | def encode_polyline(features):
"""Encode and iterable of features as a polyline
"""
points = list(read_points(features))
latlon_points = [(x[1], x[0]) for x in points]
return polyline.encode(latlon_points) | python | def encode_polyline(features):
"""Encode and iterable of features as a polyline
"""
points = list(read_points(features))
latlon_points = [(x[1], x[0]) for x in points]
return polyline.encode(latlon_points) | [
"def",
"encode_polyline",
"(",
"features",
")",
":",
"points",
"=",
"list",
"(",
"read_points",
"(",
"features",
")",
")",
"latlon_points",
"=",
"[",
"(",
"x",
"[",
"1",
"]",
",",
"x",
"[",
"0",
"]",
")",
"for",
"x",
"in",
"points",
"]",
"return",
... | Encode and iterable of features as a polyline | [
"Encode",
"and",
"iterable",
"of",
"features",
"as",
"a",
"polyline"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/encoding.py#L81-L86 | train |
mapbox/mapbox-sdk-py | mapbox/services/directions.py | Directions.directions | def directions(self, features, profile='mapbox/driving',
alternatives=None, geometries=None, overview=None, steps=None,
continue_straight=None, waypoint_snapping=None, annotations=None,
language=None, **kwargs):
"""Request directions for waypoints encoded... | python | def directions(self, features, profile='mapbox/driving',
alternatives=None, geometries=None, overview=None, steps=None,
continue_straight=None, waypoint_snapping=None, annotations=None,
language=None, **kwargs):
"""Request directions for waypoints encoded... | [
"def",
"directions",
"(",
"self",
",",
"features",
",",
"profile",
"=",
"'mapbox/driving'",
",",
"alternatives",
"=",
"None",
",",
"geometries",
"=",
"None",
",",
"overview",
"=",
"None",
",",
"steps",
"=",
"None",
",",
"continue_straight",
"=",
"None",
",... | Request directions for waypoints encoded as GeoJSON features.
Parameters
----------
features : iterable
An collection of GeoJSON features
profile : str
Name of a Mapbox profile such as 'mapbox.driving'
alternatives : bool
Whether to try to ret... | [
"Request",
"directions",
"for",
"waypoints",
"encoded",
"as",
"GeoJSON",
"features",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/directions.py#L143-L249 | train |
mapbox/mapbox-sdk-py | mapbox/services/matrix.py | DirectionsMatrix.matrix | def matrix(self, coordinates, profile='mapbox/driving',
sources=None, destinations=None, annotations=None):
"""Request a directions matrix for trips between coordinates
In the default case, the matrix returns a symmetric matrix,
using all input coordinates as sources and destina... | python | def matrix(self, coordinates, profile='mapbox/driving',
sources=None, destinations=None, annotations=None):
"""Request a directions matrix for trips between coordinates
In the default case, the matrix returns a symmetric matrix,
using all input coordinates as sources and destina... | [
"def",
"matrix",
"(",
"self",
",",
"coordinates",
",",
"profile",
"=",
"'mapbox/driving'",
",",
"sources",
"=",
"None",
",",
"destinations",
"=",
"None",
",",
"annotations",
"=",
"None",
")",
":",
"annotations",
"=",
"self",
".",
"_validate_annotations",
"("... | Request a directions matrix for trips between coordinates
In the default case, the matrix returns a symmetric matrix,
using all input coordinates as sources and destinations. You may
also generate an asymmetric matrix, with only some coordinates
as sources or destinations:
Para... | [
"Request",
"a",
"directions",
"matrix",
"for",
"trips",
"between",
"coordinates"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/matrix.py#L65-L138 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets._attribs | def _attribs(self, name=None, description=None):
"""Form an attributes dictionary from keyword args."""
a = {}
if name:
a['name'] = name
if description:
a['description'] = description
return a | python | def _attribs(self, name=None, description=None):
"""Form an attributes dictionary from keyword args."""
a = {}
if name:
a['name'] = name
if description:
a['description'] = description
return a | [
"def",
"_attribs",
"(",
"self",
",",
"name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"a",
"=",
"{",
"}",
"if",
"name",
":",
"a",
"[",
"'name'",
"]",
"=",
"name",
"if",
"description",
":",
"a",
"[",
"'description'",
"]",
"=",
"desc... | Form an attributes dictionary from keyword args. | [
"Form",
"an",
"attributes",
"dictionary",
"from",
"keyword",
"args",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L25-L32 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets.create | def create(self, name=None, description=None):
"""Creates a new, empty dataset.
Parameters
----------
name : str, optional
The name of the dataset.
description : str, optional
The description of the dataset.
Returns
-------
reque... | python | def create(self, name=None, description=None):
"""Creates a new, empty dataset.
Parameters
----------
name : str, optional
The name of the dataset.
description : str, optional
The description of the dataset.
Returns
-------
reque... | [
"def",
"create",
"(",
"self",
",",
"name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{owner}'",
")",
".",
"expand",
"(",
"owner",
"=",
"self",
".",
"username",
")",
"return... | Creates a new, empty dataset.
Parameters
----------
name : str, optional
The name of the dataset.
description : str, optional
The description of the dataset.
Returns
-------
request.Response
The response contains the properti... | [
"Creates",
"a",
"new",
"empty",
"dataset",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L34-L53 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets.list | def list(self):
"""Lists all datasets for a particular account.
Returns
-------
request.Response
The response contains a list of JSON objects describing datasets.
"""
uri = URITemplate(self.baseuri + '/{owner}').expand(
owner=self.usernam... | python | def list(self):
"""Lists all datasets for a particular account.
Returns
-------
request.Response
The response contains a list of JSON objects describing datasets.
"""
uri = URITemplate(self.baseuri + '/{owner}').expand(
owner=self.usernam... | [
"def",
"list",
"(",
"self",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{owner}'",
")",
".",
"expand",
"(",
"owner",
"=",
"self",
".",
"username",
")",
"return",
"self",
".",
"session",
".",
"get",
"(",
"uri",
")"
] | Lists all datasets for a particular account.
Returns
-------
request.Response
The response contains a list of JSON objects describing datasets. | [
"Lists",
"all",
"datasets",
"for",
"a",
"particular",
"account",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L55-L66 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets.update_dataset | def update_dataset(self, dataset, name=None, description=None):
"""Updates a single dataset.
Parameters
----------
dataset : str
The dataset id.
name : str, optional
The name of the dataset.
description : str, optional
The descriptio... | python | def update_dataset(self, dataset, name=None, description=None):
"""Updates a single dataset.
Parameters
----------
dataset : str
The dataset id.
name : str, optional
The name of the dataset.
description : str, optional
The descriptio... | [
"def",
"update_dataset",
"(",
"self",
",",
"dataset",
",",
"name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{owner}/{id}'",
")",
".",
"expand",
"(",
"owner",
"=",
"self",
".... | Updates a single dataset.
Parameters
----------
dataset : str
The dataset id.
name : str, optional
The name of the dataset.
description : str, optional
The description of the dataset.
Returns
-------
request.Response... | [
"Updates",
"a",
"single",
"dataset",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L86-L108 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets.delete_dataset | def delete_dataset(self, dataset):
"""Deletes a single dataset, including all of the features that it contains.
Parameters
----------
dataset : str
The dataset id.
Returns
-------
HTTP status code.
"""
uri = URITemplate(self.... | python | def delete_dataset(self, dataset):
"""Deletes a single dataset, including all of the features that it contains.
Parameters
----------
dataset : str
The dataset id.
Returns
-------
HTTP status code.
"""
uri = URITemplate(self.... | [
"def",
"delete_dataset",
"(",
"self",
",",
"dataset",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{owner}/{id}'",
")",
".",
"expand",
"(",
"owner",
"=",
"self",
".",
"username",
",",
"id",
"=",
"dataset",
")",
"return",
"s... | Deletes a single dataset, including all of the features that it contains.
Parameters
----------
dataset : str
The dataset id.
Returns
-------
HTTP status code. | [
"Deletes",
"a",
"single",
"dataset",
"including",
"all",
"of",
"the",
"features",
"that",
"it",
"contains",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L110-L125 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets.list_features | def list_features(self, dataset, reverse=False, start=None, limit=None):
"""Lists features in a dataset.
Parameters
----------
dataset : str
The dataset id.
reverse : str, optional
List features in reverse order.
Possible value ... | python | def list_features(self, dataset, reverse=False, start=None, limit=None):
"""Lists features in a dataset.
Parameters
----------
dataset : str
The dataset id.
reverse : str, optional
List features in reverse order.
Possible value ... | [
"def",
"list_features",
"(",
"self",
",",
"dataset",
",",
"reverse",
"=",
"False",
",",
"start",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{owner}/{id}/features'",
")",
".",
"expand"... | Lists features in a dataset.
Parameters
----------
dataset : str
The dataset id.
reverse : str, optional
List features in reverse order.
Possible value is "true".
start : str, optional
The id of the feature after wh... | [
"Lists",
"features",
"in",
"a",
"dataset",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L127-L162 | train |
mapbox/mapbox-sdk-py | mapbox/services/datasets.py | Datasets.delete_feature | def delete_feature(self, dataset, fid):
"""Removes a feature from a dataset.
Parameters
----------
dataset : str
The dataset id.
fid : str
The feature id.
Returns
-------
HTTP status code.
"""
uri = URITe... | python | def delete_feature(self, dataset, fid):
"""Removes a feature from a dataset.
Parameters
----------
dataset : str
The dataset id.
fid : str
The feature id.
Returns
-------
HTTP status code.
"""
uri = URITe... | [
"def",
"delete_feature",
"(",
"self",
",",
"dataset",
",",
"fid",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{owner}/{did}/features/{fid}'",
")",
".",
"expand",
"(",
"owner",
"=",
"self",
".",
"username",
",",
"did",
"=",
"... | Removes a feature from a dataset.
Parameters
----------
dataset : str
The dataset id.
fid : str
The feature id.
Returns
-------
HTTP status code. | [
"Removes",
"a",
"feature",
"from",
"a",
"dataset",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/datasets.py#L217-L236 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader._get_credentials | def _get_credentials(self):
"""Gets temporary S3 credentials to stage user-uploaded files
"""
uri = URITemplate(self.baseuri + '/{username}/credentials').expand(
username=self.username)
resp = self.session.post(uri)
self.handle_http_error(
resp,
... | python | def _get_credentials(self):
"""Gets temporary S3 credentials to stage user-uploaded files
"""
uri = URITemplate(self.baseuri + '/{username}/credentials').expand(
username=self.username)
resp = self.session.post(uri)
self.handle_http_error(
resp,
... | [
"def",
"_get_credentials",
"(",
"self",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{username}/credentials'",
")",
".",
"expand",
"(",
"username",
"=",
"self",
".",
"username",
")",
"resp",
"=",
"self",
".",
"session",
".",
... | Gets temporary S3 credentials to stage user-uploaded files | [
"Gets",
"temporary",
"S3",
"credentials",
"to",
"stage",
"user",
"-",
"uploaded",
"files"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L37-L51 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader._validate_tileset | def _validate_tileset(self, tileset):
"""Validate the tileset name and
ensure that it includes the username
"""
if '.' not in tileset:
tileset = "{0}.{1}".format(self.username, tileset)
pattern = '^[a-z0-9-_]{1,32}\.[a-z0-9-_]{1,32}$'
if not re.match(pattern,... | python | def _validate_tileset(self, tileset):
"""Validate the tileset name and
ensure that it includes the username
"""
if '.' not in tileset:
tileset = "{0}.{1}".format(self.username, tileset)
pattern = '^[a-z0-9-_]{1,32}\.[a-z0-9-_]{1,32}$'
if not re.match(pattern,... | [
"def",
"_validate_tileset",
"(",
"self",
",",
"tileset",
")",
":",
"if",
"'.'",
"not",
"in",
"tileset",
":",
"tileset",
"=",
"\"{0}.{1}\"",
".",
"format",
"(",
"self",
".",
"username",
",",
"tileset",
")",
"pattern",
"=",
"'^[a-z0-9-_]{1,32}\\.[a-z0-9-_]{1,32}... | Validate the tileset name and
ensure that it includes the username | [
"Validate",
"the",
"tileset",
"name",
"and",
"ensure",
"that",
"it",
"includes",
"the",
"username"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L53-L66 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader._resolve_username | def _resolve_username(self, account, username):
"""Resolve username and handle deprecation of account kwarg"""
if account is not None:
warnings.warn(
"Use keyword argument 'username' instead of 'account'",
DeprecationWarning)
return username or account... | python | def _resolve_username(self, account, username):
"""Resolve username and handle deprecation of account kwarg"""
if account is not None:
warnings.warn(
"Use keyword argument 'username' instead of 'account'",
DeprecationWarning)
return username or account... | [
"def",
"_resolve_username",
"(",
"self",
",",
"account",
",",
"username",
")",
":",
"if",
"account",
"is",
"not",
"None",
":",
"warnings",
".",
"warn",
"(",
"\"Use keyword argument 'username' instead of 'account'\"",
",",
"DeprecationWarning",
")",
"return",
"userna... | Resolve username and handle deprecation of account kwarg | [
"Resolve",
"username",
"and",
"handle",
"deprecation",
"of",
"account",
"kwarg"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L69-L75 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader.stage | def stage(self, fileobj, creds=None, callback=None):
"""Stages data in a Mapbox-owned S3 bucket
If creds are not provided, temporary credentials will be
generated using the Mapbox API.
Parameters
----------
fileobj: file object or filename
A Python file obje... | python | def stage(self, fileobj, creds=None, callback=None):
"""Stages data in a Mapbox-owned S3 bucket
If creds are not provided, temporary credentials will be
generated using the Mapbox API.
Parameters
----------
fileobj: file object or filename
A Python file obje... | [
"def",
"stage",
"(",
"self",
",",
"fileobj",
",",
"creds",
"=",
"None",
",",
"callback",
"=",
"None",
")",
":",
"if",
"not",
"hasattr",
"(",
"fileobj",
",",
"'read'",
")",
":",
"fileobj",
"=",
"open",
"(",
"fileobj",
",",
"'rb'",
")",
"if",
"not",
... | Stages data in a Mapbox-owned S3 bucket
If creds are not provided, temporary credentials will be
generated using the Mapbox API.
Parameters
----------
fileobj: file object or filename
A Python file object opened in binary mode or a filename.
creds: dict
... | [
"Stages",
"data",
"in",
"a",
"Mapbox",
"-",
"owned",
"S3",
"bucket"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L77-L117 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader.create | def create(self, stage_url, tileset, name=None, patch=False, bypass=False):
"""Create a tileset
Note: this step is refered to as "upload" in the API docs;
This class's upload() method is a high-level function
which acts like the Studio upload form.
Returns a response object whe... | python | def create(self, stage_url, tileset, name=None, patch=False, bypass=False):
"""Create a tileset
Note: this step is refered to as "upload" in the API docs;
This class's upload() method is a high-level function
which acts like the Studio upload form.
Returns a response object whe... | [
"def",
"create",
"(",
"self",
",",
"stage_url",
",",
"tileset",
",",
"name",
"=",
"None",
",",
"patch",
"=",
"False",
",",
"bypass",
"=",
"False",
")",
":",
"tileset",
"=",
"self",
".",
"_validate_tileset",
"(",
"tileset",
")",
"username",
",",
"_name"... | Create a tileset
Note: this step is refered to as "upload" in the API docs;
This class's upload() method is a high-level function
which acts like the Studio upload form.
Returns a response object where the json() contents are
an upload dict. Completion of the tileset may take s... | [
"Create",
"a",
"tileset"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L119-L175 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader.list | def list(self, account=None, username=None):
"""List of all uploads
Returns a Response object, the json() method of which returns
a list of uploads
Parameters
----------
username : str
Account username, defaults to the service's username.
account : s... | python | def list(self, account=None, username=None):
"""List of all uploads
Returns a Response object, the json() method of which returns
a list of uploads
Parameters
----------
username : str
Account username, defaults to the service's username.
account : s... | [
"def",
"list",
"(",
"self",
",",
"account",
"=",
"None",
",",
"username",
"=",
"None",
")",
":",
"username",
"=",
"self",
".",
"_resolve_username",
"(",
"account",
",",
"username",
")",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{u... | List of all uploads
Returns a Response object, the json() method of which returns
a list of uploads
Parameters
----------
username : str
Account username, defaults to the service's username.
account : str, **deprecated**
Alias for username. Will ... | [
"List",
"of",
"all",
"uploads"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L177-L199 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader.status | def status(self, upload, account=None, username=None):
"""Check status of upload
Parameters
----------
upload: str
The id of the upload or a dict with key 'id'.
username : str
Account username, defaults to the service's username.
account : str, **... | python | def status(self, upload, account=None, username=None):
"""Check status of upload
Parameters
----------
upload: str
The id of the upload or a dict with key 'id'.
username : str
Account username, defaults to the service's username.
account : str, **... | [
"def",
"status",
"(",
"self",
",",
"upload",
",",
"account",
"=",
"None",
",",
"username",
"=",
"None",
")",
":",
"username",
"=",
"self",
".",
"_resolve_username",
"(",
"account",
",",
"username",
")",
"if",
"isinstance",
"(",
"upload",
",",
"dict",
"... | Check status of upload
Parameters
----------
upload: str
The id of the upload or a dict with key 'id'.
username : str
Account username, defaults to the service's username.
account : str, **deprecated**
Alias for username. Will be removed in ve... | [
"Check",
"status",
"of",
"upload"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L228-L253 | train |
mapbox/mapbox-sdk-py | mapbox/services/uploads.py | Uploader.upload | def upload(self, fileobj, tileset, name=None, patch=False, callback=None, bypass=False):
"""Upload data and create a Mapbox tileset
Effectively replicates the Studio upload feature. Returns a
Response object, the json() of which returns a dict with upload
metadata.
Parameters
... | python | def upload(self, fileobj, tileset, name=None, patch=False, callback=None, bypass=False):
"""Upload data and create a Mapbox tileset
Effectively replicates the Studio upload feature. Returns a
Response object, the json() of which returns a dict with upload
metadata.
Parameters
... | [
"def",
"upload",
"(",
"self",
",",
"fileobj",
",",
"tileset",
",",
"name",
"=",
"None",
",",
"patch",
"=",
"False",
",",
"callback",
"=",
"None",
",",
"bypass",
"=",
"False",
")",
":",
"tileset",
"=",
"self",
".",
"_validate_tileset",
"(",
"tileset",
... | Upload data and create a Mapbox tileset
Effectively replicates the Studio upload feature. Returns a
Response object, the json() of which returns a dict with upload
metadata.
Parameters
----------
fileobj: file object or str
A filename or a Python file object... | [
"Upload",
"data",
"and",
"create",
"a",
"Mapbox",
"tileset"
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/uploads.py#L255-L287 | train |
mapbox/mapbox-sdk-py | mapbox/services/geocoding.py | Geocoder._validate_country_codes | def _validate_country_codes(self, ccs):
"""Validate country code filters for use in requests."""
for cc in ccs:
if cc not in self.country_codes:
raise InvalidCountryCodeError(cc)
return {'country': ",".join(ccs)} | python | def _validate_country_codes(self, ccs):
"""Validate country code filters for use in requests."""
for cc in ccs:
if cc not in self.country_codes:
raise InvalidCountryCodeError(cc)
return {'country': ",".join(ccs)} | [
"def",
"_validate_country_codes",
"(",
"self",
",",
"ccs",
")",
":",
"for",
"cc",
"in",
"ccs",
":",
"if",
"cc",
"not",
"in",
"self",
".",
"country_codes",
":",
"raise",
"InvalidCountryCodeError",
"(",
"cc",
")",
"return",
"{",
"'country'",
":",
"\",\"",
... | Validate country code filters for use in requests. | [
"Validate",
"country",
"code",
"filters",
"for",
"use",
"in",
"requests",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/geocoding.py#L28-L33 | train |
mapbox/mapbox-sdk-py | mapbox/services/geocoding.py | Geocoder._validate_place_types | def _validate_place_types(self, types):
"""Validate place types and return a mapping for use in requests."""
for pt in types:
if pt not in self.place_types:
raise InvalidPlaceTypeError(pt)
return {'types': ",".join(types)} | python | def _validate_place_types(self, types):
"""Validate place types and return a mapping for use in requests."""
for pt in types:
if pt not in self.place_types:
raise InvalidPlaceTypeError(pt)
return {'types': ",".join(types)} | [
"def",
"_validate_place_types",
"(",
"self",
",",
"types",
")",
":",
"for",
"pt",
"in",
"types",
":",
"if",
"pt",
"not",
"in",
"self",
".",
"place_types",
":",
"raise",
"InvalidPlaceTypeError",
"(",
"pt",
")",
"return",
"{",
"'types'",
":",
"\",\"",
".",... | Validate place types and return a mapping for use in requests. | [
"Validate",
"place",
"types",
"and",
"return",
"a",
"mapping",
"for",
"use",
"in",
"requests",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/geocoding.py#L35-L40 | train |
mapbox/mapbox-sdk-py | mapbox/services/geocoding.py | Geocoder.forward | def forward(self, address, types=None, lon=None, lat=None,
country=None, bbox=None, limit=None, languages=None):
"""Returns a Requests response object that contains a GeoJSON
collection of places matching the given address.
`response.geojson()` returns the geocoding result as Ge... | python | def forward(self, address, types=None, lon=None, lat=None,
country=None, bbox=None, limit=None, languages=None):
"""Returns a Requests response object that contains a GeoJSON
collection of places matching the given address.
`response.geojson()` returns the geocoding result as Ge... | [
"def",
"forward",
"(",
"self",
",",
"address",
",",
"types",
"=",
"None",
",",
"lon",
"=",
"None",
",",
"lat",
"=",
"None",
",",
"country",
"=",
"None",
",",
"bbox",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"languages",
"=",
"None",
")",
":",... | Returns a Requests response object that contains a GeoJSON
collection of places matching the given address.
`response.geojson()` returns the geocoding result as GeoJSON.
`response.status_code` returns the HTTP API status code.
Place results may be constrained to those of one or more ty... | [
"Returns",
"a",
"Requests",
"response",
"object",
"that",
"contains",
"a",
"GeoJSON",
"collection",
"of",
"places",
"matching",
"the",
"given",
"address",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/geocoding.py#L42-L79 | train |
mapbox/mapbox-sdk-py | mapbox/services/geocoding.py | Geocoder.reverse | def reverse(self, lon, lat, types=None, limit=None):
"""Returns a Requests response object that contains a GeoJSON
collection of places near the given longitude and latitude.
`response.geojson()` returns the geocoding result as GeoJSON.
`response.status_code` returns the HTTP API status... | python | def reverse(self, lon, lat, types=None, limit=None):
"""Returns a Requests response object that contains a GeoJSON
collection of places near the given longitude and latitude.
`response.geojson()` returns the geocoding result as GeoJSON.
`response.status_code` returns the HTTP API status... | [
"def",
"reverse",
"(",
"self",
",",
"lon",
",",
"lat",
",",
"types",
"=",
"None",
",",
"limit",
"=",
"None",
")",
":",
"uri",
"=",
"URITemplate",
"(",
"self",
".",
"baseuri",
"+",
"'/{dataset}/{lon},{lat}.json'",
")",
".",
"expand",
"(",
"dataset",
"="... | Returns a Requests response object that contains a GeoJSON
collection of places near the given longitude and latitude.
`response.geojson()` returns the geocoding result as GeoJSON.
`response.status_code` returns the HTTP API status code.
See: https://www.mapbox.com/api-documentation/se... | [
"Returns",
"a",
"Requests",
"response",
"object",
"that",
"contains",
"a",
"GeoJSON",
"collection",
"of",
"places",
"near",
"the",
"given",
"longitude",
"and",
"latitude",
"."
] | 72d19dbcf2d254a6ea08129a726471fd21f13023 | https://github.com/mapbox/mapbox-sdk-py/blob/72d19dbcf2d254a6ea08129a726471fd21f13023/mapbox/services/geocoding.py#L81-L113 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.