420 likes | 605 Views
Game Playing II and on to Logic. Introduction to Artificial Intelligence CS440/ECE448 Lecture 8 SECOND HOMEWORK OUT TODAY. Last lecture. Deterministic games Minimax pruning Chapter 6 Non-deterministic games Introduction to logic The Wumpus world Elements of logic Reading
E N D
Game Playing IIand on to Logic Introduction to Artificial Intelligence CS440/ECE448 Lecture 8 SECOND HOMEWORK OUT TODAY
Last lecture • Deterministic games • Minimax • pruning Chapter 6 • Non-deterministic games • Introduction to logic • The Wumpus world • Elements of logic Reading • Chapters 6 and 7
Minimax • Perfect play for deterministic, perfect-information games. • Max’s strategy: choose action with highest minimax value ) best achievable payoff against best play by min. • Consider a 2-ply (two step) game: Max want’s largest outcome --- Min want’s smallest.
Evaluation Function For chess, typically linear weighted sum of features Eval(s) = w1 f1(s) + w2 f2(s) + ... + wn fn(s) e.g., w1 = 9 with f1(s) = (number of white queens) - (number of black queens) w2 = 5 with f2(s) = (number of white rooks) - (number of black rooks)
=3 =2 2 14 5 X X 14 2 5 2 Pruning Example 3 MAX =3 MIN 12 8 3
How is the search tree pruned? • is the best value (to MAX) found so far. • If V, then the subtree containing V will have utility no greater than V. Prune that branch • can be defined similarly from MIN’s perspective.
Properties of Pruning does not affect final result. Good move ordering improves effectiveness of pruning. With “perfect ordering”, time complexity = O(bm/2): • doubles depth of search; • can easily reach depth 8 and play good chess. A simple example of the value of reasoning about which computations are relevant (a form of metareasoning).
Deterministic games in practice Checkers: In 1994 Chinookended 40-year-reign of human world champion Marion Tinsley. Used an endgame database defining perfect play for all positions involving 8 or fewer pieces on the board, a total of 443,748,401,247 positions. Chess:Deep Blue defeated human world champion Gary Kasparov in a six-game match in 1997. Deep Blue searches 200 million positions per second, uses very sophisticated evaluation, and undisclosed methods for extending some lines of search up to 40 ply. Othello: Human champions refuse to compete against computers, who are too good. Go: Human champions refuse to compete against computers, who are too bad. In Go, b > 300, so most programs use pattern knowledge bases to suggest plausible moves.
Minimax for nondeterministic games • For min node, compute min of children. • For chance node, compute weighted average of children. • For max node, compute max of children. 3
Minimax for nondeterministic games ctd. Expectiminimax maximize expected value (average) of utility against a perfect opponent. Pseudocode is just like Minimax, except we must also handle chance nodes: ... ifstate is a chance node then return average of ExpectiMinimax-Value of Successors(state) ... A version of pruning is possible but only if the leaf values are bounded.
Function MINIMAX-VALUE (state, game) returns a utility value If TERMINAL-TEST[game](state) then return UTILITY[game](state) else if MAX is to move in state then return the highest MINIMAX-VALUE of Successors[state] else return the lowest MINIMAX-VALUE of Successors[state] Function EXPECTIMINIMAX-VALUE (state, game) returns a utility value If TERMINAL-TEST[game](state) then return UTILITY[game](state) else ifstate is a chance node then return average of EXPECTIMINMAX-VALUE of Successors(state) else if MAX is to move in state then return the highest EXPECTIMINIMAX-VALUE of Successors[state] else return the lowest EXPECTIMINIMAX-VALUE of Successors[state]
Nondeterministic games in practice • Dice rolls increase branching factor b: • 21 possible rolls with 2 dice, • Backgammon 20 legal moves. • depth 4 20 £ (21 £ 20)3 1.2 £ 109. • As depth increases, probability of reaching a given node shrinks value of look ahead is diminished. • pruning is much less effective. • TDGammon uses depth-2 search + very good Eval plays at world-champion level.
Digression: Exact values DO matter • Behavior is preserved only by positive linear transformation of Eval. • Hence Eval should be proportional to the expected payoff.
Games Summary • Games are fun to work on (and dangerous) ! • They illustrate several important points about AI: • perfection is unattainable must approximate; • good idea to think about what to think about; • uncertainty constrains the assignment of values to states. • “Games are to AI as grand prix racing is to automobile design”.
Logic as a tool How can we formalize our knowledge about the world so that: • We can reason about it. • We can do sound inference. • We can prove things. • We can plan actions. • We can understand and explain things.
Knowledge bases Inference Engine Knowledge Base Domain-independent knowledge Domain-specific content • Knowledge base = set of sentences in a formal language. • Declarative approach to building an agent or other system: • Tell it what it needs to know • Alternative is a learning approach, but we will do that later. • Answers should follow from the KB. • Agents or systems can be viewed at the knowledge level, i.e., what they know, regardless of how implemented. • Or at the implementation level, i.e., data structures in KB and algorithms that manipulate them.
THE WUMPUS Introducing
Goals: Get gold back to the start without entering it or wumpus square. Percepts: Breeze, Glitter, Smell. Actions: Left turn, Right turn, Forward, Grab, Release, Shoot. Environment Squares adjacent to wumpus are smelly. Squares adjacent to pit are breezy. Glitter if and only if gold is in the same square. Shooting kills the wumpus if you are facing it. Shooting uses up the only arrow. Grabbing picks up the gold if in the same square. Releasing drops the gold in the same square. The Wumpus World
Wumpus World Characteristics • Is the world deterministic? Yes --- outcomes exactly specified. • Is the world fully accessible? No --- only local perception of square you are in. • Is the world static? Yes --- Wumpus and Pits do not move. • Is the world discrete? Yes.
Exploring a Wumpus World Haven’t fallen into a pit. Haven’t been eaten by a Wumpus. A
Exploring a Wumpus World Since • no Stench, • no Breeze, neighbors are safe (OK). A
Exploring a Wumpus World We move and feel a breeze. A
Exploring a Wumpus World We can infer the following. Note: square (1,1) remains OK. A
Exploring a Wumpus World Move and smell the stench of the wumpus!! What can we conclude? A
But, can the 2,2 square really have either a Wumpus or a pit? And what about the other P? and W? squares Exploring a Wumpus World A NO!
Exploring a Wumpus World That was a complex inference! Kind of like Minesweeper OK A
Exploring a Wumpus World … And the exploration continues onward until the gold is found. … A A
A tight spot • Breeze in (1,2) and (2,1) no safe actions. • Assuming pits uniformly distributed, (2,2) is most likely to have a pit.
W? W? Another tight spot Smell in (1,1) cannot move. Can use a strategy of coercion: • shoot straight ahead; • wumpus was there dead safe. • wumpus wasn't there safe.
Logic in general • Logicsare formal languages for representing information such that conclusions can be drawn. • Syntax defines the sentences in the language • Semantics define the ``meaning'' of sentences; i.e., define truth of a sentence in a world. • For example, the language of arithmetic • x + 2 y is a sentence. • x + y > is not a sentence. • x + 2 yis true iff the number x+2 is no less than the number y. • x + 2 yis true in a world where x = 7, y =1. • x + 2 y is false in a world where x = 0, y= 6.
Types of logic • Logics are characterized by what they commit to as ``primitives'' • Ontological commitment: what exists - facts? objects? time? beliefs? • Epistemological commitment: what states of knowledge?
Entail Sentences KB Semantics Follows Facts Facts Entailment Sentences Logical Representation Semantics World A knowledge base is a collection of sentences. An entailed sentence is true, given that the old sentences in the knowledge base are true.
Potential models of the Wumpus world A model is an instance of the world. A model of a set of sentences is an instance of the world where these sentences are true.