The minimum maximal value algorithm and pruning algorithm used in chess

Source: Internet
Author: User

1. Chess usually needs to calculate the current situation, each step after the situation points, usually we can set the consideration of a few moves, usually we call the calculation of chess, and the computer's AI algorithm is most commonly used is the maximum minimum value algorithm, and pruning algorithm is a maximum value of the minimum algorithm optimization.

As shown in the following:

1. If in the current situation, assume that there are three steps to go chess, after the completion of the situation is 100,80,90, if only consider a step, of course, the choice of 100 of the corresponding chess, which is the simplest and the most myopic approach, such AI will make people think too stupid. At this time level=1

2. If you consider the situation of two-step chess, after the first step, turn to the other side to go, the other side after the end of the situation is the third layer of points, the possible way to go: 100 branches, there are three possible: 60,10,40, walk 80 branches, there: 50,30,20, Walk 90 branch, there: 40 , 50, 30, suppose we are not silly, will pick the most unfavorable chess go, so walk 100 branch words, the other side can be bound to walk 10 branch, if walk 80 branch, the other side certainly walk 20 branch, if Walk 90 branch words, the other side certainly walk 30 branch, so we to make two steps after walking (2 steps, level=2), oneself obtains the situation to be the biggest, makes oneself most advantageous, then must walk 90 branches, thus, the other side regardless of how to walk, obtains the smallest value situation to be 30, is compared to walks other branches (100 and 80) the minimum value to be big. This is the minimum maximum value algorithm.

3. If considering three-step chess situation, at this time level=3, to the fourth level situation, at this time, level=0, that is, only need to directly calculate the current situation of each branch can be, get: 15, 35,8,9,25,15,34,25,8,20,18,10,7,14,32,21,16,15,

How can we walk at this time to be the most advantageous?

A. Assuming that the first step of the 100 branch, then the other side must walk 10 branches, at this time we can only walk 9 branch (Getmaxscore),

B. If the first step 80 branch, then the other side must walk 20 branches, at this time we can only walk 18 branch (Getmaxscore, get the best situation points)

C. If the first step to the 90 branch, then the other side must walk 30 branches, at this time we can only walk 16 branch (Getmaxscore, get the best situation points)

Therefore, we only need to consider selecting a maximum value in the fourth layer. There is no doubt that the first step must go 80 branches, then the other side walk 20 branches, and then we walk 18 branches, at this time the situation for our best interests.

So the summary is as follows:

Our ultimate goal is to make the final situation the most important basis.

The minimum, maximum algorithm is used alternately, depending on the number of steps (level) there are different ways to go.

Getminscore () calls Getmaxscore (), and Getmaxscore () internally calls Getminscore () two functions to form an indirect recursion.

4. Pruning algorithm:

Suppose you consider a situation like this:

Assuming that the second branch 80 below 50 for 5, and only consider the case of level=2, at this time we are the first step is to find the minimum (the third layer), the second to find the maximum (the second layer), note that this is a back-up algorithm, according to the possible results (final situation points) backward, may have to go chess step.

When we finish the first branch (100) and found that the minimum value is 10, and when we deduce the second branch, when the minimum value (the third layer), encountered 5, obviously 5<10, and at this time the upper layer (the second layer, that is 100,80,90) required is the maximum value, So the other branches of the branch (30,20) do not need to be deduced, since the minimum value of the branch (5) is already smaller than the minimum value of 10 in the previous branch (100-->60,10,40), it is meaningless to deduce it, so you can discard the remaining branches of the branch, does not need to calculate, greatly reduces the computation quantity, directly deduces the third part (90), commonly known as the pruning algorithm.

So we need to pass in a parameter that marks the highest value in the previous branch. If a value in the branch is smaller than the maximum value in the previous branch, the other branches of the branch can be ignored because the branch is definitely out of scope. Therefore, you can end the calculation of this branch in advance and calculate the next branch directly.

The minimum maximal value algorithm and pruning algorithm used in chess

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.