Sunteți pe pagina 1din 14

Game Tree

Chapter-3

Game Tree
A finite game is a game in which every possible combination of moves leads to an end of the game. That is, it is impossible for the game to go on forever! A game tree is a directed graph whose nodes are positions in a game and whose edges are moves. In a game tree, every node corresponds to a board position. The children of each node N are the different positions that result from a single move in N, made by the player whose turn it is at N.

How to play a game


A way to play such a game is to: Consider all the legal moves you can make. Each move leads to a new board configuration (position). Evaluate each resulting position and determine which is best Make that move. Wait for your opponent to move and repeat? Key problems are: Representing the board Generating all legal next boards Evaluating a position Look ahead

Game Trees
Problem spaces for typical games represented as trees. Root node represents the board configuration at which a decision must be made as to what is the best single move to make next. (not necessarily the initial configuration) Evaluator function rates a board position. f(board) (a real number). Arcs represent the possible legal moves for a player (no costs associates to arcs Terminal nodes represent end-game configurations (the result must be one of win, lose, and draw, possibly with numerical payoff)

If it is my turn to move, then the root is labeled a "MAX" node; otherwise it is labeled a "MIN" node indicating my opponent's turn. Each level of the tree has nodes that are all MAX or all MIN; nodes at level i are of the opposite kind from those at level i+1 Complete game tree: includes all configurations that can be generated from the root by legal moves (all leaves are terminal nodes) Incomplete game tree: includes all configurations that can be generated from the root by legal moves to a given depth (looking ahead to a given steps)

Game Tree
The root of the tree is the starting position, or the position from which we want to find a move. The leaves (nodes which have no children) in the game tree correspond to terminating positions; positions in which the game has ended. A portion of the game tree for "Tic-tac-toe" is shown in Figure. Note that each level in the tree pertains to the moves made by one particular player.

Importance
Game trees are important in artificial intelligence because one way to pick the best move in a game is to search the game tree using the minimax algorithm or its variants.

An example (partial) game tree for Tic-Tac-Toe

f(n) = +1 if the position is a win for X. f(n) = -1 if the position is a win for O. f(n) = 0 if the position is a draw.

Some Chess Positions and their Evaluations

Minimax Rule
Goal of game tree search: to determine one move for Max player that maximizes the guaranteed payoff for a given game tree for MAX Regardless of the moves the MIN will take The value of each node (Max and MIN) is determined by (back up from) the values of its children MAX plays the worst case scenario: Always assume MIN to take moves to maximize his payoff (i.e., to minimize the pay-off of MAX) For a MAX node, the backed up value is the maximum of the values associated with its children For a MIN node, the backed up value is the minimum of the values associated with its children

Game Tree
Each node represents a board position, and the children of each node are the legal moves from that position. To score each position, we will give each position which is favorable for player 1 a positive number (the more positive, the more favorable). Similarly, we will give each position which is favorable for player 2 a negative number (the more negative, the more favorable). In our tic tac toe example, player 1 is 'X', player 2 is 'O', and the only three scores we will have are +1 for a win by 'X', -1 for a win by 'O', and 0 for a draw.

A player can play perfect tic-tac-toe if they choose the move with the highest priority in the following table[3]. 1) Win: If you have two in a row, play the third to get three in a row. 2) Block: If the opponent has two in a row, play the third to block them. 3) Fork: Create an opportunity where you can win in two ways. 4) Block Opponent's Fork: Option 1: Create two in a row to force the opponent into defending, as long as it doesn't result in them creating a fork or winning. For example, if "X" has a corner, "O" has the center, and "X" has the opposite corner as well, "O" must not play a corner in order to win. (Playing a corner in this scenario creates a fork for "X" to win.) Option 2: If there is a configuration where the opponent can fork, block that fork. 5) Center: Play the center. 6) Opposite Corner: If the opponent is in the corner, play the opposite corner. 7) Empty Corner: Play an empty corner. 8) Empty Side: Play an empty side.

S-ar putea să vă placă și