jordanbray / chess

A rust library to manage chess move generation
https://jordanbray.github.io/chess/
MIT License
234 stars 54 forks source link

Material value #25

Closed FilipAndersson245 closed 4 years ago

FilipAndersson245 commented 4 years ago

Hello, im trying to wrap my head how i should accuire the material for Black, Respective White using a given board?

FilipAndersson245 commented 4 years ago

I implemented how i think it should look like. Don't know how efficient it is.


fn score_board(board: &Board, color: chess::Color) -> u16 {
    let b = board.color_combined(color).0;
    let mut sum = 0u16;

    for i in 0..64u64 {
        if b & (1 << i) != 0 {
            let a:Square = ALL_SQUARES[i as usize];
            sum += match board.piece_on(a).unwrap() {
                Piece::Pawn => {1},
                Piece::Knight => {3},
                Piece::Bishop => {3},
                Piece::Rook => {5},
                Piece::Queen => {9},
                Piece::King => {100},
            }

        }
    }
    sum
}