pensquid / yobmef

Weird toy chess engine written *very much from scratch* in Rust.
14 stars 1 forks source link

Refactor eval::get_score #3

Open UlisseMini opened 3 years ago

UlisseMini commented 3 years ago

Currently, eval::get_score takes in a Board and num_legal_moves. This is ugly and the code is not readable. This could be fixed by moving num_legal_moves into the Board struct and have it be cached, or perhaps something else.

// this is unreadable garbage
pub fn get_score(board: &Board, legal_move_count: usize) -> i16 {
    if legal_move_count == 0 && board.in_check() {
        MATE * board.side_to_move.other().polarize()
    } else if legal_move_count > 0 {
        get_score_ongoing(board)
    } else {
        0
    }
}
UlisseMini commented 3 years ago

The function is also used incorrectly in sort_by_promise. It uses the current legal moves which are nonzero, so it will never account for checkmate.

Unfortunately, the speed decrease from running movegen on all legal moves is unacceptable. So we'll need to come up with a faster solution.

UlisseMini commented 3 years ago

I've mostly fixed it by passing game_over: bool instead. Still need to fix the issue with mates. (computing if there is a checkmate should be a quick operation with bitboards.)