Turn from: Minimax search method, negative value maximum algorithm and Alpha-beta search method
1. Minimal Maximum search method
General application in game search, such as: Go, Gobang, chess and so on. There are three possible outcomes: victory, failure, and draw. Violent search, if you want to search through violence, the final result, the depth of the search tree is too large, the machine can not be satisfied, is generally defined as a depth of search, in this depth of depth first search.
Suppose: A and B, the turn a moves, then we will iterate through each of the possible moves methods of a, and then for each moves method of the preceding a, traverse each of the moves method of B, and then go through each moves method of a, and so on, until the result is determined or reached the limit of the search depth. When the search depth limit is reached, at this time can not determine how the outcome, is generally based on the current situation of the form, given a score, the method of calculating the score is called the evaluation function, different game evaluation functions vary greatly, need a good design.
In the search tree, the node representing a moves is the maximum node, which indicates that the node of B moves is a very small node.
Such as: A is a maximum node, B is a very small node. A is called a maximal node, because a will choose one of the most moves method of the situation scoring, said B is a very small node, because B will choose a moves method with the smallest situation score, where the situation score is relative to a. This is done by assuming that both A and B will choose the best moves method available within a limited search depth.
Figure-Maximal node (A) and Minimum Node (B) Graph-Minimax Search
The pseudo code is as follows (from Wikipedia):
function minimax (node, depth)//Specify the current node and search depth
//If you can get a definite result or a depth of zero, use the evaluation function to return the score of the situation
IfNodeIsA terminal node or depth=0
ReturnThe heuristic value of node
//If the turn of the opponent moves, is a minimum node, choose a score of the least-way
IfThe AdversaryIsTo play at node
Letα:=+∞
ForeachChild of Node
Alpha:=Min (α, minimax (child, depth-1))
//If it is our turn to moves, is the maximal node, choose one of the best scoring methods
else {we are to play at node}
let Α := -∞
foreach child of node
α := max (Α, minimax (Child , depth-1 return α;
A more specific algorithm:
the evaluation of the int minmax (int depth) { // function is evaluated in terms of white. If(Sidetomove ()==White) {//White is the "biggest" person
ReturnMax (depth);
}Else{//Black is the "smallest" person
ReturnMin (depth);
}
}
IntMax (IntDepth) {
IntBest=-INFINITY;
If(Depth<=0) {
ReturnEvaluate ();
}
Generatelegalmoves ();
While(Movesleft ()) {
Makenextmove ();
Val=Min (Depth-1);
Unmakemove ();
If(Val>Best) {
Best=Val
}
}
ReturnBest
}
IntMin (IntDepth) {
IntBest=INFINITY;//Note that this is different from the "Max" algorithm
If(Depth<=0) {
ReturnEvaluate ();
}
Generatelegalmoves ();
While (Movesleft ()) {
Makenextmove ();
Val = max (Depth - 1 Unmakemove (); &NBSP
if (val < best) { // Note this differs from the "Max" algorithm
Best =&NBSP;VAL;&NBSP;
}
}
return&NBSP;BEST;&NBSP;
}
The above code is the same as the previous pseudo-code, but the maximum algorithm and the minimum algorithm are divided into two functions.
2. Negative value maximum algorithm
The previous two sections of code are two parts of the code to deal with the maximum node and the minimum node two cases, in fact, you can only use a portion of the code, both the maximum node processing and processing pole points.
The difference is that the previous evaluation function is for white, that is, the specified party to give the score, the evaluation function here is based on the current search node to give a score. Each person selects the maximum score, and then returns to the previous node, giving the opposite number of points.
IntNegamax (IntDepth) {
IntBest=-INFINITY;
If(Depth<=0) {
ReturnEvaluate ();
}
Generatelegalmoves ();
While(Movesleft ()) {
Makenextmove ();
Val= -negamax (depth - 1// notice there's a minus sign
Unmakemove ();
if< Span style= "COLOR: #000000" > (Val > Best) { //is the highest score selected because the object that evaluates the score has changed
best =&NBSP;VAL;&NBSP;
}
}
return&NBSP;BEST;&NBSP;
}
This negative value is the largest algorithm, mainly the reduction of the amount of code, time and space efficiency does not improve.
3. Alpha-beta Search method
For example, consider the following example:
Figure-alpha-beta Search
The Minimax search is a deep search, when the second green node of the second layer is searched, it is known that its first child node returns a value of 2, because this is a pole point, then the value of this node is definitely less than 2, and the first green node of the second layer has a value of 7, so even after the node is searched, No more than 2, not more than 7, so the nodes behind this node can be ignored, that is, the third volume of the graph has no number of nodes. This is the alpha pruning, which is probably the reason why the cut-off node is a great node. The corresponding beta pruning is also available, which is ignored in the picture.
The following Wikipedia pseudocode, where two values, α represents the best value to search, β indicates the worst value to search for.
function Alphabeta (node, depth,α,β, Player)
IfDepth=0or nodeIsA terminal node
ReturnThe heuristic value of node
IfPlayer=Maxplayer// max node
for each child of node // min node
α := max (α, Alphabeta (Child, depth-1 , α, β, not (Player) ))
if β ≤ α// The value of the maximal node >=α >=β, the search-to-value behind the maximal node will certainly be greater than β, so it is not chosen by the smallest node in its upper layer. For root node, β is positive infinity Break(*Beta Cut-Off*)
return α
else // min node
for each child of node // max node
β := min (Β, alphabeta (Child, depth-1, α, β, not (Player) ) // min node IfΒ≤αThe value of the maximal node <=β<=α, the value searched for after the minimum node is definitely less thanα, so it will not be chosen by the great nodes of its upper layer. For the root node,αis negative infinity
Break(* Alpha cut-off *)
return Beta
(* Initial call *)
Alphabeta (origin, depth, -infinity, +infinity, maxplayer)
4. References
Wikipedia-minimizing the maximum algorithm
Min-Max Search http://www.xqbase.com/computer/search_minimax.htm
Alpha-beta Search Http://www.xqbase.com/computer/search_alphabeta.htm
Turn: Minimax search method, negative value maximum algorithm and Alpha-beta search method