Gobang Calculation Ideas

Source: Internet
Author: User

Gobang is divided into a forbidden hand and a no-ban hand, there is no prohibition on the hands of the rules on the basis of the prohibition of hand rules, specific rules do not speak. So on the man-machine battle, from the non-banned hand to do, relatively good to do. This is only a case of no-cut hands. No-ban hand is as long as can be connected to 5, or more than 5 children, even win.
And the computer game to solve the problem, abstractly speaking only one question "How to go Next", to Gobang, is the next step in which point Lazi.
General idea in chess man-machine versus the general principle-Billysir-blog Park has been said. The following focus on Gobang unique algorithm ideas.

How to go next, general idea:
1. If you can win next, take this step
2. If you lose the next step, stop the opponent from winning.
3. The computer score determines where to Lazi.
Which prevents the other side win, is in the other side can win the point on the Lazi, generally there will be 1 to 3 points.
The first 2 points are better understood, the focus is 3rd, calculate the score.
The thinking of scoring is very common, that is, each empty position on the board, calculate a point, all the empty position of the points, which point (position) scored the highest lazi at that spot.

How do you calculate the score for each point?
Scan all empty positions on the board (no white and no sunspot points), and calculate the score for each point.
Each point of the score is affected by 8 directions, the graph is a "rice" word. This point is the central point of the rice word. Consider the 2 directions on the same line as 1 directions, which is the effect of 4 directions. is to scan 4 directions and see if the Lazi will make a difference (to one's own side)
If it's 5, of course it's won, the highest score.
The order from highest to lowest score is:
Five (or more than five) > live four > Punch four > Live three > Punch three > Live two > Punch two > Live one > Punch one
(Ps. Live four live three often have heard, live two rushed one these also do not know people have this saying, but does not affect our software writing. )
Scan the situation in one direction, corresponding to one of the 9 cases above. Check the scoring table and get the score. The scoring table is the top of each case giving a fixed number as a score. The score in 4 directions is added as a total score.

This is only the case of Lazi to his own side, that is the score of the attack.
Lazi will also cause obstruction to each other, so lazi in addition to the role of "attack", there is a "defense" role.
But the attack is their own first (it must be the turn of the computer to think how to next), anti-Talk is the hand (we take a step back to the other side, on the other hand), the same situation, the initiator score and the score is not the same. So the score table has 3 columns: The situation, the initiator score, and the score.

To summarize, for an empty point on the board, it scores from 8 numbers, of which 4 are 4 directions of the attack, and the other 4 are 4 directions of the anti-score.

The same situation, the attack is greater than the anti-point, so special circumstances, both sides are rushed four live four of the situation, it is natural to complete their own five, instead of first blocking each other's four.

    • Search

The front is a scan, get the score of each point, pick the highest points of the point Lazi. But we know, Gobang, to win, is often the last few steps attached, such as first into the "four live three", and then take a few steps to win. And if the other side is ready to "punch four live three" to stop quickly, rather than wait until "live four" again plugging, it is too late. So, you need to walk through the next few steps in memory, where the two sides might go. This is the search.

Back to the situation just now, computer in thinking this step should be at which point Lazi, we pick out the highest points of several points (can be set higher than the punch three to calculate, can also set the highest x points, such as 8 points), assuming that we have one of the points (this is the 1th step), then the next turn to the other side, the other is the same thinking, From the perspective of each other, the computer out of each point of the score, pick the highest score of a few points to try (this is the 2nd step), and then turn to our son, thinking and algorithm is the same. So you can search several steps. In this way, the situation is branched into many cases, becoming a tree. Since each step is trying several different approaches, it is ultimately desirable to determine one of the most advantageous approaches to oneself (relative) in several ways. Every step of the way. This is called the maximum principle. If as an onlooker, always standing on one side to evaluate, is the maximum minimization principle.

Because it is impossible to search for the outcome, so the search to a certain number of steps to stop searching, so to determine the current situation to their own advantage, so need an algorithm to assess a static situation score. Simple can be the sum of all points in the situation as the score of the situation (considering attack and defense situation)

Each step chooses the most advantageous situation to oneself (relative), then goes back to the 1th step of several situations, certainly chooses that to oneself most advantageous situation to Lazi, this point is not necessarily the first point which the highest score. This search is more lazi than the point with the highest score directly selected.

This is the whole idea, so far the problem of "where to go" has been solved and is the only goal of computing.

However, the actual problem has come to a pop.

    • Optimization

Because search this tree has a lot of leaves and branches, each leaf to calculate the situation score, in the calculation of a one-time score, the situation score, is a large amount of computation, plus the branches of the tree, this computer is magnified many times, so the search becomes very slow. Can not let man-machine PvP every time waiting for a computer to go a long time, such as 3 minutes, 1 minutes, if it is you, to suffer? So, man-machine PvP often spends a lot of effort in optimizing search. Above, it is an effective optimization to pick out a few of the highest points to try, instead of trying every step for all empty locations.

pruning is the cutting off of branches, thus reducing the amount of computer. How to cut off branches without affecting the results of the computer, or the impact of small to ignore is worth in-depth study. and Alphabeta pruning method is in "Maximum minimum value search", can cut off some branches, without affecting the computer results of an optimization algorithm.

    • Alpha-beta Pruning

Alpha Pruning

To add, the chess search is generally in depth first, but also on the basis of depth first, then combine depth first, step by step deepened. In essence, it is depth first.

For example, a minimum value of 4 is obtained from 5,8,4, and then to a node, 2 children of a have results, 6 and 2. Since 2 is already smaller than its Uncle 4, so, regardless of the size of the 2 Brother B node, the value of a must not be greater than 2, and the highest level is to take the maximum number (note the left of Max and Min), since a maximum value does not exceed 2, so, no longer search for a 3rd Child B node and the child behind.
Similarly, the 1th child of A's brother (c-node) is already 3 (smaller than 4), also cut off.

Beta pruning, exactly the opposite of Alpha. For example, since 2 and 9 of the uncle is 7, and 2 and 9 is the largest between 9, so 2 and 9 of the Father a node, at least 9, and the upper layer is to take small, definitely take 7, so do not calculate 9 of the brother (b node) scores.

Alpha-beta Pruning Search-ithinktan-Blog Park

    • Update optimization of the fractional disk

Each empty point on the board has a score, the whole chessboard is a 2-D fractional disk, obviously before and after a sub-lazi, the score disk will change, but the range is limited, only need to recalculate the points that may be affected, you can create a new score disk on the basis of the original score table, Instead of having to recalculate each empty point. The range of Lazi after each point is also the "M" range centered on this point. So you just need to recalculate the empty dots on this meter.


Gobang algorithm, I basically finished.

There are some algorithms that are closer to the principle of chess, such as empty steps. We are counted as simple, assuming the other side does not go, how can we do. Empty steps can be used to improve the accuracy of the situation valuation.

The dead center is marked and will not be searched again. For example, the foot, some chess type can never be 5, will never be 5 points do not search!

Thank you for your Sorrow (qq:35994468) provides a number of supplements to this article.

Gobang Calculation Ideas

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.