Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Playing.

Similar presentations


Presentation on theme: "Game Playing."— Presentation transcript:

1 Game Playing

2 Introduction Why is game playing so interesting from an AI point of view? Game Playing is harder then common searching The search space is too large for complete searches We are facing an unpredictable opponent Games are adversarial search problems Solution is strategy, contingency plan. There are time limits Game playing is considered to be an intelligent activity.

3 Introduction Two-Person games How do we think when we play e.g. Chess?
If I move my queen there, then my opponent has to move his knight there and then can I move my pawn there and check mate. We are making some assumptions We want our best move The opponent wants his best move The opponent has the same information as we Our opponent wants to win

4 Game Trees Game trees are used to represent two-player games.
Alternate moves in the game are represented by alternate levels in the tree (plies). Nodes in the tree represent positions. Edges between nodes represent moves. Leaf nodes represent won, lost or drawn positions. For most games, the game tree can be enormous.

5 Game Trees This is an example of a partial game tree for the game tic-tac-toe. Even for this simple game, the game tree is very large.

6 Assumptions In talking about game playing systems, we make a number of assumptions: The opponent is rational – will play to win. The game is zero-sum – if one player wins, the other loses. Usually, the two players have complete knowledge of the game. For games such as poker, this is clearly not true.

7 Minimax Minimax is a method used to evaluate game trees.
A static evaluator is applied to leaf nodes, and values are passed back up the tree to determine the best score the computer can obtain against a rational opponent.

8 MiniMax Games with two players MIN and MAX are a search problem with:
Initial state Successor function Terminal test / state Utility function (objective / payoff)

9 MiniMax Utility function Is assumed to be in relation with Max
What is good for max is always bad for min. E.g. if max wins then min lose In chess the utility function might be. -1 if min wins 0 for a draw 1 if max wins In other games, e.g. Othello the utility function might be more advanced. utility = number of my pieces – number of his pieces

10 MiniMax Simple Games If we play e.g. TicTacToe or NIM, we can generate a complete search tree Some leafs in the tree will end up with max winning and some with min winning For more complex games a complete search tree is impossible. But that’s a question for the near future.

11 MiniMax Searching with minimax
We use depth first search to reach down to the leafs first When we reach a leaf, we evaluate the current state by a utility function and then returns the result to the parent node. If we are not in a leaf and have evaluated all children. If it, from this state, is max move, then return the highest utility If it is a min move return the lowest utility.

12 MiniMax Example of MiniMax – 1st version of NIM
The rules of NIM are as follows We start with a number of sticks in a group (7) On each move, a player may pick up 1, 2, or 3 sticks The last player to make a legal move wins

13 MiniMax Example of MiniMax – 2nd version of NIM
The rules of NIM are as follows We start with a number of sticks in a group On each move, a player must divide a group into two smaller groups Groups of one or two sticks can’t be divided The last player to make a legal move wins

14 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

15 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

16 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

17 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

18 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

19 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

20 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

21 MiniMax NIM Search tree Max moves Min moves Max moves Min moves 6 1-5
2-4 3-3 Min moves 1-1-4 1-2-3 2-2-2 Max moves Min moves

22 Minimax – Animated Example
3 6 The computer can obtain 6 by choosing the right hand edge from the first node. Max 5 1 3 6 2 7 6 Min 5 3 1 3 7 Max 6 5

23 Bounded Lookahead For trees with high depth or very high branching factor, minimax cannot be applied to the entire tree. In such cases, bounded lookahead is applied: When search reaches a specified depth, the search is cut off, and the static evaluator applied. Must be applied carefully: In some positions a static evaluator will not take into account significant changes that are about to happen.

24 Static Evaluation Functions
Since game trees are too large to be fully searched, it is important to have a function to statically evaluate a given position in the game. A static evaluator assigns a score to a position: High positive = computer is winning Zero = even game High negative = opponent is winning It is most important that a static evaluator will give a better score to a better position – the actual values are not so important.

25 Searching Game Trees Exhaustively searching a game tree is not usually a good idea. Even for a game as simple as tic-tac-toe there are over 350,000 nodes in the complete game tree. An additional problem is that the computer only gets to choose every other path through the tree – the opponent chooses the others.


Download ppt "Game Playing."

Similar presentations


Ads by Google