Pleco icon indicating copy to clipboard operation
Pleco copied to clipboard

Move generator benchmarks

Open yukw777 opened this issue 4 years ago • 1 comments

Hi! I'm planning on writing a chess engine in rust to learn the language better and I'm looking for a move generator to use. I'm currently in between Pleco and chess. Do you have any benchmarks on which one is a faster move generator? Thanks in advance!

yukw777 avatar Apr 12 '20 02:04 yukw777

A bit late but. I can tell you that the chess library is way faster.

You can use this code to test it yourself: Chess:

fn main() {
	let mut board = Board::default();
	let start = Instant::now();
	let nodes = perft(&board, 6);
	let elapsed = start.elapsed();
	println!("Found {} nodes in {:?}", nodes, elapsed);
	println!("That is about {} n/s", nodes as f64 / elapsed.as_secs_f64())
}
pub fn perft(board: &Board, depth: u32) -> u32{
	if depth == 1 {
		return MoveGen::new_legal(board).len() as u32;
	}
	let mut nodes_searched = 0;
	for m in MoveGen::new_legal(board) {
		let new_board = board.make_move_new(m);
		nodes_searched += perft(&new_board, depth-1);
	}
	nodes_searched
}

pleco:

fn main() {
	let mut board = Board::start_pos();
	let start = Instant::now();
	let nodes = perft(&mut board, 6);
	let elapsed = start.elapsed();
	println!("Found {} nodes in {:?}", nodes, elapsed);
	println!("That is about {} n/s", nodes as f64 / elapsed.as_secs_f64())
}
pub fn perft(board: &mut Board, depth: u32) -> u32{
	if depth == 1 {
		return board.generate_moves().len() as u32;
	}
	let mut nodes_searched = 0;
	for m in board.generate_moves() {
		board.apply_move(m);
		nodes_searched += perft(board, depth-1);
		board.undo_move();
	}
	nodes_searched
}

This gives on my machine about 88M nodes/second on pleco and about 144M nodes/second on chess.

victoralan2 avatar Jan 03 '24 17:01 victoralan2