Introduction to Cognitive Science

Minimax Exercise
Due: Tuesday, Dec. 1

Contents

Minimax is an algorithm for playing two-player games (it generalizes to multi-player games as well). It was first proposed by Shannon, in 19501, as an algorithm for playing chess. Alan Newell and Herb Simon actually used the algorithm to write the first chess-playing program2. The topic is covered in detail in any introductory AI textbook.

Minimax proceeds as follows:

  1. Pick a ply, which is the number of moves the algorithm will look ahead.
  2. From the current state of the game, generate all the possible next moves. This is the first ply set of possible moves. For each first ply move, generate all the possible next moves. The is the second ply, and so on. Generate all the ply until the chosen depth is reached. This final set consitutes the set of all possible game positions that could result from the starting point.
  3. For each member of the final ply set, compute a heuristic. In minimax, a heuristic is a number that represents the relative strategic value of a game state from the perspective of the computer. This number should be negative if the state represents an advantage for the opponent, positive if the state represents an advantage for the computer, and zero if there is no discernable advantage. Note that heuristics should also be reflexive; if the sides were switched the value would just change signs.
  4. Now it gets complicated. Since the computer does not have control over every alternate move (because the opponent does), the algorithm must predict what the opponent will do. In order to do this, the algorithm assumes, based on the reflexive nature of the heuristic, that its opponent will always choose the move that represents the worst possible situation for the computer. Therefore, on turns which represent the computer's move, the algorithm selects the move that results in the highest, or maximum, heuristic value. On turns which represent the opponents move, the algorithm selects the move that results in the lowest, or minimum, heuristic value.
  5. The values are passed up through the intermediate moves. At each level in the tree that results from generating all the ply, a node gets a value from the selected sucessor.
  6. At the top level, the result that corresponds to the best next move is chosen.

Minimax suffers from exponential explosion of number of nodes or states - that is, the number of states to consider goes up exponentially with the number of ply. Consider the connect-4 game, in which, at least for the first six moves, every state has seven possible next states, because there are seven possible moves at each point in the game (unless a column is full). The number of states to consider for two ply is 7*7 or 49. For three ply it's 7*7*7 or 343, four ply is 2401, five ply is 16,807 and so on. In other words, for connect-4, the number of nodes to consider is roughly 7n, where n is the number of ply. In general, this is what defines an exponential algorithm - the number of alternatives to consider increases exponentially.

The heuristic in game-playing is the key element of minimax. It is within this computation that the knowledge or understanding of the game, the strategies themselves, is encoded. Most modern heuristics use feature-detectors. Feature-detectors were first proposed in the Pandemonium system of Oliver Selfridge3.

Feature-detectors are individual modules which are responsible for searching a space (in this case, searching a game board) for a particular pattern (or feature). When present, the detector "shouts" at a level dependant on both its strength (which is configurable) and it's frequency in the space. In other words, the more times a pattern appears, the louder the detector will shout.

Of course, in the heuristic evaluation there is no shouting, only a sum. Rather than listen to the loudest detector, each detector yeilds a number, and the heuristic function takes the sum of all these numbers. The number each feature detector returns for a specific state will be the product of its strength (or weight) and the frequency (the number of times the feature appears in that state).

A feature is a pattern that is evident in a particular state of the game. For example, one important connect-4 feature is the middle-column feature. This feature is present for each peice in the middle column of the board. This is an important column in connect-4 play, because any horizontal or diagonal four-in-a-row sequence must include the middle column.

One special kind of features are color-specific features. In the examples we will be doing, all features are color-specific. That means that the feature is only present for pieces of a single color. Furthermore, color-specific features are differential. The frequency of a differential feature is actually the difference between the number of occurrences of the feature for peices of the computers and the number of occurrences of the feature for peices of the opponent. For example, in a game board in which the computer has three peices in the middle column and the opponent has two, the frequency of the middle-column feature will be 1 (3 - 2). If, conversely, the game board had two peices of the computer's in the middle column and three of the opponent's, the frequency of the middle-column feature will be -1 (2 - 3). Note that this maintains the reflexive property required of minimax heuristics.

Most features are a bit more complicated than simply counting the number of peices in a column. For example, in connect-4 we have a three-in-a-row-1-end feature, which is present whenever there are three peices of a single color in a row (horizontally, vertically, or diagonally) and an open space bordering one of the ends.

References

  1. Shannon, C.E. 1950. Programming a computer for playing chess. Philisophical Magazine (Series 7), vol. 41, pp. 256-275.

  2. Newell, A., Shaw, J., and Simon, H. 1958. Chess-playing programs and the problem of complexity. IBM J. Research and Development, 2, pp 320-355.

  3. Selfridge, O., and Neisser, U. 1963. Pattern recognition by machine. In Feigenbaum and Feldman, eds., Computers and Thought. Pp. 237-250. McGraw-Hill, NY.