Game Playing CIS 479/579 Bruce R. Maxim UM-Dearborn.

Slides:



Advertisements
Similar presentations
Adversarial Search Chapter 6 Section 1 – 4. Types of Games.
Advertisements

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.
Adversarial Search Reference: “Artificial Intelligence: A Modern Approach, 3 rd ed” (Russell and Norvig)
Games & Adversarial Search Chapter 5. Games vs. search problems "Unpredictable" opponent  specifying a move for every possible opponent’s reply. Time.
For Friday Finish chapter 5 Program 1, Milestone 1 due.
February 7, 2006AI: Chapter 6: Adversarial Search1 Artificial Intelligence Chapter 6: Adversarial Search Michael Scherger Department of Computer Science.
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2008.
Game Playing Games require different search procedures. Basically they are based on generate and test philosophy. At one end, generator generates entire.
Adversarial Search: Game Playing Reading: Chapter next time.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
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.
Lecture 13 Last time: Games, minimax, alpha-beta Today: Finish off games, summary.
Artificial Intelligence in Game Design
Mahgul Gulzai Moomal Umer Rabail Hafeez
All rights reservedL. Manevitz Lecture 31 Artificial Intelligence A/O* and Minimax L. Manevitz.
This time: Outline Game playing The minimax algorithm
Game Playing CSC361 AI CSC361: Game Playing.
Min-Max Trees Based on slides by: Rob Powers Ian Gent Yishay Mansour.
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.
Games & Adversarial Search Chapter 6 Section 1 – 4.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
1 Heuristic Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
Game Playing State-of-the-Art  Checkers: Chinook ended 40-year-reign of human world champion Marion Tinsley in Used an endgame database defining.
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
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.
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.
KU NLP Heuristic Search Heuristic Search and Expert Systems (1) q An interesting approach to implementing heuristics is the use of confidence.
Game Playing.
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.
1 Computer Group Engineering Department University of Science and Culture S. H. Davarpanah
October 3, 2012Introduction to Artificial Intelligence Lecture 9: Two-Player Games 1 Iterative Deepening A* Algorithm A* has memory demands that increase.
Heuristic Search In addition to depth-first search, breadth-first search, bound depth-first search, and iterative deepening, we can also use informed or.
For Wednesday Read Weiss, chapter 12, section 2 Homework: –Weiss, chapter 10, exercise 36 Program 5 due.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
For Wednesday Read chapter 7, sections 1-4 Homework: –Chapter 6, exercise 1.
CSCI 4310 Lecture 6: Adversarial Tree Search. Book Winston Chapter 6.
GAME PLAYING 1. There were two reasons that games appeared to be a good domain in which to explore machine intelligence: 1.They provide a structured task.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Game-playing AIs Part 2 CIS 391 Fall CSE Intro to AI 2 Games: Outline of Unit Part II  The Minimax Rule  Alpha-Beta Pruning  Game-playing.
CMSC 421: Intro to Artificial Intelligence October 6, 2003 Lecture 7: Games Professor: Bonnie J. Dorr TA: Nate Waisbrot.
Adversarial Search. Regular Tic Tac Toe Play a few games. –What is the expected outcome –What kinds of moves “guarantee” that?
Adversarial Search 2 (Game Playing)
Adversarial Search and Game Playing Russell and Norvig: Chapter 6 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
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!)
Adversarial Search In this lecture, we introduce a new search scenario: game playing 1.two players, 2.zero-sum game, (win-lose, lose-win, draw) 3.perfect.
Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.
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*
Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) R&N: Chap. 6.
Alpha-Beta Search.
NIM - a two person game n objects are in one pile
Alpha-Beta Search.
The Alpha-Beta Procedure
Introduction to Artificial Intelligence Lecture 9: Two-Player Games I
Alpha-Beta Search.
Minimax strategies, alpha beta pruning
Alpha-Beta Search.
Alpha-Beta Search.
Minimax strategies, alpha beta pruning
Unit II Game Playing.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Game Playing CIS 479/579 Bruce R. Maxim UM-Dearborn

Generate and Test Search can be viewed generate and test procedures Testing for a complete path is performed after varying amount of work has been done by the generator At one extreme the generator generates a complete path which is evaluated At the other extreme each move is tested by the evaluator as it is proposed by the generator

Improving Search-Based Problem Solving Two options 1.Improve “generator” to only generate good moves or paths 2.Improve “tester” so that good moves recognized early and explored first

Using Generate and Test Can be used to solve identification problems in small search spaces Can be thought of as being a depth-first search process with backtracking allowed Dendral – expert system for identifying chemical compounds from NMR spectra

Dangers Consider a safe cracker trying to use generate a test to crack a safe with a 3 number combination ( ) There are possible combinations At 3 attempts/minute it would take 16 weeks of 24/7 work to try each combination in a systematic manner

Generator Properties Complete –capable of producing all possible solutions Non-redundant –don’t propose same solution twice Informed –make use of constraints to limit solutions being prposed

Dealing with Adversaries Games have fascinated computer scientists for many years Babbage –playing chess on Analytic Engine –designed Tic-Tac-Toe machine Shanon (1950) and Turing (1953) –described chess playing algorithms Samuels (1960) –Built first significant game playing program (checkers)

Why games attracted interest of computer scientists? Seemed to be a good domain for work on machine intelligence, because they were thought to: –provide a source of a good structured task in which success or failure is easy to measure –not require much knowledge (this was later found to be untrue)

Chess Average branching factor for each position is 35 Each player makes 50 moves in an average game A complete game has potential positions to consider Straight forward search of this space would not terminate during either players lifetime

Games Can’t simply use search like in “puzzle” solving since you have an opponent Need to have both a good generator and an effective tester Heuristic knowledge will also be helpful to both the generator and tester

Ply Some writers use the term “ply” to mean a single move by either player Some insists “ply” is made up of a move and a response I will use the first definition, so “ply” is the same as the “depth - 1” of the decision tree rooted at the current game state

Static Evaluation Function Used by the “tester” Similar to “closerp” from our heuristic search work in A* type algorithms In general it will only be applied to the “leaf” node of the game tree

Static Evaluation Functions Turing (Chess) sum of white values / sum of black values Samuels (Checkers) linear combination with interaction terms piece advantage capability for advancement control of center threat of fork mobility

Role of Learning Initially Samuels did not know how to assign the weights to each term of his static evaluation function Through self-play the weights were adjusted to match the winner’s values c1 * piece advan + c2 * advanc + …

Tic Tac Toe

100A + 10B + C – (100D + 10E + F) A = number of lines with 3X’s B = number of lines with 2X’s C = number of lines with single X D = number of lines with 3 O’s E = number of lines with 2 O’s F = number of lines with a single O

Example X X O O X A = 0 B = 0 C = 1 D = 0 E = 1 F = (0) + 10(0) + 1 – (100 (0) + 10(1) + 1) = 1 – 11 = -10

Weakness All static evaluation functions suffer from two weaknesses –information loss as complete state information mapped to a single number –Minsky’s Credit Assignment problem it is extremely difficult to determine which move in a particular sequence of moves caused a player to win or loss a game (or how much credit to assign to each for end result)

What do we need for games? Plausible move generator Good static evaluation functions Some type of search that takes opponent behavior into account for nontrivial games

1-ply Minimax If the static evaluation is applied to the leaf nodes we get B = 8 C = 3 D = -2 So best move appears to be B A CBD

2-ply Minimax Applying the static evaluation function E = 9 F = -6 G = 0 H = 0 I = -2 J = -4 K = -3 A BCD EFGIHJK

Propagating the Values Will depend on the level Assuming that the “minimizer” chooses from the leaf nodes, be would get B = min(9, -6, 0) = -6 C = min(0, -2) = -2 D = min(-4, -3) = -4 The the “maximizer” gets to choose from the minimizers values and selects move C A = max(-6, -2, -4)

Minimax Algorithm If (limit of search reached) then compute static value of current position return the result Else If (level is minimizing level) then use Minimax on children of current position report minimum of children’s results Else use Minimax on children of current position report maximum of children’s results

Search Limit Has someone won the game? Number of ply explored so far How promising is this path? How much time is left? How stable is this configuration?

Criticism of Minimax Goodness of current position translated to a single number without knowing how the number was forced on us Suffers from “horizon effect” –a win or loss might be in the next ply and we would not know it

Minimax with Alpha-Beta Pruning Alpha cut-off –whenever a min node descendant receives a value less than the “alpha” known to the min node’s parent, which will be a max node, the final value of min. node can be set to beta Beta cut-off –whenever a max node descendant receives a value greater than “beta” known to the max nodes parent (a min node), the final value of max node can be set to “alpha”

Alpha-Beta Assumptions Alpha value initially set to -  and never decreases Beta value initially set to +  and never increases Alpha value is always current largest backed up value found by any node successor Beta value is always current smallest backed up value found by any node successor

Alpha-Beta Pruning

Alpha-Beta With perfect ordering more static evaluations are skipped Even without perfect ordering many evaluations can be skipped If worst paths are explored first no cutoffs will occur With perfect ordering alpha-beta lets you exam twice the number of ply that minimax without alpha-beta can examine in the same amount of time

Alpha-Beta Algorithm Function Value (P, ,  ) // P is the position in the data structure { // determine successors of P and call them // P(1), P(2),... P(d) if d=0 then return f(p) // call static evaluation function // return as value to parent

Alpha-Beta Algorithm else { m =  for i =1 to d do { t = - value (Pi - , - m) if t > m then m = t if =>  then exit loop } return m }

Alpha-Beta C++ #include // This program is a implementation of the AlphaBeta // algorithm found in Kreutzer & MacKenzie p const True = 1; const False = 0; const MaxNum = 2; //node degree const NumPly = 4; //search ply const Root = 1; //start search at this location const Index = 51;

Alpha-Beta C++ typedef float Tree[Index]; //simulated game tree typedef int State; typedef int Ply; typedef int ListIndex; typedef float List[MaxNum]; //state siblings Tree T; //game tree declaration

Alpha-Beta C++ void Init(Tree &T) // Build dummy game tree. { int I; for (I = 16; I <= 31; I++) //blank out 4-ply leaf nodes T[I] = 0.0; } float Eval(State S) //Compute value of state S. { return random(101); }

Alpha-Beta C++ int Terminal(State S) //Stub function to check S for succesor states. { return False; } float Max(float X, float Y) // Returns maximum of X and Y. { if (X > Y) return X; else return Y; }

Alpha-Beta C++ float Min(float X, float Y) //Returns minimum of X and Y. { if (X < Y) return X; else return Y; } State Child(State S, ListIndex I) //Compute I-th successor of state S. { return MaxNum * S + I - 1; }

Alpha-Beta C++ int MachineMove(Ply N) // Checks to see if it is computer's move // in this ply. { return !(N % 2); //odd moves are computers }

Alpha-Beta C++ float AlphaBeta (State S, Ply N, float Alpha, float Beta) // Recusively score state S using evaluation // function Eval and an N - Ply state space graph. { State Next; ListIndex I; float V, Value, BestScore; List L; //successors of S at this level

Alpha-Beta C++ if ((N == 0) || Terminal(S)) { Value = Eval(S); T[S] = Value; //record values only to confirm cut offs if (Value > 100) //machine win return MAXINT; else if (Value < -100) //machine loss return -MAXINT; else if (Value == 0) //draw return 0; else return Value; }

Alpha-Beta C++ else { if (MachineMove(N)) //program's move BestScore = Alpha; else BestScore = Beta; I = 1; while (I <= MaxNum) { Next = Child(S, I); V = AlphaBeta(Next, N - 1, Alpha, Beta);

Alpha-Beta C++ if (MachineMove(N)) //program's move { BestScore = Max(V, BestScore); Alpha = BestScore; if (Alpha >= Beta) { BestScore = Beta; I = MaxNum; //prune remaining S successors }

Alpha-Beta C++ else { BestScore = Min(V, BestScore); Beta = BestScore; if (Alpha >= Beta) { BestScore = Alpha; I = MaxNum; //prune remaining S successors } I = I + 1; } return BestScore; }

Alpha-Beta C++ void main( ) { randomize(); Init(T); cout << "Value = “ << AlphaBeta(Child(Root, 1), NumPly - 1, -MAXINT, MAXINT) << "\n"; cout << "Value = “ << AlphaBeta(Child(Root, 2), NumPly - 1, -MAXINT, MAXINT) << "\n"; }

Horizon Heuristics Progressive deepening –3 ply search followed by 4 ply, followed by 5 ply, etc. until time runs out Heuristic pruning –order moves based on plausibility and eliminate unlikely possibilities –does not come with “minimax” guarantee Heuristic continuation –extend promising or volatile paths 1 or 2 more steps before committing to choice

Horizon Heuristics Futility cut-off –stop exploring when improvements are marginal –does not come with “minimax” guarantee Secondary search –once you pick a path using a 6 ply search continue from leaf node with a 3 ply search to confirm pick Book moves –eliminates search in specialized situations –does not come with “minimax” guarantee