XADREZ

A slightly better chess player than its creator.

What am I?

I am a chess engine. That means that I can find all legal moves on a chessboard, evaluate how good positions on the board are, and find what I think are the best moves. You can play against me here in the browser, or have me help you with a game by seeing how I think. You can even use me in your own projects!

How do I work?

I find the best moves by using an algorithm called negamax alpha-beta search. By making every possible move from the current position, I can evaluate all the positions one move into the future, and find the best one. Then, I make every possible move after the first one, and find the best possible position two moves into the future. I continue to do this, looking as far into the future as I can, and find out what move I need to make to get to the best position for me. Sounds complicated? The code below is all the code for it!
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;
}

How can you use me?

To use me yourself, go to my GitHub repository, download me, and add me to your project. You can see an example on how to use me in code below
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());
}