Basic Game Theory and AI Search by andrew


									ECE 461 – Software Engineering February 1 & 3 Sessions

Basic Game Theory and AI Search
“Game theory is to games of strategy what probability theory is to games of chance.” – Two-Person Game Theory, Anatol Rapoport, 1966 Formal Definition of a Game  A game has at least two players.  Example: Solitaire is not considered a game by game theory.  An instance of a game begins with a player choosing from a set of specified (by the game rules) alternatives. This choice is called a move.  After the first move is made, the new situation determines which player is to make the next move and the alternatives available to that player.  Example: In many two-player board games, the player making the next move is simply the other player.  Example: In many multi-player card games, the player making the next move depends on who dealt, who took the last trick, won the last hand, etc.  The moves made by a player may or may not become known to the other players. Games in which all the moves of all players are known to everyone are called games of perfect information.  Example: Most board games are games of perfect information.  Example: Most card games are not games of perfect information.  Every instance of the game must end.  When an instance of a game ends, each player receives a payoff. A payoff is a value associated with each player's final situation. A zero-sum game is one in which the elements of the payoff matrix sum to zero.  Example: In chess, win = 1 point, draw = ½ point, loss = 0 points.  Example: In a typical zero-sum game, win = 1 point, draw = 0 points, loss = -1 points. Introduction to Evaluation Functions Nine Men's Morris is a game of perfect information, but a player does not know, in general, what move their opponent will make in response to their move; there are few situations where only one move is possible. Thus, a player must consider several possible futures. An AI player uses a tree data structure to examine the future. The vertices of the tree represent board positions, with the root of the tree being the current position. The edges of the tree represent moves. The branching factor of this tree can be very large, so symmetry often is used to reduce it. For example, there are 24 possible moves to begin an instance of Nine Men's Morris, but symmetry reduces the branching factor to 6:


When Player One moves, they must choose from among those 6 positions (ignoring the symmetric choices). How? Expanding the tree all the way to the end of the game to see the payoff would require too much time and memory. Therefore, the player must estimate which move will lead to the best payoff. This estimation requires an evaluation function to compare alternative moves. The evaluation function may take into consideration such factors as the number of pieces that each player has remaining, the number of Mills that each player has, whether a move could lead to a Mill after the next move, the utility of controlling a particular location on the board, etc. An evaluation function computes a positive value for a position advantageous to a player, and a negative value for a position advantageous to their opponent. Selecting the best move means maximizing the evaluation function. Suppose we want an evaluation function for the first move of the game. One possible function evaluates to:







This function simply uses the number of lines that meet at the position of the piece. The function assumes that a piece placed at a 4-way intersection will be most useful in the sliding phase of the game. There are no negative values because none of these alternatives are clearly advantageous to the opponent. Let us assume that Player Two responds using the same strategy, yielding this board position:

The simple function now appears inadequate: there are two 4-way intersections remaining, but maybe it is better to use one of the corners next to Player One's first piece in order to create a near-Mill (two adjacent pieces that could become a Mill with the player's next move). Let us assume that Player One creates a near-Mill:

Now Player Two must decide whether to (i) place a piece on a 4-way intersection, (ii) create a near-Mill, or (iii) prevent Player One's near-Mill from becoming a Mill. As you can see, writing a good evaluation function is quite complicated (and this example did not even consider the sliding phase, selecting which opponent's piece to remove after achieving a Mill, etc.).


Simplifying Evaluation Functions and AI Search The example above became complicated when the evaluation function tried to consider the future. Instead, we can continue using an evaluation function that considers only the current board position, and then let AI search techniques consider the future. The following function considers only the current board position from the perspective of Player One: eval(board) = number of Player One's pieces on the board - number of Player Two's pieces on the board + number of Mills for Player One - number of Mills for Player Two + (number of slide moves available to Player One / 32) - (number of slide moves available to Player Two / 32)

Min-Max Search This search strategy assumes that the opponent plays optimally. Because we are using positive values to indicate a good position for Player One and negative values to indicate a good position for Player Two, the position with the maximum value is best for Player One and the position with the minimum value is best for Player Two. Min-Max search alternates between Min and Max depending on what level of the tree is being considered. For example:

--max-... --min--

The search can be implemented as a recursive function, but must be cutoff at a certain depth, otherwise it will require too much time to return an answer. There are several possible cutoff strategies:
 

Simple Depth Cutoff – Once the recursion reaches a depth d, the board positions at level d are treated as final positions such that the value of their evaluation function begins to propagate back up the call stack. Depth Cutoff with Pruning – Same as the simple depth cutoff, but if a board position at depth i < d has a “sufficiently negative” evaluation function, then the recursion does not go deeper. The assumption is that if the position is that bad for Player One, then additional moves cannot improve their chance of winning.

Alpha-Beta Pruning One way to increase search depth without requiring more time is to prune irrelevant branches of the tree. Alphabeta search updates two values during the search.
● ●

alpha – the value of the best (highest-value) choice found so far using max. beta – the value of the best (lowest-value) choice found so far using min.

As soon as the value of the current position is known to be worse than the best value found so far along that path, the search is pruned and the rest of that branch is ignored. By ignoring irrelevant branches, the time saved can be spent investigating the other branches that really matter.


To top