A slightly better chess player than its creator.
function negaMax(chessboard, depth) {
if (depth === 0) {
return evaluate(chessboard);
}
let max = -Infinity;
let moves = findLegalMoves(chessboard);
for (move in moves) {
makeMove(chessboard, move);
let score = -negaMax(chessboard, depth - 1);
undoMove(chessboard, move);
if (score > max) {
max = score;
}
}
return max;
}
use xadrez::prelude::*;
fn main() {
let mut board = Chessboard::default();
let evaluation = board.evaluate();
let best_move = board.search(SearchLimits::from_depth(2)).0;
board.make_move(best_move);
let e7e5 = Move::from_str("e7e5").unwrap();
board.make_move(e7e5);
let pieces = board.pieces();
println!("{board}: {}", board.game_state());
}