Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move generator benchmarks #126

Open
yukw777 opened this issue Apr 12, 2020 · 1 comment
Open

Move generator benchmarks #126

yukw777 opened this issue Apr 12, 2020 · 1 comment

Comments

@yukw777
Copy link

yukw777 commented Apr 12, 2020

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!

@victoralan2
Copy link

victoralan2 commented Jan 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants