Trait alcibiades::DeepeningSearch
[−]
[src]
pub trait DeepeningSearch: SetOption { type Ttable: Ttable; type SearchNode: SearchNode; type ReportData; fn new(tt: Arc<Self::Ttable>) -> Self; fn start_search(&mut self, params: SearchParams<Self::SearchNode>); fn wait_report(&self, timeout_after: Duration); fn try_recv_report(
&mut self
) -> Result<SearchReport<Self::ReportData>, TryRecvError>; fn send_message(&mut self, msg: &str); }
A trait for executing iterative deepening searches.
Chess programs must rely on some type of search in order to play reasonably. Searching involves looking ahead at different move sequences and evaluating the positions after making the moves. Normally, this is done by traversing and min-maxing a tree-like data-structure by some algorithm.
There are two types of searches that should be distinguished:
Depth-first search (the
Search
trait).Starts at the root position and explores as far as possible along each branch before backtracking.
Iterative deepening search (the
DeepeningSearch
trait).A depth-first search is executed with a depth of one ply, then the depth is incremented and another search is executed. This process is repeated until the search is terminated or the requested search depth is reached. In case of a terminated search, the engine can always fall back to the move selected in the last iteration of the search.
To implement your own search algorithm, you must define a type
that implements either Search
or DeepeningSearch
trait.
Note: You can use stock::Deepening
to turn a depth-first
search into an iterative deepening search.
Associated Types
type Ttable: Ttable
The type of transposition table that the implementation works with.
type SearchNode: SearchNode
The type of search node that the implementation works with.
type ReportData
The type of auxiliary data that search progress reports carry.
Required Methods
fn new(tt: Arc<Self::Ttable>) -> Self
Creates a new instance.
tt
supplies a transposition table instance for the search
algorithm to work with.
fn start_search(&mut self, params: SearchParams<Self::SearchNode>)
Starts a new search.
This method must not block the current thread. After calling
start_search
, wait_report
and try_recv_report
will be
called periodically until the returned report indicates that
the search is done. A new search will not be started until the
previous search is done.
Important note: The executing search must generate periodic reports, informing about its current progress. Also, the executing search must continuously update the transposition table so that, at each moment, it contains the results of the work done so far.
fn wait_report(&self, timeout_after: Duration)
Waits until a search progress report is available, timing out after a specified duration or earlier.
fn try_recv_report(
&mut self
) -> Result<SearchReport<Self::ReportData>, TryRecvError>
&mut self
) -> Result<SearchReport<Self::ReportData>, TryRecvError>
Attempts to return a search progress report without blocking.
fn send_message(&mut self, msg: &str)
Sends a message to the currently executing search.
The message format is not specified, but the implementation must meet the following requirements:
Unrecognized messages are ignored.
The message
"TERMINATE"
is recognized as a request to terminate the current search.Receiving two or more termination requests for the same search does not cause any problems.
Note: Normally, after sending one or more "TERMINATE"
messages, wait_report
and try_recv_report
methods will
continue to be called periodically until the returned report
indicates that the search is done.