user16593: I'm building a chess engine in Python. I'd like to find a board evaluation function that would be easy to put into my engine as a placeholder while I work on other aspects of the engine first.
I would love to use some iteration of StockFish's board evaluation. But there's no way I can see to do this without interacting with the normal StockFish engine in some way that has obscene overhead.
So, basically, I'm wondering if there are any evaluation functions someone else has already made that I can use. I would like for it to be easy to get working, not extremely slow, and not that bad at scoring boards.
Bonus points if possible:

The board representation it expects is a Python-Chess Board object (or uses similar bitboards)
You also know of a placeholder I can use for move ordering as well (would have the same criteria as the evaluation function)
It's actually written fully in Python, so JIT compilation may be possible (so NumPy works but not much else)


user30545: A simple board material evaluation using python-chess.
Code
import chess


PV = {
    'pawn': 100,
    'knight': 320,
    'bishop': 330,
    'rook': 500,
    'queen': 950
}

DRAW_VALUE = 0


def evaluation(board):
    if board.is_insufficient_material():
        return DRAW_VALUE

    wp = len(board.pieces(chess.PAWN, chess.WHITE))
    bp = len(board.pieces(chess.PAWN, chess.BLACK))

    wn = len(board.pieces(chess.KNIGHT, chess.WHITE))
    bn = len(board.pieces(chess.KNIGHT, chess.BLACK))

    wb = len(board.pieces(chess.BISHOP, chess.WHITE))
    bb = len(board.pieces(chess.BISHOP, chess.BLACK))

    wr = len(board.pieces(chess.ROOK, chess.WHITE))
    br = len(board.pieces(chess.ROOK, chess.BLACK))

    wq = len(board.pieces(chess.QUEEN, chess.WHITE))
    bq = len(board.pieces(chess.QUEEN, chess.BLACK))

    value = (
        PV['pawn'] * (wp - bp) +
        PV['knight'] * (wn - bn) +
        PV['bishop'] * (wb - bb) +
        PV['rook'] * (wr - br) +
        PV['queen'] * (wq - bq)
    )

    if board.turn == chess.WHITE:
        return value
    return -value


# Start
fen = 'rnbqkbnr/ppp1pppp/8/3P4/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2'
board = chess.Board(fen)
print(board)

value = evaluation(board)
print(f'board evaluation: {value}')

Output
r n b q k b n r
p p p . p p p p
. . . . . . . .
. . . P . . . .
. . . . . . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R
board evaluation: -100


16593: <p>I'm building a chess engine in Python. I'd like to find a board evaluation function that would be easy to put into my engine as a placeholder while I work on other aspects of the engine first.</p>
<p>I would love to use some iteration of StockFish's board evaluation. But there's no way I can see to do this without interacting with the normal StockFish engine in some way that has obscene overhead.</p>
<p>So, basically, I'm wondering if there are any evaluation functions someone else has already made that I can use. I would like for it to be easy to get working, not <em>extremely</em> slow, and not that bad at scoring boards.</p>
<p>Bonus points if possible:</p>
<ul>
<li>The board representation it expects is a Python-Chess <code>Board</code> object (or uses similar bitboards)</li>
<li>You also know of a placeholder I can use for move ordering as well (would have the same criteria as the evaluation function)</li>
<li>It's actually written fully in Python, so JIT compilation may be possible (so NumPy works but not much else)</li>
</ul>
 30545: <p>A simple board material evaluation using <a href="https://github.com/niklasf/python-chess" rel="nofollow noreferrer">python-chess</a>.</p>
<h4>Code</h4>
<pre><code>import chess


PV = {
    'pawn': 100,
    'knight': 320,
    'bishop': 330,
    'rook': 500,
    'queen': 950
}

DRAW_VALUE = 0


def evaluation(board):
    if board.is_insufficient_material():
        return DRAW_VALUE

    wp = len(board.pieces(chess.PAWN, chess.WHITE))
    bp = len(board.pieces(chess.PAWN, chess.BLACK))

    wn = len(board.pieces(chess.KNIGHT, chess.WHITE))
    bn = len(board.pieces(chess.KNIGHT, chess.BLACK))

    wb = len(board.pieces(chess.BISHOP, chess.WHITE))
    bb = len(board.pieces(chess.BISHOP, chess.BLACK))

    wr = len(board.pieces(chess.ROOK, chess.WHITE))
    br = len(board.pieces(chess.ROOK, chess.BLACK))

    wq = len(board.pieces(chess.QUEEN, chess.WHITE))
    bq = len(board.pieces(chess.QUEEN, chess.BLACK))

    value = (
        PV['pawn'] * (wp - bp) +
        PV['knight'] * (wn - bn) +
        PV['bishop'] * (wb - bb) +
        PV['rook'] * (wr - br) +
        PV['queen'] * (wq - bq)
    )

    if board.turn == chess.WHITE:
        return value
    return -value


# Start
fen = 'rnbqkbnr/ppp1pppp/8/3P4/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2'
board = chess.Board(fen)
print(board)

value = evaluation(board)
print(f'board evaluation: {value}')
</code></pre>
<h4>Output</h4>
<pre><code>r n b q k b n r
p p p . p p p p
. . . . . . . .
. . . P . . . .
. . . . . . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R
board evaluation: -100
</code></pre>
