Wu haipin game core algorithm Round 5-proof that no one can ban the first player

Source: Internet
Author: User

The proof that wuziqi must win is too complex by means of manual work. The difficulty is equivalent to proving the correctness of the four-color theorem or the correctness of the ruoer theorem. However, if you use a computer to solve the problem, the complexity will be much lower. Since it is difficult to enumerate all possible situations in a blanket, this wuziqi Terminator algorithm (the latest version should be 1.22, And the 2.0 and 4.0 versions circulating on the Internet are all imaginary) it is almost possible to win the first hand. The author even offered a reward of 0.92 million US dollars. That is to say, if you use his program to defeat the hacker, He will give you so much money as compensation. However, so far, this algorithm can almost achieve first-hand victory!

 

Wuziqi Terminator Algorithm

The key to any type of chess game is to determine whether the current Board has a correct score. The more accurate the score, the higher the computer's AI. The same is true for wuziqi games.


 

So, before scoring, we first scan the entire board and fill in the chess model of each vacant space in eight directions into the array gstyle (2, 15,
15,


 

8, 2). When the first subscript is 1, it indicates black. When it is 2, it indicates white. The second and third subscript indicates (x, y), and the fourth subscript indicates 8.


 

Direction. When the last subscript is 1, it indicates the number of pawns. If it is 2, it indicates the number of spaces, for example:


 

Gstyle (1st, 1) = 3 indicates that the number of black chess pieces adjacent to the coordinate () in the direction is 3

Gstyle (1st, 2) = 4 indicates the number of spaces closest to the coordinate () in the direction is 4

When defining the direction, you should also pay attention to some tips, indicating that the number of two opposite directions should be 4 different, which is defined in the program as follows:

Const dir_up = 1

Const dir_upright = 2

Const dir_right = 3

Const dir_rightdown = 4

Const dir_down = 5

Const dir_downleft = 6

Const dir_left = 7

Const dir_leftup = 8

In this way, we can add four in the first four directions to get the value in the other direction. See the following figure:

---------

---------

--- Oo ----

-Ox * XX ---

---------

---------

The * point in the figure is marked as (4, 4), (the position of the * is blank), then:

Gstyle (, 1) = 1 The number of white games at the top of the adjacent vertex () is 1.

Gstyle (, 2) = 2 the number of spaces closest to the top of the vertex () is 2

Gstyle (, 1) = 2 the number of black games on the right adjacent to () is 2.

Gstyle (, 2) = 1 the number of spaces closest to the right of the right side of the vertex () is 3

...


 

Once you fill in the chess value of all the empty points, we can easily obtain the value of the point (4, 4) in the horizontal direction of the black game.


 

Games in the world are called Chong) and active 2 (the two sides are unbounded

Called active. The value of playing the game in the vertical direction (4, 4) is a live 1, and the live 1 in the/direction. So, as long as we


 

Calculate the value of this point for black and white games

Then, we will take the sum of the two values of the empty points on the board as the playing point. However, what should we choose from various chess models?


 

What is the value? We can first make the following assumptions:

FN indicates the active Chess Model of the First n pawns. For example, F4.

FN 'indicates the playing style of the First n pawns. For example, f4' indicates the playing style of the First n pawns.

Ln indicates the active Chess Model of the N pawns of the postmaster. For example, L3 indicates the active three of the postmaster.

Ln 'indicates the playing style of N pawns in the backend, for example: L3' indicates playing three

.

..

Based on the chess analysis in a row, the following relationship is obtained:

L1 '<= F1' <L2 '<= f2' <= L1 <F1 <L2 <F2 <L3' <= F3 '<L4' <F4 '= F4 from this relationship includes the relationship between attack and defense (of course, this


 

The relationships are determined by me. You can define these relationships by yourself ). Further refine these relationships, such as the four sides of a game.


 

There are three active nodes in the upward direction, which is not comparable to a four-pronged approach, so we can get another 4 * F3 <L4 'relationship. Similarly, we can get other


 

Relationships, such as: 4 * F2 <L3, 4 * L3 <F3. these relationships may be different because of your method and my method.


 

Not the same. Finally, we set the value of L1 with the minimum score to 1. Then we get the scores of the following chess models, represented by the C language:

F [2] [5] = {16000, 30,750,160 }};

L [2] [5] = {3750, 30,150,400,}, {, 0 }};

The F array indicates the forehand. When the first subscript is 0, it indicates the impulse. The second subscript indicates the number of pawns. Then, the F2 'corresponds to f [0] [2] l array to indicate the latter.


 

When the first subscript is 0, it indicates the impulse, and the second subscript indicates the number of pawns. Then L2 corresponds to f [1] [2] OK. After the score relationship of the chess model is determined


 

In the left-side navigation pane.


 

One point is the point for the computer to go down :).


 

After that:

1. The maximum value may be more than one vertex, but only the first largest vertex can be selected in my program. Of course, you can use a random number to determine the maximum value.

You can select the maximum value for further analysis.

2. In this algorithm, I only considered the points of pawns, but I did not consider other points.

3. You can go further. Use this algorithm to predict the next few moves, and then select the best predicted step. In this way, the computer AI will be higher.

4. This algorithm does not take into account the banned players of black games (double 3, double 4, and more than five players ). Because I usually do not have these five games.

Banned

 

Algorithm solving process of wuziqi Terminator

Final Completion of five games is not a very difficult problem, and it is not much different from ordinary traversal solutions. The calculation workload is a little large. We need to consider the point of gradual development of systematic hierarchy during the design. It is impossible to complete very subtle algorithms within three or two days. Therefore, the final work of wuziqi is not very fruitful. It only solves the traversal problem with a slightly larger state space. All the knowledge required is only the C language, binary tree, and knowledge of wuziqi rules, you don't need a good player to write a program. You just need to give the idea to the machine.


The computing engine of the final game is divided into three layers. The upper layer calls the lower layer, which is


> Target process layer.


Limited by computer capabilities, the terminator of wuziqi cannot be completely terminated by a single search. Instead, it is a progressive process from the primary branches to the secondary branches to the end of the entire game. The engine at this layer is just a for loop, gradually increasing the width of the final target, from 5 to 10 to 30 to 50 to 225. When it reaches 225, wuziqi is completely terminated.


> Policy engine layer.


Optimal priority and or solution tree engine. Not to mention the complexity of the name, it is actually an ever-expanding M-tree. Let the best piece get the CPU. The priority of the piece is dynamically calculated and adjusted based on the lower-layer results, also known as feedback, until the branch is terminated under the current target width.


> VC attack engine layer.


VCF and VCT, short for VC, are the winning engines of continuous attacks. The speed and accuracy of the solution are crucial.

How does one perform dozens of in-depth attacks within S? The relationship between black and white during attack and defense and their respective correlations are calculated.

Unrelated considerations can resolve casual counterattacks of the other party, while relevance considerations can associate their own attacks to maintain the pace and organization, rather than blindly. the two work together to drive their attacks straight into the cloud, the trend is like a storm.

The VC design in Version 1.00 is similar, because the Width Estimation is taken into account in VC, rather than comprehensive reasoning. Therefore, the end is similar and easy to defeat. Vvc 1.20 is strictly designed, but the program
"Three adjacent active connections only need to defend against two blank locations on both sides" is a vulnerability-proof Attack and Defense logic. Therefore, version 1.20 was also defeated a month later. Version 1.22 corrected the above vulnerability in version 1.20 and changed only one character, that is, the defensive mask next to active three. Previously, I thought that the strict reasoning logic was still found to have an unexpected vulnerability. Therefore, for 1.22 of VC engines, I do not know whether there is a logical vulnerability, no one beat 1.22 for the moment. This does not indicate that the vulnerability does not exist.


After the above algorithm is implemented, execute the final command. After half a month of continuous computing, a complete carpet winning tree will be generated, containing about one million pawns, all the leaves of the tree can be solved by VC. If the VC Solution Engine does not have any vulnerabilities, the five games will win.


The Terminator program is very small. The algorithm only contains more than 10 thousand lines of code, and the compilation result is more than one hundred kb. It only needs a few MB of memory to run, and the winning tree has only to nodes.


The following is the code for reading the winning tree. You can use the following function to operate the winning tree in the terminator Resource:

1 // read the resource file to the array book []. Call this function to generate a winning tree
2 // int key = 1 ;//!!!!!!!
3 // input the current key and the pointer to the Child root to complete the growth of the tree to which the root points
4 // when the upper layer calls this function, the key already points to the next character of [(, my processing:
5 // (-- add the root child
6 //) -- after the child is added, it is optional.
7 // [-- add children to children
8 //] -- the root tree has been grown
9 // The parameter is the pointer of the eldest son and the pointer of the father.
10 void make (nodeoftree ** root, nodeoftree * parent)
11 {
12/** root points to the node. We need to assign a value to * root */
13 int rootok = 0;
14 nodeoftree * rightc = NULL;/* rightc always points to the new brother */
15 nodeoftree * Rightt = NULL;/* Rightt points to new brothers */
16
17 if (Book [Key]! = '(')
18 {
19 f5_print (1, "make book [Key]! = '('");
20 return;
21}
22
23 do
24 {
25 switch (Book [Key])
26 {
27 case '[': // fprintf (outcourse, "start to have children... \ n ");
28 key ++;
29 make (& (rightc-> down), rightc );
30 break;
31 case ']': // fprintf (outcourse, "Child completed... \ n ");
32 key ++;
33 return;
34
35 case '(':/* Add a brother */
36
37 Rightt = (nodeoftree *) malloc (sizeof (nodedata ));
38 If (Rightt = NULL)
39 f5_print (1, "Make Rightt = NULL ");
40 node_mum ++;
41 memset (Rightt, 0, sizeof (nodedata ));
42 Rightt-> data [0] = cover (Book [Key + 1], 1 );
43 Rightt-> data [1] = cover (Book [Key + 2], 2 );
44 If (Key = 1)
45 Rightt-> data [2] = 1;/* The first child is a sunspot */
46 else
47 {/* opposite to the father's color */
48 if (parent-> data [2] = 1) Rightt-> data [2] = 2;
49 If (parent-> data [2] = 2) Rightt-> data [2] = 1;
50}
51 Rightt-> right = NULL;
52 Rightt-> down = NULL;
53
54 if (rightc! = NULL)
55 {
56 rightc-> right = Rightt;
57}
58 rightc = Rightt;
59
60
61 If (rootok! = 1)/* One of the brothers, that is, the boss */
62 {* root = Rightt; rootok = 1;
63}
64
65 key = Key + 3;
66 // fprintf (outcourse, "add a brother (% C-% C) \ n", rightc-> data [0], rightc-> data [1], rightc-> data [2]);
67
68 break;
69 case ')':
70 key ++;
71 break;
72
73 case '\ 0': // fprintf (outcourse, "this field is not allowed and is returned in the last! \ N ");
74 break;
75
76 default: Key ++;
77 // fprintf (outcourse, "the string contains incorrect characters! \ N ");
78 break;
79}
80} while (Book [Key]! = '\ 0 ');
81 return;
82}


 

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.