Game theory is a branch of artificial intelligence. As the name implies is the algorithm of chess. Of course, the extended application may be used not only for playing chess, but also for playing games or simulating war strategies.
Game of the basic algorithm is also simulated human thinking, such as when the next step through all possible to seek the most advantageous steps, but a way if not a step to win the other side may take the most unfavorable to their own way, if the other party can not win, and then further consider the other side of the law of their best response is what, So recursively go down and find the odds of each path and take the best strategy.
Pseudo-code can do this:
function Find_best (P)
{
var Bestsolution=worst;
For every possible step S after P:
if (Willwin (s))
return S;
else if (Willend (S))
if (S >= bestsolution) bestsolution = s;
Else
var w= find_worse (S);
if (W >= bestsolution) bestsolution =w;
return bestsolution;
}
The Find_worse function should have similar logic, the only difference being that the Find_worse judgment logic, in turn, finds the most advantageous solution to the other.
The simplest algorithm is described above, in fact, in a slightly complex board game, this algorithm does not work. The reason for this is that the algorithm recursively iterates through all the possibilities, and in many board games, this is time-consuming. If you pre-calculate all possible and too much storage space. This often requires recursion to a specific depth to end, and because often can not search for the final win or negative outcome of the game, you must have an evaluation function in either state to evaluate the score. For further optimization, you might want to crop the traversed path. For example, the Gobang does not consider solutions that are too far from the existing ones, and so on.
Since we only study the simplest case today, the above algorithm can solve the problem. We take the TIC as an example, we can traverse all the cases, and the recursive algorithm directly does not cause stack overflow-a total of only 9 steps in depth:).
Here's the code: http://www.luoxq.com/tic.html
The simplest example of game theory Tactictoe