Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop.

Slides:



Advertisements
Similar presentations
Artificial Intelligence 5. Game Playing
Advertisements

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,
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.
Computers playing games. One-player games Puzzle: Place 8 queens on a chess board so that no two queens attack each other (i.e. on the same row, same.
AI for Connect-4 (or other 2-player games) Minds and Machines.
Artificial Intelligence Adversarial search Fall 2008 professor: Luigi Ceccaroni.
ICS-271:Notes 6: 1 Notes 6: Game-Playing ICS 271 Fall 2008.
CHAPTER 10 FUN AND GAMES Group 1: Xiangling Liu.
Adversarial Search Chapter 6 Section 1 – 4.
Lecture 12 Last time: CSPs, backtracking, forward checking Today: Game Playing.
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.
Lecture 13 Last time: Games, minimax, alpha-beta Today: Finish off games, summary.
Artificial Intelligence in Game Design
State Space 4 Chapter 4 Adversarial Games. Two Flavors Games of Perfect Information ◦Each player knows everything that can be known ◦Chess, Othello Games.
CompSci Recursion & Minimax Playing Against the Computer Recursion & the Minimax Algorithm Key to Acing Computer Science If you understand everything,
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)
A TIE IS NOT A LOSS Paul Adamiak T02 Aruna Meiyeppen T01.
How computers play games with you CS161, Spring ‘03 Nathan Sturtevant.
Game Tree Search based on Russ Greiner and Jean-Claude Latombe’s notes.
Adversarial Search: Game Playing Reading: Chess paper.
Game Playing: Adversarial Search Chapter 6. Why study games Fun Clear criteria for success Interesting, hard problems which require minimal “initial structure”
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.
Game Trees: MiniMax strategy, Tree Evaluation, Pruning, Utility evaluation Adapted from slides of Yoonsuck Choe.
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.
Game Playing.
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.
Adversarial Search CS311 David Kauchak Spring 2013 Some material borrowed from : Sara Owsley Sood and others.
Instructor: Vincent Conitzer
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.
1 Adversarial Search CS 171/271 (Chapter 6) Some text and images in these slides were drawn from Russel & Norvig’s published material.
W 2 L 1 sh 1 C lessons LessonSubjectBook Week 1 lesson 1Objects, names Week 1 lesson 2Statements, layout Week 2 lesson 1Functions, decomposition Week 2.
Cilk Pousse James Process CS534. Overview Introduction to Pousse Searching Evaluation Function Move Ordering Conclusion.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW AI for games: min-max search COMP #
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.
Will Britt and Bryan Silinski
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)
Parallel Programming in Chess Simulations Part 2 Tyler Patton.
Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.
CPS 100, Spring Search, Backtracking,Heuristics l How do you find a needle in a haystack?  How does a computer play chess?  Why would you write.
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.
Instructor: Vincent Conitzer
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
State Space 4 Chapter 4 Adversarial Games.
David Kauchak CS52 – Spring 2016
Chapter 6 : Game Search 게임 탐색 (Adversarial Search)
Alpha-Beta Search.
Alpha-Beta Search.
Instructor: Vincent Conitzer
Alpha-Beta Search.
Minimax strategies, alpha beta pruning
Alpha-Beta Search.
Alpha-Beta Search.
Minimax strategies, alpha beta pruning
Data Structures and Algorithms
CS51A David Kauchak Spring 2019
Unit II Game Playing.
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Mark Dunlop, Computer and Information Sciences, Strathclyde University 1 Algorithms & Complexity 5 Games Mark D Dunlop 14.6

Mark Dunlop, Computer and Information Sciences, Strathclyde University 2 How computers play games Chess, draughts and naughts and crosses We'll do naughts and crosses –its easiest

Mark Dunlop, Computer and Information Sciences, Strathclyde University 3 Naughts and crosses Three X or thee O in a row to win Can guarantee not to lose Can grab a win when available

Mark Dunlop, Computer and Information Sciences, Strathclyde University 4 Minimax strategy Use an evaluation strategy to quantify the goodness of a position Terminal cases: A win for the computer gives +1, a draw 0, a loss -1 Non-terminal: calculated by recursively assuming best play by both computer and human Minimax - human tries to minimise the computer goodness function, computer tries to maximise it and we take turns

Mark Dunlop, Computer and Information Sciences, Strathclyde University 5 Basic Strategy "If I (computer) move there, then my opponent will probably move there, then I can move there,..., and win!"

Mark Dunlop, Computer and Information Sciences, Strathclyde University 6 Next position The successor position of P is any position P’ reachable from P in one move –Computer move: look at all next positions and calculate their score (recursively) pick next move with maximum score –Guess of human move: look at all next positions and calculate their score assume human plays move with minimum score

Mark Dunlop, Computer and Information Sciences, Strathclyde University 7 Some Psuedo Code public moveInfo findComputerMove() //computer plays X, human O if board is full return new moveInfo(DRAW) else if can_win_in_one_move return new moveInfo(winmove,WIN) else maxvalue = LOSE for i=1..9 if square i is empty place (i, 'X') tryvalue = findHumanMove().value emptycell (i) if tryvalue > maxvalue maxvalue = tryvalue; bestmove = i return new moveInfo(bestmove, maxvalue) findHumanMove is very similar

Mark Dunlop, Computer and Information Sciences, Strathclyde University 8 Problems All this says is –if I (computer) move there then I can win if user plays best as I expect –If I move there the best I can do is draw –If I move there I can only lose Better to return some function of the probability of winning, i.e. –if I move here then for 1/6 human moves I can win or –If I move here then for 5/6 human moves I can win

Mark Dunlop, Computer and Information Sciences, Strathclyde University 9 Complexity Main loop cycles round 9 squares For each square - calculate all possible future values from that move, e.g first move –computer has 9 choices –human then has 8 –computer then has 7 –human then has 6 –computer then has 5 and might win or not, etc... 9x8x7x6x5x4x3x2x1 = combinations Of which are possible (stop after a win)

Mark Dunlop, Computer and Information Sciences, Strathclyde University 10 Complexity If the computer moves first it has positions to evaluate If the human then picks the centre square, the computers next turn has evaluations (9 761 for a corner, for a side) For chess it is estimated there are 10^100 positions to be examined to decide the best first move Standard openings help but in general, this is still too bad...

Mark Dunlop, Computer and Information Sciences, Strathclyde University 11 Complexity reducers Only look so far ahead –requires some function to evaluate the strength of a current board –in chess these functions can be very complex –still the ply or number of levels look ahead is still the big performance factor

Mark Dunlop, Computer and Information Sciences, Strathclyde University 12 Complexity reducers Remember already calculated positions –Use a transposition table - almost always a hash table –When you calculate a position you store it in the table –Next time you face a position, see if it is there and just read off the value (note: there are many routes to one position) Only look ahead where it looks good

Mark Dunlop, Computer and Information Sciences, Strathclyde University 13 Sample game tree Note: no tree is actually created - this is the tree of recursive calls, or choices we can make.

Mark Dunlop, Computer and Information Sciences, Strathclyde University 14 Alpha-Beta Pruning Another algorithmic design pattern We can ignore large parts of the tree because we can't do better than already found, e.g.

Mark Dunlop, Computer and Information Sciences, Strathclyde University 15 How to beat a chess program Most chess programs (and real games) have a time limit per move The programs optimise their "thinking" using alpha-beta pruning to maximise the depth in places where they are likely to be asked to play, i.e. they assume the human plays well

Mark Dunlop, Computer and Information Sciences, Strathclyde University 16 How to beat a chess program If you play very badly for one move, the computer will run out of time on its next shot since it will not have calculated that whole chunk of the game tree Grand masters didn't take long to work that one out...

Mark Dunlop, Computer and Information Sciences, Strathclyde University 17 Summary MiniMax strategy for making best choice for computer, and best from human too Look ahead level, ply, & evaluation function are both important ply usually dominates Transposition tables remember positions ALPHA-BETA pruning reduce number of nodes to calculate based on best/worst already seen You throw a chess program by playing badly (once...)