pleco-rs / Pleco

A Rust-based re-write of the Stockfish Chess Engine
https://crates.io/crates/pleco
GNU General Public License v3.0
358 stars 38 forks source link

Move generator benchmarks #126

Open yukw777 opened 4 years ago

yukw777 commented 4 years ago

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 commented 5 months ago

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.