Skip to content

bitbully_core

Bitbully is a fast Connect-4 solver.

Classes:

Name Description
BitBullyCore
BoardCore
OpeningBookCore
Player

Attributes:

Name Type Description
N_COLUMNS int
N_ROWS int

N_COLUMNS module-attribute

N_COLUMNS: int

N_ROWS module-attribute

N_ROWS: int

__all__ module-attribute

__all__: list[str] = ['BitBullyCore', 'BoardCore', 'OpeningBookCore', 'Player', 'N_COLUMNS', 'N_ROWS']

BitBullyCore

Methods:

Name Description
getNodeCounter

Get the current node counter.

isBookLoaded

Check, if opening book is loaded

loadBook

Load an opening book from a file path.

mtdf

MTD(f) algorithm

negamax

Negamax search

nullWindow

Null-window search

resetBook

Unload the currently loaded opening book (if any).

resetNodeCounter

Reset the node counter

resetTranspositionTable

Reset the transposition table

scoreMove

Evaluate a single move.

scoreMoves

Evaluate all moves

getNodeCounter

getNodeCounter() -> int

Get the current node counter. Returns: int: The number of nodes visited since the last reset.

Source code in src/bitbully/bitbully_core.pyi
def getNodeCounter(self) -> int:
    """Get the current node counter.
    Returns:
        int: The number of nodes visited since the last reset.
    """

isBookLoaded

isBookLoaded() -> bool

Check, if opening book is loaded

Source code in src/bitbully/bitbully_core.pyi
def isBookLoaded(self) -> bool:
    """Check, if opening book is loaded"""

loadBook

loadBook(bookPath: PathLike[str] | str = ...) -> bool

Load an opening book from a file path.

Parameters:

Name Type Description Default

bookPath

PathLike[str] | str

Path to the opening book file. If empty or invalid, no book is loaded.

...

Returns:

Name Type Description
bool bool

True if the book was loaded successfully, False otherwise.

Source code in src/bitbully/bitbully_core.pyi
def loadBook(self, bookPath: os.PathLike[str] | str = ...) -> bool:
    """Load an opening book from a file path.

    Args:
        bookPath (os.PathLike[str] | str):
            Path to the opening book file. If empty or invalid, no book is loaded.

    Returns:
        bool: ``True`` if the book was loaded successfully, ``False`` otherwise.
    """

mtdf

mtdf(board: BoardCore, first_guess: int) -> int

MTD(f) algorithm Args: board (BoardCore): The current board state. first_guess (int): Initial guess for the score. Returns: int: The minimax score of the position.

Source code in src/bitbully/bitbully_core.pyi
def mtdf(self, board: BoardCore, first_guess: int) -> int:
    """MTD(f) algorithm
    Args:
        board (BoardCore): The current board state.
        first_guess (int): Initial guess for the score.
    Returns:
        int: The minimax score of the position.
    """

negamax

negamax(board: BoardCore, alpha: int, beta: int, depth: int) -> int

Negamax search

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

nullWindow

nullWindow(board: BoardCore) -> int

Null-window search

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

resetBook

resetBook() -> None

Unload the currently loaded opening book (if any).

Source code in src/bitbully/bitbully_core.pyi
def resetBook(self) -> None:
    """Unload the currently loaded opening book (if any)."""

resetNodeCounter

resetNodeCounter() -> None

Reset the node counter

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

resetTranspositionTable

resetTranspositionTable() -> None

Reset the transposition table

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

scoreMove

Evaluate a single move.

Parameters:

Name Type Description Default

board

BoardCore

The current board state.

required

column

int

Column index (0–6) of the move to evaluate.

required

first_guess

int

Initial guess for the score.

required

Returns:

Name Type Description
int int

The evaluation score of the move.

Source code in src/bitbully/bitbully_core.pyi
def scoreMove(self, board: BoardCore, column: int, first_guess: int) -> int:
    """Evaluate a single move.

    Args:
        board (BoardCore): The current board state.
        column (int): Column index (0–6) of the move to evaluate.
        first_guess (int): Initial guess for the score.

    Returns:
        int: The evaluation score of the move.
    """

scoreMoves

scoreMoves(board: BoardCore) -> list[int]

Evaluate all moves

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

BoardCore

Methods:

Name Description
__eq__

Check if two boards are equal

__ne__

Check if two boards are not equal

__repr__

Return a developer-oriented string representation of the board.

__str__

Return a human-readable string representation of the board.

allPositions

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

copy

Create a deep copy of the board.

countTokens

Get the number of Tokens on the board

doubleThreat

Find double threats

findThreats

Find threats on the board

generateNonLosingMoves

Generate non-losing moves

hasWin

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.

isLegalMove

Check if a move is legal

isValid

Check, if a board is a valid one.

legalMoves

Generate possible moves as a vector of column indices

legalMovesMask

Generate possible moves as bitboard

mirror

Get the mirrored board (mirror around center column)

movesLeft

Get the number of moves left

playMoveOnCopy

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

popCountBoard

Popcount of all tokens bitboard (number of occupied cells).

randomBoard

Create a random board with n tokens and returns the board and the move sequence.

toArray

Convert the board to a 2D array representation

toHuffman

Encode position into a huffman-code compressed sequence.

toString

Return a string representation of the board

uid

Get the unique identifier for the board

Attributes:

Name Type Description
__hash__ None

__hash__ class-attribute

__hash__: None = None

__eq__

__eq__(arg0: BoardCore) -> bool

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__

__ne__(arg0: BoardCore) -> bool

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"""

__repr__

__repr__() -> str

Return a developer-oriented string representation of the board.

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

__str__

__str__() -> str

Return a human-readable string representation of the board.

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

allPositions

allPositions(upToNPly: int, exactlyN: bool) -> list[BoardCore]

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

copy() -> BoardCore

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

countTokens() -> int

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

doubleThreat(moves: int) -> int

Find double threats

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

findThreats

findThreats(moves: int) -> int

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

generateNonLosingMoves() -> int

Generate non-losing moves

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

hasWin

hasWin() -> bool

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() -> int

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

isLegalMove(column: int) -> bool

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 staticmethod

isValid(board: list[list[int]]) -> bool

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

legalMoves(nonLosing: bool, orderMoves: bool) -> list[int]

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

legalMovesMask() -> int

Generate possible moves as bitboard

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

mirror

mirror() -> BoardCore

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

movesLeft() -> int

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

playMoveOnCopy(mv: int) -> BoardCore

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"""

popCountBoard

popCountBoard() -> int

Popcount of all tokens bitboard (number of occupied cells).

Source code in src/bitbully/bitbully_core.pyi
def popCountBoard(self) -> int:
    """Popcount of all tokens bitboard (number of occupied cells)."""

randomBoard staticmethod

randomBoard(nPly: int, forbidDirectWin: bool) -> tuple[BoardCore, list[int]]

Create a random board with n tokens and returns the board and the move sequence.

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 and returns the board and the move sequence."""

toArray

toArray() -> list[list[int]]

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

toHuffman() -> int

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

toString() -> str

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

uid() -> int

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

Methods:

Name Description
convertValue

Convert a value to the internal scoring system.

getBoardValue

Get the value of a given board.

getBook

Return the raw book table.

getBookSize

Get the size of the book.

getEntry

Get an entry from the book by index.

getNPly

Get the ply depth of the book.

init

Reinitialize the OpeningBook with new settings.

isInBook

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

readBook

Read a book from a file.

convertValue

convertValue(value: int, board: BoardCore) -> int

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

getBoardValue(board: BoardCore) -> int

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

getBook() -> list[tuple[int, int]]

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

getBookSize() -> int

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

getEntry(entryIdx: int) -> tuple[int, int]

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

getNPly() -> int

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

init(bookPath: PathLike, is_8ply: bool, with_distances: bool) -> None

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

isInBook(board: BoardCore) -> bool

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 staticmethod

readBook(filename: PathLike, with_distances: bool = True, is_8ply: bool = False) -> list[tuple[int, int]]

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."""

Player


              flowchart TD
              src.bitbully.bitbully_core.Player[Player]

              

              click src.bitbully.bitbully_core.Player href "" "src.bitbully.bitbully_core.Player"
            

Attributes:

Name Type Description
P_EMPTY int
P_RED int
P_YELLOW int

P_EMPTY instance-attribute

P_EMPTY: int

P_RED instance-attribute

P_RED: int

P_YELLOW instance-attribute

P_YELLOW: int