Yeah,I might have made a mistake somewhere, but honestly I believe that my minmax funcs are correct. Just for the sake of completeness, I'll past them [as-is] below:
constexpr int16_t MAX_EVAL = 25000;
constexpr int16_t MIN_EVAL = -MAX_EVAL;
///Minmax evaluation with alpha beta pruning
int16_t minmax_ab(GPosition& position, uint8_t plies, int16_t alpha, int16_t beta, bool isMaximizer)
{
if (plies == 0) {
return get_position_value(position);
}
invert_color(GEval::EvalTurn);
std::vector<PMove> validMoves = get_all_valid_moves(position);
Pid capturedID;
if (isMaximizer) {
for (auto move : validMoves) {
capturedID = Pid::NO_PIECE;
perform_move(position, move, capturedID);
alpha = std::max(alpha, minmax_ab(position, plies - 1, alpha, beta, false) );
undo_move(position, move, capturedID);
if (alpha >= beta) {
return beta;
}
}
return alpha;
}
else {
for (auto move : validMoves) {
capturedID = Pid::NO_PIECE;
perform_move(position, move, capturedID);
beta = std::min(beta, minmax_ab(position, plies - 1, alpha, beta, true) );
undo_move(position, move, capturedID);
if (beta <= alpha) {
return alpha;
}
}
return beta;
}
}
PMove minmax_root(uint8_t plies)
{
auto position = Board;
std::vector<PMove> validMoves = get_all_valid_moves(position);
/// assert((!validMoves.empty() && "no valid moves in minmax_root"));
PMove bestmove = validMoves.back();
Pid capturedID;
perform_move(position, bestmove, capturedID);
int16_t besteval = get_position_value(position);
undo_move(position, bestmove, capturedID);
for (auto move : validMoves) {
capturedID = Pid::NO_PIECE;
perform_move(position, bestmove, capturedID);
int16_t eval = minmax_ab(position, plies - 1, MIN_EVAL, MAX_EVAL, false);
undo_move(position, bestmove, capturedID);
if (eval > besteval) {
besteval = eval;
bestmove = move;
}
}
return bestmove;
}