Docsity

Artificial intelligence advanced alogs, Summaries of Artificial Intelligence

Toggle sidebar
bg1
Two Player Game Playing through
Adversarial Search
In this chapter we cover competitive environments, in
which the agents’ goals are in conflict, giving rise to
adversarial search problems—often known as games.
We begin with a definition of the optimal move and an
algorithm for finding it. We then look at techniques for
choosing a good move when time is limited. Pruning
allows us to ignore portions of the search tree that make
no difference to the final choice, and heuristic evaluation
functions allow us to approximate the true utility of a
state without doing a complete search.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download Artificial intelligence advanced alogs and more Summaries Artificial Intelligence in PDF only on Docsity!

Two Player Game Playing through

Adversarial Search

In this chapter we cover competitive environments, in

which the agents’ goals are in conflict, giving rise to

adversarial search problems—often known as games.

We begin with a definition of the optimal move and an

algorithm for finding it. We then look at techniques for

choosing a good move when time is limited. Pruning

allows us to ignore portions of the search tree that make

no difference to the final choice, and heuristic evaluation

functions allow us to approximate the true utility of a

state without doing a complete search.

GAME TREE

The initial state, ACTIONS function, and RESULT function

define the game tree for the game—a tree where the nodes

are game states, and the edges are moves. Figure 5.1 shows

part of the game tree for tic-tac-toe.

From the initial state, MAX has nine possible moves. Play

alternates between MAX’s placing an X and MIN’s placing an

O until we reach leaf nodes corresponding to terminal states

such that one player has three in a row, or all the squares

are filled.

The number on each leaf node indicates the utility value of

the terminal state from the point of view of MAX; high values

are assumed to be good for MAX and bad for MIN (which is

how the players get their names).

Size of Game

Tree

For tic-tac-toe, the game tree is relatively small—

fewer than 9! = 362, 880 terminal nodes. But for

chess there are over 10power40 nodes, so the

game tree is best thought of as a theoretical

construct that we cannot realize in the physical

world. But regardless of the size of the game tree,

it is Player’s job to search for a good move.

We begin with a definition of the optimal move and an algorithm for finding it. We PRUNING then
look at techniques for choosing a good move when time is limited. Pruning allows us to ignore
portions of the search tree that make no difference to the final choice, and heuristic evaluation
functions allow us to approximate the true utility of a state without doing a complete search.
We first consider games with two players, whom we call MAX and MIN for reasons that will soon
become obvious. MAX moves first, then they take turns until the game ends. At the end of the
game, points are awarded to the winning player and penalties are given to the loser. A game can be
formally defined as a kind of search problem with the following elements:
S0: The initial state specifies how the game is set up at the start.

**- PLAYER(s): Defines which player has the move in a state.

  • ACTIONS(s): Returns the set of legal moves in a state.
  • RESULT(s, a): The transition model defines the result of a move.**
TERMINAL TEST • TERMINAL-TEST(s): A terminal test, which is true when the game is
over and false otherwise.
TERMINAL STATES The States where the game has ended are called terminal states.

- UTILITY(s, p): A utility function (also called an objective function or payoff function): It

can be applied to the terminal state of the game, and it gives the numerical value of the
outcome of the game. The final numeric value for a game that ends in terminal state s for a
player p. It could be +1, 0, or -1 in games like Tic-tac Toe, chess etc. It could be from 0 to
+192 in the game of Backgammon.

Finding Solution by MinMax Algorithm MINMAX algorithm A Simple Descriptive Definition The minimax algorithm computes the minimax decision from the current state. It uses a simple recursive computation of the minimax values of each successor state, directly implementing the defining equations. The recursion proceeds all the way down to the leaves of the tree, and then the minimax values are backed up through the tree as the recursion unwinds. For example, in Figure 5.2, the algorithm first recurses down to the three bottom left nodes and uses the UTILITY function on them to discover that their values are 3, 12, and 8, respectively. Then it takes the minimum of these values, 3, and returns it as the backed up value of node B. A similar process gives the backed-up values of 2 for C and 2 for D. Finally, we take the maximum of 3, 2, and 2 to get the backed-up value of 3 for the root node.

Game Strategies in Intelligent Techniques. Second Version The technique embodied in this program #1 does not appear to meet any of our requirements for a good AI technique. Let's see if we can do better. First human player use strategies. An example is given below:

  • (^) Initial Strategy
    • Move to corner square
    • Move to middle square
  • (^) Move Strategy
    • (^) I am winning – go for that
    • (^) My opponent winning – block opponent
    • (^) Rest – call Make1-corner square strategies
    • (^) Middle square – call Make 2-non-corner square strategies

is a possible win by multiplying the values of its squares together. If the product is 18 (3 x 3 x 2), then X can win. If the product is 50 (5 x 5 x 2), then 0 can win. If we find a winning row, we determine which element is blank and return the number of that square. Go( n ) Makes a move in square n. This procedure sets Board[ n ] to 3 if Turn is odd, or 5 if Turn is even. It also increments Turn by one. 3 3 2 5 5 2

Algorithm for Intelligent System Playing Tic-Tac-Toe Initialize all nine squares to 2. i= Player i and i+1 chose Make 2 or Make 1 and call them alternately. After the third move each player calls ‘possiblewin’ to check if he is winning to make a winning move or the opponent is winning to block him. Take an action accordingly. If possiblewin does not give winning move, then call Make 1 or Make 2 which ever has been selected by the player. Process continue with players alternate, till one player wins or the game is draw.

EXERCISE TO BE DONE BY STUDENTS Steps if X moves first and starts with Make 1 X 1 (3) 2 O 4 (5) 3 X 7 (3) 4 X 9 (3) 5 O 2 (5) 6 O 8 (5) 7 O 6 (5) 8 X 5 (3) 9 X 3 (3)

Comments on Program # This program is not quite as efficient in terms of time as the first one since it has to check several conditions before making each move. But it is a lot more efficient in terms of space. It is also a lot easier to understand the program's strategy or to change the strategy if desired. But the total strategy has still been figured out in advance by the programmer. Any bugs in the programmer's tic-tac-toe playing skill will show up in the program's play. And we still cannot generalize any of the program's knowledge to a different domain, such as three-dimensional tic-tac- toe. Very importantly, it takes too much search time to check every row and column. Improvements in Program #3: Use of Magic Square:

Differences with program #2:
1. The numbering of the board produces a magic square: all the rows,
columns and diagonals sum to 15. We again represent the board as a nine-
element vector, but this time we assign board positions to vector elements as
follows Using magic squares, shown below:
  1. A new Possible win function is used which is explained through an example below in the next few PowerPoint slides. This means that we can simplify the process of checking for a possible win. In addition to marking the board as moves are made, we keep a list, for each player, of the squares in which he or she has played. To check for a possible win for one player, we consider each pair of squares owned by that player and compute the difference between 15 and the sum of the two squares. If this difference is not positive or if it is greater than 9, then the original two squares were not collinear and so can be ignored. Otherwise, if the square representing the

Corner Center X 1 O 1 5

This is O’s Turn The next Turn is for X 8 3 4 1 5 O 1 9 6 7 2 Player  O 1 Action  1 Initial Step O Calls make2 which assigns O 1 to central square ‘5’