Search
Algorithm
Typhoon uses a derivative of alpha-beta called principal variation search (PVS). PVS prunes away whole branches of the minimax tree that don't influence the root position's value, but only the first move at a given node is searched with a full alpha-beta window — subsequent moves get a minimal window of beta = alpha + 1.
Ideally the best move is searched first and all subsequent moves fail low. With the minimal window, a great deal of work is saved. But if a subsequent move fails high, it must be re-searched with a larger window. With good move ordering, such re-searches are rare, and narrowing the window for subsequent moves saves work overall. More information about PVS and other search techniques can be found here. You can also read my (very cluttered) search.c for a working implementation.
Nullmove Pruning
A nullmove search is a forward pruning technique based on this idea: moving twice in a row in chess is a strong (though illegal) advantage. Imagine telling an opponent "my position is so strong you can move twice in a row — it won't help you." If they genuinely couldn't make progress against a "passed" turn, then their position must be terrible.
So, at non-PV plies, the engine tries a nullmove ("pass") before any real move, letting the opponent move twice in a row, then does a recursive search to a reduced depth. If that search fails high, the engine assumes "doing something is better than doing nothing" and fails high at the current node without doing further work — saving the cost of generating moves or searching subtrees.
The amount of reduction is called R, typically 1–3 plies. Like all good things, nullmove has dangers: in zugzwang positions it's actually an advantage to pass, violating the core assumption. Most engines disable nullmove late in the endgame where zugzwang is common, or "confirm" results with a verification search.
Typhoon uses adaptive nullmove, where R changes with the position under consideration — historically based on remaining search depth (per Ernst Heinz's Scalable Search in Computer Chess) and on the number of pieces left on the board; more recently, the regression-model-driven "situational safety" work described in Late Move Reductions & Pruning feeds into these decisions too. See the bottom of searchsup.c.
"Static" nullmove pruning
Search Extensions
In some positions a player's move is effectively forced, which are good candidates for search-line extension. Typhoon's extensions include: intelligent checks, nullmove threat detection, zugzwang positions, single legal reply to check, multi-piece checks, forced recaptures, "singular" reply to check, and productive passed pawn pushes in the endgame — using fractional ply extensions, so some extensions add less than a full ply.
Extension code is split in two: the part that considers the present
position lives at the top of Search in
search.c;
the part that considers the move being made lives in
ComputeMoveExtension in
searchsup.c.
Multithreaded Search
On a multi-processor machine, Typhoon uses a tree-splitting
algorithm, similar to PVSplit, to search in parallel — splitting
anywhere it believes is an "all" node (PV nodes, and "alpha" nodes
where the first N moves all fail low). You can see the split
conditions in the #ifdef MP blocks in
search.c;
the splitting code itself lives in
split.c.
Each searcher thread needs its own place to store positions, move stacks, and ply counters — a "searcher thread context" structure, defined in chess.h:
typedef struct _SEARCHER_THREAD_CONTEXT
{
POSITION sPosition;
MOVE_STACK sMoveStack;
POSITION_HISTORY sPositionHistory[MAX_PLY_PER_SEARCH];
MOVE mvKiller[MAX_PLY_PER_SEARCH][2];
ULONG uPly;
COUNTERS sCounters;
FLAG fImAHelper;
SPLIT_INFO *pSplitInfo;
ULONG uPositional;
}
SEARCHER_THREAD_CONTEXT;
I'd recommend either something like this or a class if you're implementing a parallel search — not TLS (Thread Local Storage), which is slower and non-portable.