pub fn best_move(&self, max_depth: usize) -> Result<(Move, isize), ChessError> {
        let mut rng = rand::thread_rng();
        let mut best_score = isize::min_value();
        let mut best_move = None;
        let moves = self.legal_moves()?;
        for mv in moves {
            let score;
            if max_depth == 0 {
                score = match self.make_move(&mv) {
                    Err(ChessError::Checkmate) => return Ok((mv, isize::max_value() - 1)),
                    Err(ChessError::Stalemate) => 0,
                    Err(e) => return Err(e),
                    Ok(new_board) => new_board.score(self.color_to_move),
                };
            } else {
                let tt = Arc::new(TranspositionTable::new(max_depth + 1));
                score = self
                    .make_move(&mv)?
                    .alpha_beta(max_depth, None, Some(tt.clone()));
            }
            if score > best_score || (score == best_score && rng.gen()) {
                best_move = Some(mv);
                best_score = score;
            }
        }
        Ok((best_move.unwrap(), best_score))
    }
// find the move with the weakest response - single threaded
find the move with the weakest response - single threaded
find the move with the weakest response - single threaded
pub fn best_move(&self, max_depth: usize) -> Result<(Move, isize), ChessError> {
        let mut rng = rand::thread_rng();
        let mut best_score = isize::min_value();
        let mut best_move = None;
        let moves = self.legal_moves()?;
        for mv in moves {
            let score;
            if max_depth == 0 {
                score = match self.make_move(&mv) {
                    Err(ChessError::Checkmate) => return Ok((mv, isize::max_value() - 1)),
                    Err(ChessError::Stalemate) => 0,
                    Err(e) => return Err(e),
                    Ok(new_board) => new_board.score(self.color_to_move),
                };
            } else {
                let tt = Arc::new(TranspositionTable::new(max_depth + 1));
                score = self
                    .make_move(&mv)?
                    .alpha_beta(max_depth, None, Some(tt.clone()));
            }
            if score > best_score || (score == best_score && rng.gen()) {
                best_move = Some(mv);
                best_score = score;
            }
        }
        Ok((best_move.unwrap(), best_score))
    }
pub fn best_move ( & self , max_depth : usize ) -> Result < ( Move , isize ) , ChessError > { let mut rng = rand :: thread_rng ( ) ; let mut best_score = isize :: min_value ( ) ; let mut best_move = None ; let moves = self . legal_moves ( ) ? ; for mv in moves { let score ; if max_depth == 0 { score = match self . make_move ( & mv ) { Err ( ChessError :: Checkmate ) => return Ok ( ( mv , isize :: max_value ( ) - 1 ) ) , Err ( ChessError :: Stalemate ) => 0 , Err ( e ) => return Err ( e ) , Ok ( new_board ) => new_board . score ( self . color_to_move ) , } ; } else { let tt = Arc :: new ( TranspositionTable :: new ( max_depth + 1 ) ) ; score = self . make_move ( & mv ) ? . alpha_beta ( max_depth , None , Some ( tt . clone ( ) ) ) ; } if score > best_score || ( score == best_score && rng . gen ( ) ) { best_move = Some ( mv ) ; best_score = score ; } } Ok ( ( best_move . unwrap ( ) , best_score ) ) }
find the move with the weakest response - single threaded
find the move with the weakest response - single threaded
&self
max_depth
usize