Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.

Slides:



Advertisements
Similar presentations
Adversarial Search We have experience in search where we assume that we are the only intelligent being and we have explicit control over the “world”. Lets.
Advertisements

For Friday Finish chapter 5 Program 1, Milestone 1 due.
For Monday Read chapter 7, sections 1-4 Homework: –Chapter 4, exercise 1 –Chapter 5, exercise 9.
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
CMSC 671 Fall 2001 Class #8 – Thursday, September 27.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2008.
CS 484 – Artificial Intelligence
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
MINIMAX SEARCH AND ALPHA- BETA PRUNING: PLAYER 1 VS. PLAYER 2.
Artificial Intelligence in Game Design Heuristics and Other Ideas in Board Games.
Search Strategies.  Tries – for word searchers, spell checking, spelling corrections  Digital Search Trees – for searching for frequent keys (in text,
Games CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
G51IAI Introduction to AI Minmax and Alpha Beta Pruning Garry Kasparov and Deep Blue. © 1997, GM Gabriel Schwartzman's Chess Camera, courtesy IBM.
Minimax and Alpha-Beta Reduction Borrows from Spring 2006 CS 440 Lecture Slides.
Artificial Intelligence in Game Design
This time: Outline Game playing The minimax algorithm
Game Playing CSC361 AI CSC361: Game Playing.
1 search CS 331/531 Dr M M Awais A* Examples:. 2 search CS 331/531 Dr M M Awais 8-Puzzle f(N) = g(N) + h(N)
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2006.
Alpha-Beta Search. 2 Two-player games The object of a search is to find a path from the starting position to a goal position In a puzzle-type problem,
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
1 Adversary Search Ref: Chapter 5. 2 Games & A.I. Easy to measure success Easy to represent states Small number of operators Comparison against humans.
CSC 412: AI Adversarial Search
CHAPTER 6 : ADVERSARIAL SEARCH
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
PSU CS 370 – Introduction to Artificial Intelligence Game MinMax Alpha-Beta.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning CPSC 315 – Programming Studio Spring 2008 Project 2, Lecture 2 Adapted from slides of Yoonsuck.
CISC 235: Topic 6 Game Trees.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
Minimax.
Game Playing Chapter 5. Game playing §Search applied to a problem against an adversary l some actions are not under the control of the problem-solver.
Lecture 6: Game Playing Heshaam Faili University of Tehran Two-player games Minmax search algorithm Alpha-Beta pruning Games with chance.
Game Playing.
Artificial Intelligence in Game Design Lecture 22: Heuristics and Other Ideas in Board Games.
AD FOR GAMES Lecture 4. M INIMAX AND A LPHA -B ETA R EDUCTION Borrows from Spring 2006 CS 440 Lecture Slides.
Game Playing Chapter 5. Game playing §Search applied to a problem against an adversary l some actions are not under the control of the problem-solver.
October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase.
For Wednesday Read Weiss, chapter 12, section 2 Homework: –Weiss, chapter 10, exercise 36 Program 5 due.
Game Playing. Towards Intelligence? Many researchers attacked “intelligent behavior” by looking to strategy games involving deep thought. Many researchers.
Minimax with Alpha Beta Pruning The minimax algorithm is a way of finding an optimal move in a two player game. Alpha-beta pruning is a way of finding.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
Games 1 Alpha-Beta Example [-∞, +∞] Range of possible values Do DF-search until first leaf.
For Wednesday Read chapter 7, sections 1-4 Homework: –Chapter 6, exercise 1.
Game Playing. Introduction One of the earliest areas in artificial intelligence is game playing. Two-person zero-sum game. Games for which the state space.
CSCI 4310 Lecture 6: Adversarial Tree Search. Book Winston Chapter 6.
Adversarial Search Chapter Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent reply Time limits.
Today’s Topics Playing Deterministic (no Dice, etc) Games –Mini-max –  -  pruning –ML and games? 1997: Computer Chess Player (IBM’s Deep Blue) Beat Human.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Graph Search II GAM 376 Robin Burke. Outline Homework #3 Graph search review DFS, BFS A* search Iterative beam search IA* search Search in turn-based.
Adversarial Search 2 (Game Playing)
February 25, 2016Introduction to Artificial Intelligence Lecture 10: Two-Player Games II 1 The Alpha-Beta Procedure Can we estimate the efficiency benefit.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
Understanding AI of 2 Player Games. Motivation Not much experience in AI (first AI project) and no specific interests/passion that I wanted to explore.
Search: Games & Adversarial Search Artificial Intelligence CMSC January 28, 2003.
Adversarial Search and Game-Playing
Iterative Deepening A*
PENGANTAR INTELIJENSIA BUATAN (64A614)
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
Artificial Intelligence
Alpha-Beta Search.
NIM - a two person game n objects are in one pile
Artificial Intelligence
Alpha-Beta Search.
Introduction to Artificial Intelligence Lecture 9: Two-Player Games I
Alpha-Beta Search.
Alpha-Beta Search.
Alpha-Beta Search.
CS51A David Kauchak Spring 2019
Unit II Game Playing.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Artificial Intelligence in Game Design Board Games and the MinMax Algorithm

Board Games Examples: –Chess, checkers, tic tac toe, backgammon, etc. Characteristics: –Alternating moves: player  AI  player  AI  … –Limited (but usually not small) set of possible moves Example: legal moves in chess –Set of winning and losing board configurations Examples: checkmate in chess, all pieces gone in checkers Goal of AI: –Choose next move so that will “likely” lead to victory Key problem: What exactly does this mean?

Planning Against an Opponent Idea: Create sequence of steps that lead from initial board state to winning state Problem: Unlike normal planning, AI does not get to choose every step of path –Player gets to choose every other step in plan –Will choose steps that defeat the AI X XOXO X XO XO XO XO X XXOXO X XO X O

Tree Representation Can represent possible moves as tree –Node = board state –Branch = possible moves from that state –Opponent controls every other branching of tree! Example: Tic Tac Toe –Simplified to remove duplicate branches for reflection, rotation Root node = initial board state X X X Possible X moves XOXOX O X O X O XOX O XOX O X O X O X O Possible O moves

Choosing Next Move Simple idea: Choose next move so guaranteed win no matter which moves opponent makes –No real game is this simple! Example: I winI lose I winI lose I win AB CDE F G H

Choosing Next Move Reasoning: If choose move A, then opponent will choose move D and I lose. If choose move B, I win, since: –If opponent chooses move F, I win –If opponent chooses move E, I choose move G and win Therefore, choose move B –Guaranteed win regardless of opponent moves

Lookahead Problem Main Problem: No nontrivial game has tree which can be completely explored –m possible moves each turn –n turns until game ends –m n nodes in game tree Exponential growth –Example: Chess ~20 moves per turn ~50 turns per game ~20 50 possible moves –Close to number of particles in universe!

Heuristic Evaluation of Boards How many levels can be explored in tree? Can process p nodes per second Have maximum of s seconds per move –Can process ps nodes –m n nodes looking ahead n moves –Can explore n = log m (ps) moves ahead What if game not over at deepest lookahead level? –Should AI try to force this branch or avoid it? No time to explore moves past this point

Heuristic Evaluation of Boards Key idea: Create heuristic measure of how “good” a board configuration is H(board) –Positive or negative number: Higher = better, lower = worse –Win = MAXINT, Loss = - MAXINT Goal: Choose current move that guarantees reaching board position with highest possible heuristic measure MAXINT MAXINT

Heuristic Evaluation of Boards TicTacToe Example (with AI playing X): H(board) = 2 × # of possible rows/columns/diagonals where X could win in one move × # of possible rows/columns/diagonals where X could win in two moves × # of possible rows/columns/diagonals where O could win in one move × # of possible rows/columns/diagonals where O could win in two moves Example: X OX XO H = = 3

MINMAX Algorithm Explore possible moves from current board position –Continue until reach maximum lookahead level –Forms tree of possible moves and countermoves Apply heuristic measure to all boards at leafs of tree Work from leafs to root of tree –Measure of each node based on measure of it child nodes Choose current move that results in highest heuristic value AI makes move Player makes move (may not be one expected, but can’t be worse)

MINMAX Algorithm AI’s turn = MAX level –Choose move that gives highest heuristic AI should choose move that guarantees best result! –Value of board position at that level = maximum of its children –Example: TicTacToe with AI playing X X OX O X OX XO XX OX O XX OX O X OXX O X OX XO Best move Bad move, but not relevant Will choose move with highest heuristic, so value of reaching this board = 4 4

MINMAX Algorithm Player’s turn = MIN level –Assume they choose move which is best for them Assume good for player = bad for AI Assume move that gives lowest heuristic –Value of board position at that level = minimum of its children X X OXO -2 Worst move for AI Bad moves for player, but can’t assume they will do this Player will choose move with lowest heuristic, so value of reaching this board = X OX OXO X OX OXO OX X OXO OX X OXO

Simple MinMax Example AI move 3 levels of lookahead Heuristic Measures No time to explore moves past this point AI move player move

Simple MinMax Example AI move 3 levels of lookahead Heuristic Measures No time to explore moves past this point AI move player move Max(8, -2) = 8Max(-5, -1) = -1Max(3, 5) = 5 Max(4, 12) = 12

Simple MinMax Example AI move 3 levels of lookahead Heuristic Measures No time to explore moves past this point AI move player move Max(8, -2) = 8Max(-5, -1) = -1Max(3, 5) = 5 Max(4, 12) = 12 Min(8, 5) = 5Min(-1, 12) = -1

Simple MinMax Example Heuristic Measures No time to explore moves past this point AI move player move Max(8, -2) = 8Max(-5, -1) = -1Max(3, 5) = 5 Max(4, 12) = 12 Min(8, 5) = 5Min(-1, 12) = -1 AI move Max(5, -1) = 5 Best possible outcome = 5 Follow this branch

MinMax Example Max(-1, 1, -2) = 1 X X X Min(1, -1, 0, 1, 0) = -1 XOXOX O X O X O XOX O XOX O X O X O X O Heuristic Measures No time to explore moves past this point Min(-1, 0, -2, -1, 0) = -2 Min(1, 2) = 1 Choose this move Assume player will then do this AI playing X Maximum lookahead of 2 moves Initial move choice for AI

Efficiency in MinMax Goal: Speed up MinMax algorithm –Negamaxing –Depth-first search –Alpha-beta pruning –Move ordering Idea: Faster evaluation  Able to explore more levels in game tree  Better decision making –Can speed up process by factor of 10 – 100

Negamaxing MinMax uses different function at each level –AI move: maximum –Player move: minimum –More efficient if used single function Value(node n) = maximum(–Value(child nodes of n)) –Maximizing the negative has same effect as minimizing –Signs changed at each level –Also need to invert heuristic function if player’s move at bottom of tree

Negamaxing Example: Heuristic Measures (inverted since player’s move) AI move player move Max(8, -2) = 8Max(-5, -1) = -1Max(3, 5) = 5 Max(4, 12) = 12 Max(-8, -5) = -5Max(1, -12) = 1 AI move Max(5, -1) = 5

Depth-first Search Don’t need to store entire evaluation tree in memory –Less memory = faster execution Just need: –Current branch being explored –Best score so far at each node along that branch Recursive algorithm: float DFS(node N) { if N is Leaf return H(N) bestScoreSoFar = -MAXINT for child C of N { float childScore = DFS(C) if childScore > bestScoreSoFar bestScoreSoFar = childScore } return bestScoreSoFar }

Depth-first Search Example bestScoreSoFar = 8 bestScoreSoFar = -8 bestScoreSoFar = -MAXINT

Depth-first Search Example bestScoreSoFar = 5 bestScoreSoFar = bestScoreSoFar =

Depth-first Search Example bestScoreSoFar = -1 bestScoreSoFar = bestScoreSoFar = 1

Depth-first Search Example bestScoreSoFar = -4 bestScoreSoFar = 5 bestScoreSoFar =

Alpha-Beta Pruning Idea: Many branches cannot possibly improve score –Once this is known, stop exploring them –Can typically lead to speedup by factor of 10 Example: BestSoFar = max(-1, 1, -?) = 1 X X X BestSoFar = 1 XO BestSoFar = max (1, -?, -?, -?, -?) BestSoFar = -1 1) Maximum will never get lower than -1 2) So this can never be greater than -1, which means it cannot increase BestSoFar 3) Which means that there is no point in exploring any of these branches

Alpha-Beta Pruning In general: Define -α as the value found down a previously explored branch –Can do no worse than α at this point Define β as a value found below the current branch –Can do no better than – β down this branch If α ≥ β, there is no point in exploring this branch any further -α-α BestSoFar = max (α, x) where x ≤ β = α if α ≥ β β BestSoFar = max (-β, …) ≥ -β

Move Ordering Problem: Alpha-Beta pruning only works well if best branches explored first –Only know branch is not worth exploring if have already seen a better one Goal: Order branches so moves “most likely” to be good are explored first –This is very difficult! XX X Probably no branches eliminated if explored in this order

Move Ordering Idea: Use results of last evaluation to order moves this time –Tree reevaluated each move A player move chosen CB EDGF Tree created in previous move AI move chosen Attempt to “reuse” this part of tree

Move Ordering Each board in subtree already has an evaluation –May no longer be completely accurate –Should still be somewhat accurate Use those to determine order in which next evaluation done A CB EDGF A CB DEGF

Games with Random Component Example: Backgammon –Roll dice (random event) –Determine which piece or pieces to move that many steps One piece 11 steps Two pieces 5 and 6 steps Which piece? Possible actions depend on random component

Games with Random Component Can treat random event like extra level of game tree Dice throw Possible moves based on dice throw (8 in this case)

MinMax in Random Games Algorithm: Generate tree of possible outcomes up to lookahead limit –Will alternate possible moves and possible outcomes of random event –Start with possible AI moves after random event Point at which AI has to make decision about what to do AI dice throw at current board state Possible AI moves from current board for that dice throw Possible player dice throws Possible player moves based on board and their dice throw Possible player dice throws Possible AI moves from this board for that dice throw

MinMax in Random Games Use Negamax to compute values at decision levels –AI and player make best possible move based on their dice throw Weight each node at random event level based on probability of the random event 1) Value of board for each possible move after dice throw of ) Negamax uses this value 3) Probability of dice throw of 8 = 5/36 4) Weight this state = 5/36 * 18 = 2.5

MinMax in Random Games Probability: 1/36 1/18 1/12 1/9 5/36 1/6 5/36 1/9 1/12 1/18 1/36 Negamax value from child nodes: Weighted value: Total expected value = 12 Compute value of board before random event based on expected value of boards after random event

MinMax in Random Games Random component greatly increases size of tree Example: –11 possibilities for dice throw –n moves lookahead –Increases nodes to explore by factor of 11 n Will probably not be able to look ahead more than 2 or 3 moves TD-Gammon –Plays at world championship level –Also uses learning