Thoughts on wuziqi computer AI Algorithm

Source: Internet
Author: User

This part is a key point, a difficult point, and the most possible part of a team. I read some documents, but now I have a new idea.

 

In most algorithms, two steps are required. The first step is to calculate the priority and then score. But I was wondering if I could use a certain mathematical model to combine these two types of computing. That is to say, we can identify the priority from the center of the score. This reminds me of digits in decimal notation. Anyway, I mainly judge from four directions, so when we rate some low-priority items, we set the score to a tenth above its priority. In fact, I think this is only eight times more than the score, because the method for selecting the optimal position is the accumulation method to calculate the score and the highest position. In this case, even if there is a lower priority in the four directions, even if the sum of the values does not exceed the score of the higher priority, in this case, if there is a higher priority, therefore, the calculation result must be the highest priority score. In this way, unnecessary classification is reduced, making the algorithm more direct and easier to understand.

 

First, let's take a look at the priority distribution when playing chess and the scoring plan I specified for it:

First, we declare that we will not implement the five sub-links in this part of the algorithm, because the outcome has been separated at this time. We can call the judge method of the checkboard class. This is just to copy judge's code after computer AI.

Our goal is to score the vacancies on the board, and then calculate the highest score position. So I want to use the test method here, because I think the code is easier to write. The so-called test method is to find all the vacancies on the board, and then let us assume that there is white chess on the vacant space, then look at the connection, and then score, add the score to the variable that stores the vacancy score. Then, assume that the empty space is placed with a black game, then check the connection and score, add the score to the variable that stores the vacancy score. This way, when all the vacancies are traversed, the score is completed, and then the vacant scores are compared to select the highest-score vacancy, this is the optimal position.

The following lists the priorities of some cases: (assuming we are playing white games) the following situations are all after this empty position:

During implementation, we also need to define two temporary Checker pointer variables to save the status of the front and back positions of the connected piece. Color is used to save the color of the pawns. count is used to save the number of connected pawns. temptr1 and temptr2 are used to save the pointer of the pawns at both ends. We use computers in this article!

Situation

Score

Color = 1 & count = 5 we win first, win again

100 000 0000

Color = 0 & count = 5 the other party wants to win. If we cannot win first, we must first block it.

10 000 0000

Color = 1 & count = 4 &&! Temptr1 &&! Both sides of temptr2 won't win. If we can survive, the enemy will lose.

1 000 0000

Color = 1 & count = 4 &&((! Temptr1 & temptr2) | (temptr1 )&&! Temptr2) The two sides won't win, so if we can become a Game 4, we should first set the game and lead the enemy's nose, because after this move, the enemy will definitely stop us.

100 0000

Color = 0 & count = 4 &&! Temptr1 &&! Both sides of temptr2 won't win. If the opponent can survive, we must give priority to blocking; otherwise, we will lose.

10 0000

Color = 1 & count = 3 &&! Temptr1 &&! Both sides of temptr2 won't win. If we can survive 3, we should give priority to this position.

1 0000

Color = 0 & count = 4 &&((! Temptr1 & temptr2) | (temptr1 )&&! Temptr2) both sides won't win. If the enemy can become a hit 4, we will try our best to block it.

1 000

Color = 1 & count = 3 &&((! Temptr1 & temptr2) | (temptr1 )&&! Temptr2) both sides won't win. If we can become a hit 3, we should give priority to this position.

1 00

Color = 1 & count = 2 &&! Temptr1 &&! Both sides of temptr2 won't win. If we can survive 2, we should give priority to this position.

1 0

Color = 1 & count = 2 &&((! Temptr1 & temptr2) | (temptr1 )&&! Temptr2) both sides won't win. If we can become a hit 2, we should give priority to this position.

1

Other cases

0

The main idea of this algorithm is that it does not constitute a threat to the enemy (namely, if the number is less than four, but here we have included the number four and given a higher priority ), we don't care about it for the moment, but are thinking about how we can win. Here we can only divide it into so many cases, because if our score is of the long type, its length is 32 bits, which is converted to decimal, and the number of BITs is also 10 bits, therefore, I chose the maximum score of 1000 000, which is enough to meet the requirements.

But there is a small problem here, that is, how can we get down at the beginning? I think at this time, we can set the score of a vacant space to the lowest value, and the score will be set to 0 after the game goes down. When the other party goes down first, we place the first piece around the other party's piece and start AI. Then the problem will be simple, because there will be a rush to the second, the other is the opponent's active 4, and then the defense, this step by step, it will start.

Related Article

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.