Maximum and minimum search, Alpha Beta pruning

Source: Internet
Author: User

Topic of basic technology for NLP-Max search: http://www.xqbase.com/computer/search_minimax.htm
Alpha-Beta Search: http://www.xqbase.com/computer/search_alphabeta.htm
Wikipedia MINMAX: http://en.wikipedia.org/wiki/Minimax
Wiki alpha-beta pruning: http://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning
MINMAX explain: http://ai-depot.com/articles/minimax-explained/1/
Minimax explained? Action = plugin & V = wave & TPL = Union & AC = viewgrouppost & gid = 34694 & tid = 15725
Minimum Maximum Principle and search method: http://blog.pfan.cn/rickone/16930.html

Personal Understanding:

In the game, you can find a game tree where each layer of nodes is in the same State, and each node has a winning evaluation value, which is divided into the max state and Min state, for example, Player A corresponds to the max status and player B corresponds to the min status. The goal is that a wants to maximize his/her rating, and B wants to minimize his/her rating (B's rating is represented by a negative number, which is easy to understand ).

What path does the max state go to the min state? First, let's not look at B from the perspective of a from the perspective of Player A. If a is like this, estimate the status in which B will get the min value, then select the largest (negative number, absolute value) among all min values of B, which is obviously the most favorable for. Sun Tzu Has Cloud: "know yourself, know yourself, and never slack in battles "~

This is also true for B. If the AB level is the same, the result depends on the first hand and the last hand, so the result will have a unique solution.

About alpha-beta pruning. From the perspective of. A wants to take the State that makes all min values of B the largest (negative), then it can make a record on the minimum state obtained in advance, if the ratio is largest (negative) if the status is small, the branch can be removed. This is the Alpa pruning. Similarly, from the perspective of B, the minimum value of Max is removed, which is Beta pruning.

I can only understand so much... Looking at the paper, I cried... I want to learn English well. I should be exhausted !!!

 

Poj 1085

Q: AB is used to place edges in a triangle that contains nine small triangles in turn. When a person puts an edge and forms a small triangle, this person gets a point, whoever gets more wins.

Maxmin search + alpha-beta pruning, the process is to compress this triangle, a total of 17 sides. Then search. In this question, Alpha is 1, which indicates that a can win. When the search Value Returns 1, other searches are not needed. The Beta value is-1, indicating that B can win, and then perform pruning.

Reference: http://blog.csdn.net/dooder_daodao/article/details/6682971

  

View code

// # Pragma comment (linker, "/Stack: 327680000,327680000 ") # include <iostream> # include <cstdio> # include <cmath> # include <vector> # include <cstring> # include <algorithm> # include <string> # include <set> # include <functional> # include <numeric> # include <sstream> # include <stack> # include <map> # include <queue> # define Cl (ARR, val) memset (ARR, Val, sizeof (ARR) # define rep (I, n) for (I) = 0; (I) <(N ); ++ (I) # define For (I, L, H) for (I) = (l); (I) <= (h); ++ (I) # define Ford (I, h, L) for (I) = (h); (I)> = (l); -- (I) # define L (x) (X) <1 # define R (x) <1 | 1 # define mid (L, R) (L + r)> 1 # define min (X, y) (x) <(y )? (X): (y) # define max (x, y) (x) <(y )? (Y): (x) # define e (x) (1 <(x) # define iabs (x) <0? -(X): (x) # define out (x) printf ("% i64d \ n", x) # define read () freopen ("data. in "," r ", stdin) # define write () freopen (" data. out "," W ", stdout); typedef long ll; const double EPS = 1e-8; const double Pi = ACOs (-1.0); const int INF = ~ 0u> 2; using namespace STD; // 17 vertices on the board. The two vertices form an edge and number the edges, mat [a] [B] indicates the number of the edge a-> B. Int mat [11] [11] = {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0 }, {, 0, 0}, {, 0, 0, 0 },{, 0}, {, 14}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0}, {0, 0, 0, 10, 11, 0}, {0, 0, 0, 13, 0, 16, 0, 17}, {0, 0, 0, 0, 0, 0, 0, 7,152, 0, 52,352,343, 0 }}; // compress the triangle state that consists of three edges into int tri [9] = {155648 }; int full = (1 <18) -1; int max_search (INT state, int Alpha, int ca, int CB); int min_search (INT state, int beta, int ca, int CB ); int new_status (INT old, int seg, Int & CNT) {int _ new = old | seg; For (INT I = 0; I <9; ++ I) {If (old & tri [I])! = Tri [I] & (_ New & tri [I]) = tri [I]) {CNT ++ ;}} return _ new ;} int max_search (INT state, int Alpha, int ca, int CB) {If (Ca> = 5) return 1; if (CB> = 5) Return-1; if (State = Full) return Ca> cb? 1:-1; int _ new, seg, TMP, Ta, ANS =-1; int bit = (~ State) & Full; while (BIT) {seg = bit & (-bit); TA = Ca; _ new = new_status (State, seg, TA ); if (Ta> Ca) TMP = max_search (_ new, Alpha, Ta, CB); else TMP = min_search (_ new, ANS, Ta, CB ); if (TMP> ans) ans = TMP; If (TMP> = alpha) return ans; // A can win, directly return bit-= seg ;} return ans;} int min_search (INT state, int beta, int ca, int CB) {If (Ca> = 5) return 1; if (CB> = 5) return-1; if (State = Full) r Eturn Ca> cb? 1:-1; int _ new, seg, TMP, TB, ANS = 1; int bit = (~ State) & Full; while (BIT) {seg = bit & (-bit); TB = CB; _ new = new_status (State, seg, Tb ); if (Tb> CB) TMP = min_search (_ new, beta, CA, Tb); else TMP = max_search (_ new, ANS, CA, Tb ); if (TMP <ans) ans = TMP; If (TMP <= beta) return ans; // B has the status bit-= seg;} return ans ;} int main () {// read (); int t, n, a, B, ANS, CAS = 0; int CNT, status, CA, CB, Ta, TB; cin> T; while (t --) {CIN> N; CNT = stat US = 0; CA = CB = 0; while (n --) {CIN> A> B; TA = Ca; TB = CB; status = new_status (status, 1 <mat [a] [B], (CNT & 1 )? CB: Ca); If (TA = Ca & TB = CB) CNT ++;} If (CNT & 1) ans = min_search (status,-1, CA, CB); // turn B to else ans = max_search (status, 1, CA, CB); // turn a to printf ("game % d: % s \ n ", + + cas, ANS = 1? "A wins.": "B wins.");} return 0 ;}

 

 

 

 

 

 

 

 

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.