Wuziqi Algorithm + wuziqi AI valuation Algorithm

Source: Internet
Author: User

Today, when I mentioned the wuziqi algorithm, I posted the source code I developed earlier. Let's take a look at the source code.

This is because the wuziqi algorithm may be very easy to write. So here is a simple description of the principle, the specific download source code study.

Many may ask how wuziqi judges the five sub-links in step 5. It is easy for programmers who are familiar with 2D array applications.
In this example, we use a 2-dimensional array with the white text 0 sunspots as 1 and use an array to determine whether the five sub-links are connected.

For example, use a small array like this to represent the chessboard:

Arr [0] = [0, 0, 0, 1]
Arr [1] = [1, 1, 1, 1]
Arr [2] = [0, 1, 1, 0]
Arr [3] = [0, 0, 1, 0]
Arr [4] = [1, 0, 0, 1]

Is a 2-dimensional array. With the naked eye, we can easily determine the arr1 line's five 1. Yes. You only need to expand from one point (the last step) to five vertices in eight ways. If the values of these five vertices are the same, they are connected.

Then we will talk about AI first.
How can wuziqi be a robot? A simple method is valuation. What is valuation is when the opponent takes every step. Evaluate each point of the game. Then find out the most valuable point, that is, the point where the robot is going. The AI valuation table I wrote is as follows. Of course, the more detailed the valuation and chess decisions are, the more powerful the robot will be.

Valuation Table (null value)

The number of sub-weights connected to the current player
PC survival 2 1
Competitor survival 2 2
PC survival 3 3
Competitor survival 3 4
PC survival 4 5
Competitor survival 4 6

PC survival 5 7
Competitor survival 5 8

Valuation Table (full value)

Opponent survival 2 1
PC survival 2 2
Competitor survival blank 2 3
PC survival empty 2 4
Competitor survival 3 5
PC survival 3 6
Competitor survival blank 3 7
PC survival empty 3 8
Opponent survival 4 9
PC survival 4 10
Competitor survival blank 4 11
PC survival empty 4 12
Opponent survival 5 14
PC survival 5 15

Number of pawns 2 3 4 5
Magnification 1 2 2.5 3

PC 4 8 12
Competitor 3 7 11
PC 2 6 10 15
Competitor 1 5 9 14

Formula
Competitor blank sub-count * rate + 2
Number of empty PCs x rate + 1
Number of opponents * Rate
Number of PCs * magnification-1

It may not be understood at first. But here we will only talk about the principle. As for the implementation method, we just need to look at the source code.
The following example is used to describe what is an estimate and how to make an estimate.
The most basic thing is to use the initial method to determine whether to win or lose. You can get 8 pieces in 8 directions by extending one point to eight directions. Then we can find out that the greatest number of pawns in these eight directions is the estimated value of this point. In plain words.
For example, the first array:

Arr [0] = [0, 0, 0, 1]
Arr [1] = [1 ,?, 1, 1]
Arr [2] = [0, 1, 1, 0]
Arr [3] = [0, 0, 1, 0]
Arr [4] = [1, 0, 0, 1]

For details, refer to the ARR [1] column ,? What is the estimated value? First, starting from this point, finding the most sub-item in the 8 direction is the valuation. You can see from the naked eye that it is? To the right. There are 3 1. The more the child, the highest value. The estimated value of this vertex is obtained in the most common direction.

At this time, you should know the price at one point. However, this is not enough. The only difference is to use the same method to find out where there are no pawns in the entire board, and then use the same method to calculate their valuation. The highest value. The point where Ai is going.

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.