search

Function search 

Source
pub fn search<S: State>(
    tt: &Rc<RefCell<TranspositionTable>>,
    sef: &impl StaticEvaluator<S>,
    rg: &impl ResponseGenerator<State = S>,
    s0: &Rc<S>,
    max_depth: i32,
) -> Option<Rc<S>>
Expand description

A minimax search implementation using alpha-beta pruning and a transposition table.

This function performs a complete minimax search to find the best move for the current player. It uses alpha-beta pruning for efficiency and a transposition table to avoid redundant calculations.

§Arguments

  • tt - A transposition table for caching previously computed positions. Can be reused across multiple searches.
  • sef - The static evaluation function
  • rg - The response generator
  • s0 - The state to search from
  • max_depth - Maximum search depth in plies

§Returns

Some(Rc<S>) containing the best move found, or None if no valid moves exist

§Examples

use std::cell::RefCell;
use std::rc::Rc;
use crate::minimax::search;
use crate::transposition_table::TranspositionTable;

// Set up the search components
let transposition_table = Rc::new(RefCell::new(TranspositionTable::new(1000, 100)));
let evaluator = MyStaticEvaluator::new();
let move_generator = MyResponseGenerator::new();
let game_state = Rc::new(MyGameState::initial_position());

// Search to depth 6
match search(&transposition_table, &evaluator, &move_generator, &game_state, 6) {
    Some(best_move) => println!("Best move: {:?}", best_move),
    None => println!("No moves available"),
}

§Algorithm Details

The search uses:

  • Minimax: Alternating maximizing and minimizing players
  • Alpha-beta pruning: Early termination of unpromising branches
  • Transposition table: Caching of previously evaluated positions
  • Move ordering: Better moves searched first for more effective pruning