The extremely small game tree (MinimaxGameTree) is used to compile game programs between computers. these programs are used by two gamers to take one step at a time. Of course, all possible steps constitute a tree structure. For example, the figure below shows an MGT, which represents all possible steps in the first two steps of the Tic-Tac-Toe game.
The Minimax Game Tree, short for MGT, is used to compile Game programs between computers. these games are rotated by two gamers and each step is taken. Of course, all possible steps constitute a tree structure. For example, the figure below shows an MGT, which represents all possible steps in the first two steps of the Tic-Tac-Toe game. Tic-Tac-Toe is a simple 9-court game. The gameplay is to use 3*3's 9-square grids. each person can see who first connects three lines, which is called ttt.
We have noticed that this tree is different from other tree structures, such as binary trees, 2-3 trees, and heap trees. according to the game rules, a MGT node may have many subnodes.
The tree in the figure has three levels, but in encoding, the level of the extremely large tree is usually called layer (level, layer: ply ). In each layer, the switch points to another player.
For a complete extremely small tree, the computer can traverse each step until the best step is found. Of course, as you can see in the example, just a few steps will make the tree very huge, and for a common computer, the five steps of prediction will be enough to make it crash quickly. Therefore, for large-scale game games such as chess and Go games, computer programs cannot traverse all the results. Instead, they can only judge the outcome through several top-level steps. In addition, programmers have also proposed many algorithms and techniques to reduce the number of nodes, such as Alpha-Beta pruning, Negascout search algorithm, and MTD (full name: memory enhanced Test Driver (Memory enhancement Test Driver) method.
Of course, MGT cannot predict the possible steps of all computer games. For example, in poker games, the computer will be very hard to judge the opponent's movements, because the computer cannot see the cards in the opponent's hand. Therefore, MGT is the best choice for games that both gamers can see in all forms of games. These games include International Checkers, wuziqi, chess, and Go games called games of perfect information ).
The extremely small game tree is named after a simple algorithm that depicts this structure. Let's assign a score to the results of the ttt game. If the cross (X) wins, the score is 1. If the circle (O) wins, the score is-1. Now, the fork will try to maximize the score, while the circle will try to minimize the score. As a result, the first investigator who studied this problem decided to name the gamer fork max and name the gamer circle min. Therefore, the complete data structure is named as the extremely large (Max) extremely small (Min) game tree.
Extremely small logics are also used in other games, such as chess. However, in these more complex games, the program can only search for a part of the extremely large small tree. because the tree is too large, the program often cannot find the final outcome of the game. Generally, a computer stops searching for several nodes. Then the program evaluates the outcome of the game on a node, and these evaluation results are converted into the score of the game situation. If the computer is the max side, the program will try to maximize the score of the game situation, and assign the maximum value (for example, this value is 1 million) to the winning outcome (will die ). If the computer is min, the program will obviously try to minimize the score and assign the minimum score (for example, -1000 thousand) to the winning outcome ). The two sides of the game will play the game between two maximum values. the closer the value is to which side, the more profitable the game is.
The strategy behind extremely small algorithms assumes that players involved in the game do their best to achieve good results. Therefore, no matter the other party chooses favorable or harmful steps, the computer will select the most advantageous steps according to the opponent's method.
This simple concept is the greatest secret of a great tree. For example, for a max program, no matter how min is done, the best step or step sequence will surely get the highest score. Min will obviously select the results that give it the lowest score.
In a sense,? Bottom? Nodes (bottom-layer node) is the only node that needs to evaluate the position score, because they represent the final outcome. For example, in the game of max, the leaf node is always in the same position. The program assumes that min will select the step action with the lowest score from the possible steps, then the maximum and minimum values of any max node will be equivalent to the lowest score sub-node of the min node.
Finally, like a human chess game, the ability of a program depends on the computer's ability to assess the situation and the depth of the program search. The estimation error of the situation by a chess master is much smaller than that of other amateurs, and the prediction of the board by the chess master is far beyond that of the average person. The computer can also make long-term predictions on the board, and it won't make any mistakes because it will see the response from the opponent due to the mistake.
There are many algorithms that can help extremely small algorithms improve search efficiency. One of them is called the Alpha Beta pruning algorithm. In the search using this algorithm, the number of nodes to be searched by a computer is about the square root of the number of nodes not required by this technology. That is to say, if the program needs to search for four hundred nodes, it only needs to search for 20 nodes after using the new algorithm.
Some other tools include Transposition? Table), records that record the search results are placed in a small table that can be quickly accessed. Generally, different sequence steps may reach the same position (result ). These two locations (results) can be exchanged. This table helps computers understand the current situation of chess and games, because it has been reviewed at the cost of memory access time.
At the same time, these technologies allow computers to search for more nodes and simulate strategic thinking. Although other technologies have begun to emerge (such as neural networks), extremely large trees are still the best heart of such programs.
The extremely small Game Tree (Minimax Game Tree) is used to compile Game programs between computers. these games take turns by two players and each time they take one step. Of course, all possible steps constitute a tree structure. For example, the figure below shows an MGT, which represents all possible steps in the first two steps of the Tic-Tac-Toe game.
The node in each layer usually represents the choice of different players. These two players are usually called MAX and Min ).
For example, if the second layer is Max turn, the third layer is Min turn, and each node on the second layer is Max choice. The relationship between them is OR, each node on the third layer is the choice of Min, and the relationship between them is the same. Based on this tree, the choice that Max wants to make will minimize any choice made in the next Min, that is, the meaning of the word "Minimax", minimizing the biggest benefit of the opponent. So it is different from Maximin to maximize its own benefits.
Because it is often possible to win the Game from the bottom of the Game Tree, and the growth of nodes on the Game Tree is exponential. for example, Deep Blue can search for 12 steps, if there are 10 options for each step, there are also 1 trillion searches at a time, so there are also 10 thousand searches at four steps for ordinary computers, therefore, a scoring system is required to rate the situation. considering that it is a two-person combat, the score ranges from negative infinity to positive infinity. So Marx wants to find the largest score, while Mina wants to find the smallest score.
Here is an example to illustrate the Tic-Tac-Toe game.
'O' indicates the PC and 'x' indicates the player. There are three main functions:
int minSearch( char _board[9] )int maxSearch( char _board[9] )int gameState(char _board[9])
Assume the roles of max and min respectively to find the maximum and minimum values and a scoring function.
The core part of the game is the gameState scoring function:
Three, 100, two, two, 50, a draw, 0, no match, 1
If you do not match the score, the search will continue until the other three states are found.
The source code is attached:
int gameState(char _board[9]){int state;static int table[][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}, };char chess = _board[0]; for (char i = 1; i < 9; ++i) { chess &= _board[i]; } bool isFull = 0 != chess; bool isFind = false;for (int i = 0; i < sizeof(table) / sizeof(int[3]); ++i){chess = _board[table[i][0]]; int j;for (j = 1; j < 3; ++j)if (_board[table[i][j]] != chess)break;if (chess != empty && j == 3){isFind = true; break;}}if (isFind)//got win or losestate = chess == o ? WIN : LOSE;else{if (isFull)//all position has been set without win or losereturn DRAW;else{//finds[0] -> 'o', finds[1] -> 'x'int finds[2] = {0, };for (int i = 0; i < sizeof(table) / sizeof(int[3]); ++i){bool findEmpty = false;chess = 0xff;int j;for (j = 0; j < 3; ++j)if (_board[table[i][j]] == empty && !findEmpty)findEmpty = true;else chess &= _board[table[i][j]]; if ((chess == o || chess == x) && findEmpty) { isFind = true; if (o == chess) ++finds[0]; else ++finds[1]; } } if (finds[0] > 1 && finds[1] < 1) //2 'o' has been founded twice in row, column or diagonal direction state = -(INFINITY / 2) * finds[0]; else if (finds[1] > 1 && finds[0] < 1) //2 'x' has been founded twice in row, column or diagonal direction state = INFINITY / 2 * finds[1]; else //need to search more. state = INPROGRESS; } } return state; }
This article is available at http://www.nowamagic.net/librarys/veda/detail/948.