chessengine.utils#

chessengine.utils.get_bit_positions(bitboard: int) List[int]#

Returns a list of positions in the bitboard which have a 1. For e.g. - 1001100 returns [100, 1000, 1000000] (all numbers in binary)

Parameters:

bitboard (int) – A bitboard.

Return type:

List[int]

chessengine.utils.get_file(position: int, log: bool = False) int#

Returns the file of a position. position either has to be a power of 2, or log has to be True. Returns the file which is in range [1, 8]

Parameters:
  • position (int) – The position whose file is to be returned. See Representing Positions On The Board

  • log (bool) – If True, position will not be assumed to be a power of 2, but an index on the chess board.

Return type:

int

chessengine.utils.get_rank(position: int, log: bool = False) int#

Returns the rank of a position. position either has to be a power of 2, or log has to be True. Returns the rank which is in range [1, 8]

Parameters:
  • position (int) – The position whose rank is to be returned. See Representing Positions On The Board

  • log (bool) – If True, position will not be assumed to be a power of 2, but an index on the chess board.

Return type:

int

chessengine.utils.lsb_pos(board: int) int#

Clears all but the rightmost set bit on the board. i.e. - Returns 0000100 for 1010100

Parameters:

board (int) – A bitboard

Return type:

int

chessengine.utils.clear_lines(n: int) None#

Clears the last n lines printed so we can print there again

Parameters:

n (int) – The number of lines to clear

Return type:

None

chessengine.utils.change_turn(side_to_move: str) str#

Returns “black” if side_to_move is “white”, and “white” otherwise.

Parameters:

side_to_move (str) – The current side

Return type:

str

chessengine.utils.score_from_move(side: str, piece: str, start: int, end: int, end_piece: str, prev_score: int) int#

Takes the previous board evaluation, and a move to be made, and returns the new board evaluation.

Parameters:
  • side (str) – The side that is making the move. Should be one of “white” or “black”

  • piece (str) – The piece that is making the move. Should be one of [“kings”, “queens”, “rooks”, “bishops”, “knights”, “pawns”]

  • start (int) – The start position of the move. See Representing Positions On The Board

  • end (int) – The end position of the move. See Representing Positions On The Board

  • end_piece (str) – The piece that was captured (if any)

  • prev_score (int) – The previous score/evaluation of the board before the move was made

Returns:

The new score/evaluation of the board after the move is made

Return type:

int