Artificial Intelligence of Chess Game (3)--Game tree optimization

Source: Internet
Author: User

Objective:
Chess game of Intelligent algorithm, online data a lot, very similar. However, the book came to the end of the shallow, I know this matter to preach. Combined with their own engineering practice, a simple summary of the next. On the one hand is the classic <<PC game programming (Man-machine game)>> Expression of respect, on the other hand, also want to their own game programming life to do a review.
To undertake two blog posts:
(1). Evaluation function + Game tree algorithm
(2). Learning Algorithms
This blog post returns to the game tree side, specifically elaborated under the game tree optimization means, for the game to add the reasonable skill.

heuristic search:
The game Tree essence is a minimax solution, while Alpha+beta pruning accelerates the solution process.  
Let's build a simple Alpha+beta pruning use case:

Note: The purple represents the maximal value solution, and the green represents the minimum value solution.
Through the artificial calculus and simulation, the whole game process, successfully reduced the computational capacity of 3 nodes, the effect is general.
This process, do we have room for optimization? Let's adjust the search order for the node S1 and S2 .  

Compared to the order of adjustment, its alpha+beta pruning effect increased, cutting off a large branch, reducing the computational capacity of 4 nodes.
From this example, we can clearly see that for the game tree, its alpha+beta pruning effect, and the search order has a certain relationship. Simple summary: Alpha+beta effect, order sensitive to search .
We found an optimization direction: Adjust the order of the feasible steps and prioritize the search for the high-expected branch. The technique is named: heuristic search .   Often people use historical values, killer steps to construct heuristic functions.  

Negative maxima algorithm int Negamax (gamestate s, int depth, int alpha, int beta) {    //game End | | The recursive depth of the exploration is to the boundary    if (Gameover (S) | | depth = = 0) {        return evaluation (S);    }    Sort    (Candidate list) based on estimates (history, experience) for feasible steps;    Iterate through each candidate step of    foreach (move in candidate list) {        s ' = Makemove (s);        Value =-negamax (S ', depth-1,-beta,-alpha);        Unmakemove (S ')         if (value > Alpha) {            //Alpha + Beta pruning point            if (value >= Beta) {                return beta;
   }            alpha = value;        }    }    return Alpha;}

At this point in the core algorithm structure: added the feasible step ordering process (sort (candidate list)).
Of course, the process has a certain cost, in the Alpha+beta pruning effect lifting and sequencing losses need to balance and compromise. Generally, a simple estimation function can be used.
Let's go back to Othello AI, which we can simply select, which is equivalent to the position table, that is, p (x, y) = Map (x, y). (Map is the positional importance matrix of black-and-white chess), and the effect is remarkable.

permutation table:
People who have done ACM know one way to solve the DP problem: memory Search . The essence is to save the middle State and reduce the repetition of the search technique.
The core idea of the permutation table is basically the same: State save, reduce duplicate search .
But the difficulty of the permutation table is not in thought, but in state save . The
can be analyzed as follows:
1). The game situation s itself occupies a large space, and need to save the state S set many, so need a conversion function f (S) = key, (key is not a long binary string, or a very large integer) 2). The converted key, which corresponds to a specific situation s (the conflict rate is very low negligible, or does not exist)
Let's use black and white to do an example, the situation into a matrix (0: blank, 1: Black chess, 2: white), flattened into a string, in the use of powerful hash function to transform.

This shows the specific process, the effect of the good or bad, depending on the choice of hash function. The
simple adoption of the MD5 algorithm, in fact, is feasible, but more CPU-consuming. Zobrist hashing algorithm is also highly recommended.
compared to a memory search, the permutation table corresponds to the situation that is only the intermediate prediction node , so the state is related to the game situation itself, but also with the current The search depth .
Therefore the code can be amended as follows:

//negative maxima algorithm int Negamax (gamestate S, int depth, int alpha, int beta) {//judgment state already exists in the displacement table        , and the search depth is less than or equal to the known, the IF (exists (Transpositiontable[s]) && transpositiontable[s].depth >= depth) is returned directly { Return Transpositiontable[s].value}//Whether the game is over | |    Explore if the recursion depth is to the boundary if (Gameover (s) | | depth = = 0) {return evaluation (s);        }//Traversal of each candidate step foreach (move in candidate list) {s ' = Makemove (s);        Value =-negamax (S ', depth-1,-beta,-alpha);        Save S ' into the permutation table when the depth is deeper. Transpositiontable[s '] <= (depth, value) if Transpositiontable[s '].depth < depth unmakemove (S ') if (            Value > Alpha) {//Alpha + Beta pruning point if (value >= Beta) {return beta;        } alpha = value; }} return alpha;} 

Summarize:
Heuristic Search and Substitution table, both are good ideas, the former by adjusting the search order to speed up the pruning effect . The latter passes space to change time . All in all, these are the most common optimization methods in the game tree. Of course, in specific games, it is necessary to weigh and evaluate. The next article is about how to optimize and choose your strategy for gameplay reasons.

Written at the end:
  
If you think this article is helpful to you, please give it a little reward. In fact, I would like to try to see if blogging can bring me a little bit of revenue. No matter how much, is a kind of sincere affirmation to the landlord.

Artificial Intelligence of Chess Game (3)--Game tree optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.