Skip to content

bitbully_core

Bitbully is a fast Connect-4 solver.

BitBullyCore

Source code in src/bitbully/bitbully_core.pyi
class BitBullyCore:
    @typing.overload
    def __init__(self) -> None: ...

    @typing.overload
    def __init__(self, openingBookPath: os.PathLike) -> None: ...

    def getNodeCounter(self) -> int:
        """Get the current node counter"""

    @typing.overload
    def isBookLoaded(self) -> bool:
        """Check, if opening book is loaded"""

    @typing.overload
    def isBookLoaded(self) -> bool:
        """Check, if opening book is loaded"""

    def mtdf(self, board: ..., first_guess: int) -> int:
        """MTD(f) algorithm"""

    def negamax(self, board: ..., alpha: int, beta: int, depth: int) -> int:
        """Negamax search"""

    def nullWindow(self, board: ...) -> int:
        """Null-window search"""

    def resetNodeCounter(self) -> None:
        """Reset the node counter"""

    def resetTranspositionTable(self) -> None:
        """Reset the transposition table"""

    def scoreMoves(self, board: ...) -> list[int]:
        """Evaluate all moves"""

getNodeCounter()

Get the current node counter

Source code in src/bitbully/bitbully_core.pyi
def getNodeCounter(self) -> int:
    """Get the current node counter"""

mtdf(board, first_guess)

MTD(f) algorithm

Source code in src/bitbully/bitbully_core.pyi
def mtdf(self, board: ..., first_guess: int) -> int:
    """MTD(f) algorithm"""

negamax(board, alpha, beta, depth)

Negamax search

Source code in src/bitbully/bitbully_core.pyi
def negamax(self, board: ..., alpha: int, beta: int, depth: int) -> int:
    """Negamax search"""

nullWindow(board)

Null-window search

Source code in src/bitbully/bitbully_core.pyi
def nullWindow(self, board: ...) -> int:
    """Null-window search"""

resetNodeCounter()

Reset the node counter

Source code in src/bitbully/bitbully_core.pyi
def resetNodeCounter(self) -> None:
    """Reset the node counter"""

resetTranspositionTable()

Reset the transposition table

Source code in src/bitbully/bitbully_core.pyi
def resetTranspositionTable(self) -> None:
    """Reset the transposition table"""

scoreMoves(board)

Evaluate all moves

Source code in src/bitbully/bitbully_core.pyi
def scoreMoves(self, board: ...) -> list[int]:
    """Evaluate all moves"""

BoardCore

Source code in src/bitbully/bitbully_core.pyi
class BoardCore:
    __hash__: typing.ClassVar[None] = None

    @staticmethod
    def isValid(
            board: typing.Annotated[
                list[typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(6)]],
                pybind11_stubgen.typing_ext.FixedSize(7),
            ],
    ) -> bool:
        """Check, if a board is a valid one."""

    @staticmethod
    def randomBoard(nPly: int, forbidDirectWin: bool) -> tuple[BoardCore, list[int]]:
        """Create a random board with n tokens."""

    def __eq__(self, arg0: BoardCore) -> bool:
        """Check if two boards are equal"""

    @typing.overload
    def __init__(self) -> None: ...

    @typing.overload
    def __init__(self, arg0: BoardCore) -> None: ...

    def __ne__(self, arg0: BoardCore) -> bool:
        """Check if two boards are not equal"""

    def allPositions(self, upToNPly: int, exactlyN: bool) -> list[BoardCore]:
        """Generate all positions that can be reached from the current board with n tokens."""

    @typing.overload
    def canWin(self, column: int) -> bool:
        """Check, if current player can win by moving into column."""

    @typing.overload
    def canWin(self) -> bool:
        """Check, if current player can win with the next move."""

    def copy(self) -> BoardCore:
        """Create a deep copy of the board."""

    def countTokens(self) -> int:
        """Get the number of Tokens on the board"""

    def doubleThreat(self, moves: int) -> int:
        """Find double threats"""

    def findThreats(self, moves: int) -> int:
        """Find threats on the board"""

    def legalMovesMask(self) -> int:
        """Generate possible moves as bitboard"""

    def generateNonLosingMoves(self) -> int:
        """Generate non-losing moves"""

    def legalMoves(self, nonLosing:bool, orderMoves:bool) -> list[int]:
        """Generate possible moves as a vector of column indices"""

    def hasWin(self) -> bool:
        """Check, if the player who performed the last move has a winning position (4 in a row)."""

    def hash(self) -> int:
        """Hash the current position and return hash value."""

    def isLegalMove(self, column: int) -> bool:
        """Check if a move is legal"""

    def mirror(self) -> BoardCore:
        """Get the mirrored board (mirror around center column)"""

    def movesLeft(self) -> int:
        """Get the number of moves left"""

    @typing.overload
    def play(self, column: int) -> bool:
        """Play a move by column index"""

    @typing.overload
    def play(self, moveSequence: list[int]) -> bool:
        """
        Play a sequence of moves by column index
        """

    @typing.overload
    def play(self, moveSequence: str) -> bool:
        """
        Play a sequence of moves by column index
        """

    def playMoveOnCopy(self, mv: int) -> BoardCore:
        """Play a move on a copy of the board and return the new board"""

    @typing.overload
    def setBoard(self, moveSequence: list[int]) -> bool:
        """Set the board using a 2D array"""

    @typing.overload
    def setBoard(
            self,
            moveSequence: typing.Annotated[
                list[typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(6)]],
                pybind11_stubgen.typing_ext.FixedSize(7),
            ],
    ) -> bool:
        """Set the board using a 2D array"""

    @typing.overload
    def setBoard(
            self,
            moveSequence: typing.Annotated[
                list[typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(7)]],
                pybind11_stubgen.typing_ext.FixedSize(6),
            ],
    ) -> bool:
        """Set the board using a 2D array"""

    @typing.overload
    def setBoard(self, moveSequence: str) -> bool:
        """Set the board using a sequence as string"""

    def sortMoves(self, moves: int) -> ...:
        """Sort moves based on priority"""

    def toArray(
            self,
    ) -> typing.Annotated[
        list[typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(6)]],
        pybind11_stubgen.typing_ext.FixedSize(7),
    ]:
        """Convert the board to a 2D array representation"""

    def toHuffman(self) -> int:
        """Encode position into a huffman-code compressed sequence."""

    def toString(self) -> str:
        """Return a string representation of the board"""

    def uid(self) -> int:
        """Get the unique identifier for the board"""

__eq__(arg0)

Check if two boards are equal

Source code in src/bitbully/bitbully_core.pyi
def __eq__(self, arg0: BoardCore) -> bool:
    """Check if two boards are equal"""

__ne__(arg0)

Check if two boards are not equal

Source code in src/bitbully/bitbully_core.pyi
def __ne__(self, arg0: BoardCore) -> bool:
    """Check if two boards are not equal"""

allPositions(upToNPly, exactlyN)

Generate all positions that can be reached from the current board with n tokens.

Source code in src/bitbully/bitbully_core.pyi
def allPositions(self, upToNPly: int, exactlyN: bool) -> list[BoardCore]:
    """Generate all positions that can be reached from the current board with n tokens."""

copy()

Create a deep copy of the board.

Source code in src/bitbully/bitbully_core.pyi
def copy(self) -> BoardCore:
    """Create a deep copy of the board."""

countTokens()

Get the number of Tokens on the board

Source code in src/bitbully/bitbully_core.pyi
def countTokens(self) -> int:
    """Get the number of Tokens on the board"""

doubleThreat(moves)

Find double threats

Source code in src/bitbully/bitbully_core.pyi
def doubleThreat(self, moves: int) -> int:
    """Find double threats"""

findThreats(moves)

Find threats on the board

Source code in src/bitbully/bitbully_core.pyi
def findThreats(self, moves: int) -> int:
    """Find threats on the board"""

generateNonLosingMoves()

Generate non-losing moves

Source code in src/bitbully/bitbully_core.pyi
def generateNonLosingMoves(self) -> int:
    """Generate non-losing moves"""

hasWin()

Check, if the player who performed the last move has a winning position (4 in a row).

Source code in src/bitbully/bitbully_core.pyi
def hasWin(self) -> bool:
    """Check, if the player who performed the last move has a winning position (4 in a row)."""

hash()

Hash the current position and return hash value.

Source code in src/bitbully/bitbully_core.pyi
def hash(self) -> int:
    """Hash the current position and return hash value."""

isLegalMove(column)

Check if a move is legal

Source code in src/bitbully/bitbully_core.pyi
def isLegalMove(self, column: int) -> bool:
    """Check if a move is legal"""

isValid(board) staticmethod

Check, if a board is a valid one.

Source code in src/bitbully/bitbully_core.pyi
@staticmethod
def isValid(
        board: typing.Annotated[
            list[typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(6)]],
            pybind11_stubgen.typing_ext.FixedSize(7),
        ],
) -> bool:
    """Check, if a board is a valid one."""

legalMoves(nonLosing, orderMoves)

Generate possible moves as a vector of column indices

Source code in src/bitbully/bitbully_core.pyi
def legalMoves(self, nonLosing:bool, orderMoves:bool) -> list[int]:
    """Generate possible moves as a vector of column indices"""

legalMovesMask()

Generate possible moves as bitboard

Source code in src/bitbully/bitbully_core.pyi
def legalMovesMask(self) -> int:
    """Generate possible moves as bitboard"""

mirror()

Get the mirrored board (mirror around center column)

Source code in src/bitbully/bitbully_core.pyi
def mirror(self) -> BoardCore:
    """Get the mirrored board (mirror around center column)"""

movesLeft()

Get the number of moves left

Source code in src/bitbully/bitbully_core.pyi
def movesLeft(self) -> int:
    """Get the number of moves left"""

playMoveOnCopy(mv)

Play a move on a copy of the board and return the new board

Source code in src/bitbully/bitbully_core.pyi
def playMoveOnCopy(self, mv: int) -> BoardCore:
    """Play a move on a copy of the board and return the new board"""

randomBoard(nPly, forbidDirectWin) staticmethod

Create a random board with n tokens.

Source code in src/bitbully/bitbully_core.pyi
@staticmethod
def randomBoard(nPly: int, forbidDirectWin: bool) -> tuple[BoardCore, list[int]]:
    """Create a random board with n tokens."""

sortMoves(moves)

Sort moves based on priority

Source code in src/bitbully/bitbully_core.pyi
def sortMoves(self, moves: int) -> ...:
    """Sort moves based on priority"""

toArray()

Convert the board to a 2D array representation

Source code in src/bitbully/bitbully_core.pyi
def toArray(
        self,
) -> typing.Annotated[
    list[typing.Annotated[list[int], pybind11_stubgen.typing_ext.FixedSize(6)]],
    pybind11_stubgen.typing_ext.FixedSize(7),
]:
    """Convert the board to a 2D array representation"""

toHuffman()

Encode position into a huffman-code compressed sequence.

Source code in src/bitbully/bitbully_core.pyi
def toHuffman(self) -> int:
    """Encode position into a huffman-code compressed sequence."""

toString()

Return a string representation of the board

Source code in src/bitbully/bitbully_core.pyi
def toString(self) -> str:
    """Return a string representation of the board"""

uid()

Get the unique identifier for the board

Source code in src/bitbully/bitbully_core.pyi
def uid(self) -> int:
    """Get the unique identifier for the board"""

OpeningBookCore

Source code in src/bitbully/bitbully_core.pyi
class OpeningBookCore:
    @staticmethod
    def readBook(filename: os.PathLike, with_distances: bool = True, is_8ply: bool = False) -> list[tuple[int, int]]:
        """Read a book from a file."""

    @typing.overload
    def __init__(self, bookPath: os.PathLike, is_8ply: bool, with_distances: bool) -> None:
        """Initialize an OpeningBook with explicit settings."""

    @typing.overload
    def __init__(self, bookPath: os.PathLike) -> None:
        """Initialize an OpeningBook by inferring database type from file size."""

    def convertValue(self, value: int, board: BoardCore) -> int:
        """Convert a value to the internal scoring system."""

    def getBoardValue(self, board: BoardCore) -> int:
        """Get the value of a given board."""

    def getBook(self) -> list[tuple[int, int]]:
        """Return the raw book table."""

    def getBookSize(self) -> int:
        """Get the size of the book."""

    def getEntry(self, entryIdx: int) -> tuple[int, int]:
        """Get an entry from the book by index."""

    def getNPly(self) -> int:
        """Get the ply depth of the book."""

    def init(self, bookPath: os.PathLike, is_8ply: bool, with_distances: bool) -> None:
        """Reinitialize the OpeningBook with new settings."""

    def isInBook(self, board: BoardCore) -> bool:
        """Check, if the given board is in the opening book. Note, that usually boards are only present in one mirrored variant."""

convertValue(value, board)

Convert a value to the internal scoring system.

Source code in src/bitbully/bitbully_core.pyi
def convertValue(self, value: int, board: BoardCore) -> int:
    """Convert a value to the internal scoring system."""

getBoardValue(board)

Get the value of a given board.

Source code in src/bitbully/bitbully_core.pyi
def getBoardValue(self, board: BoardCore) -> int:
    """Get the value of a given board."""

getBook()

Return the raw book table.

Source code in src/bitbully/bitbully_core.pyi
def getBook(self) -> list[tuple[int, int]]:
    """Return the raw book table."""

getBookSize()

Get the size of the book.

Source code in src/bitbully/bitbully_core.pyi
def getBookSize(self) -> int:
    """Get the size of the book."""

getEntry(entryIdx)

Get an entry from the book by index.

Source code in src/bitbully/bitbully_core.pyi
def getEntry(self, entryIdx: int) -> tuple[int, int]:
    """Get an entry from the book by index."""

getNPly()

Get the ply depth of the book.

Source code in src/bitbully/bitbully_core.pyi
def getNPly(self) -> int:
    """Get the ply depth of the book."""

init(bookPath, is_8ply, with_distances)

Reinitialize the OpeningBook with new settings.

Source code in src/bitbully/bitbully_core.pyi
def init(self, bookPath: os.PathLike, is_8ply: bool, with_distances: bool) -> None:
    """Reinitialize the OpeningBook with new settings."""

isInBook(board)

Check, if the given board is in the opening book. Note, that usually boards are only present in one mirrored variant.

Source code in src/bitbully/bitbully_core.pyi
def isInBook(self, board: BoardCore) -> bool:
    """Check, if the given board is in the opening book. Note, that usually boards are only present in one mirrored variant."""

readBook(filename, with_distances=True, is_8ply=False) staticmethod

Read a book from a file.

Source code in src/bitbully/bitbully_core.pyi
@staticmethod
def readBook(filename: os.PathLike, with_distances: bool = True, is_8ply: bool = False) -> list[tuple[int, int]]:
    """Read a book from a file."""