evaluate method

int evaluate(
  1. Colour player
)

Returns a naive material evaluation of the current position, from the perspective of player. Return value is in centipawns. For example, if white has captured a rook from black with no compensation, this will return +500.

Implementation

int evaluate(Colour player) {
  int eval = 0;
  for (int i = 0; i < size.numIndices; i++) {
    if (!size.onBoard(i)) continue;
    Square square = board[i];
    if (square.isNotEmpty) {
      Colour colour = square.colour;
      int type = square.type;
      int value = variant.pieces[type].value;
      if (colour == player) {
        eval += value;
      } else {
        eval -= value;
      }
    }
  }
  if (variant.handsEnabled) {
    eval += state.hands![player].fold<int>(
      0,
      (p, e) => p + variant.pieces[e].value + Bishop.handBonusValue,
    );
    eval -= state.hands![player.opponent].fold<int>(
      0,
      (p, e) => p + variant.pieces[e].value + Bishop.handBonusValue,
    );
  }
  return eval;
}