Intelligent CS 5 ? HW 11 (1 problem !) M/T sections W/Th sections due Sunday, 11/14 at midnight due Monday, 11/15 at midnight Recitation for HW11 -- Friday.

Slides:



Advertisements
Similar presentations
Adversarial Search Chapter 6 Sections 1 – 4. Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
Advertisements

Game Playing CS 63 Chapter 6
Adversarial Search Chapter 6 Section 1 – 4. Types of Games.
"Intelligent" CS 5 An object is structured data that is alive, responsible, and intelligent. Sound too friendly? This week’s objects and classes will be.
AI for Connect-4 (or other 2-player games) Minds and Machines.
CS 484 – Artificial Intelligence
Adversarial Search Chapter 6 Section 1 – 4.
University College Cork (Ireland) Department of Civil and Environmental Engineering Course: Engineering Artificial Intelligence Dr. Radu Marinescu Lecture.
Adversarial Search Chapter 5.
Hoe schaakt een computer? Arnold Meijster. Why study games? Fun Historically major subject in AI Interesting subject of study because they are hard Games.
Artificial Intelligence in Game Design Heuristics and Other Ideas in Board Games.
An Introduction to Artificial Intelligence Lecture VI: Adversarial Search (Games) Ramin Halavati In which we examine problems.
1 Adversarial Search Chapter 6 Section 1 – 4 The Master vs Machine: A Video.
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.
Artificial Intelligence in Game Design
HW 6: Problems 2&3 Simulating Connect 4.
CompSci Recursion & Minimax Playing Against the Computer Recursion & the Minimax Algorithm Key to Acing Computer Science If you understand everything,
CPSC 322 Introduction to Artificial Intelligence October 25, 2004.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.6: Adversarial Search Fall 2008 Marco Valtorta.
Adversarial Search: Game Playing Reading: Chess paper.
CS 5 Today: two I's AIUI hw11pr2.py an arbitrarily-good Connect 4 player! Player class Extra: scoreBoard4Tourney an intuitive Connect 4 player: hw11pr1.html.
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.
Lecture 5 Note: Some slides and/or pictures are adapted from Lecture slides / Books of Dr Zafar Alvi. Text Book - Aritificial Intelligence Illuminated.
CS 5 HW 12 (2 problems) M/T sections W/Th sections due Sunday, 11/21 at midnight due Monday, 11/22 at midnight Recitation for HW12 -- Friday 8:00am Looking.
Adversarial Search CS30 David Kauchak Spring 2015 Some material borrowed from : Sara Owsley Sood and others.
Game Playing.
Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening.
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.
Def tomorrow(self): """Changes the calling object so that it represents one calendar day after the date it originally represented. """ if self.month in.
Adversarial Search CS311 David Kauchak Spring 2013 Some material borrowed from : Sara Owsley Sood and others.
Adversarial Search Chapter 6 Section 1 – 4. Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
Introduction to Artificial Intelligence CS 438 Spring 2008 Today –AIMA, Ch. 6 –Adversarial Search Thursday –AIMA, Ch. 6 –More Adversarial Search The “Luke.
IS313 Today: two I's AIUI hw9pr1.py an arbitrarily-good Connect 4 player! Player class Hw 10 (project) I wish there were three i's! Hw 9 is due Wed., 12/23.
Homework 11 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/14 Mon., 11/15 Problems
Game Playing. Towards Intelligence? Many researchers attacked “intelligent behavior” by looking to strategy games involving deep thought. Many researchers.
Homework 3 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/21 Mon., 9/22 Problems
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
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.
Games 1 Alpha-Beta Example [-∞, +∞] Range of possible values Do DF-search until first leaf.
Adversarial Search Chapter 6 Section 1 – 4. Search in an Adversarial Environment Iterative deepening and A* useful for single-agent search problems What.
IS313 … Monday, Nov. 8 - Classes + Objects, part 2 Monday, Nov Project strategies & example pres. Tuesday, Nov. 9 - Date class due Tuesday, Nov.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Cilk Pousse James Process CS534. Overview Introduction to Pousse Searching Evaluation Function Move Ordering Conclusion.
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.
HW 6: Problems 2 & 3 Simulating Connect 4. HW 6: Overview Connect 4: Variation of Tic-Tac-Toe – Board: Vertical 7x6 – Two players take alternating move.
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.
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
Paula Matuszek, CSC 8520, Fall Based in part on aima.eecs.berkeley.edu/slides-ppt 1 CS 8520: Artificial Intelligence Adversarial Search Paula Matuszek.
Code Compression the benefits of looping... Today in CS 5 HW 4 - (3 problems) M/T sections W/Th sections due Sunday, 9/26 at midnight due Monday, 9/27.
ARTIFICIAL INTELLIGENCE (CS 461D) Princess Nora University Faculty of Computer & Information Systems.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module 5 Adversarial Search (Thanks Meinolf Sellman!)
Artificial Intelligence in Game Design Board Games and the MinMax Algorithm.
Homework 10 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/10 Mon., 11/11 Problems
Adversarial Search Chapter 5 Sections 1 – 4. AI & Expert Systems© Dr. Khalid Kaabneh, AAU Outline Optimal decisions α-β pruning Imperfect, real-time decisions.
ADVERSARIAL SEARCH Chapter 6 Section 1 – 4. OUTLINE Optimal decisions α-β pruning Imperfect, real-time decisions.
IS313 Tomorrow… Wednesday, Nov Classes + Objects, part 2 Wednesday, Nov Classes + Objects, part 3 Thursday, Nov Date class due Thursday,
1 Chapter 6 Game Playing. 2 Chapter 6 Contents l Game Trees l Assumptions l Static evaluation functions l Searching game trees l Minimax l Bounded lookahead.
EECS 110: Lec 15: Classes and Objects (2)
Adversarial Environments/ Game Playing
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
Intelligent CS 5 ? This week's objects will be more adversarial…
HW 6: Problems 2 & 3 Simulating Connect 4.
HW 6: Problems 2 & 3 Simulating Connect 4.
EECS 110: Lec 15: Classes and Objects (2)
CS51A David Kauchak Spring 2019
Adversarial Search Chapter 6 Section 1 – 4.
Presentation transcript:

Intelligent CS 5 ? HW 11 (1 problem !) M/T sections W/Th sections due Sunday, 11/14 at midnight due Monday, 11/15 at midnight Recitation for HW11 -- Friday 11/12, 8:00 am 2nd midterm exam -- this Friday, 11/12 Take-home, 2.0 hours, closed-book exam. Practice problems are online… exemption: > 95% HW Exam will be available this Friday; it’s due Sunday evening by 5:00 pm. Chess is the Drosophila of artificial intelligence. The computer that defeated Garry Kasparov (top link) Today’s Lab: M-Z - Alexander Kronrod Games: computers vs. humans…

Two-player games early programs ~ 1960’s Strategic thinking was considered essential for intelligence Computer Chess has a long history: Ranking beginner amateur world ranked world champion MacHack ( 1100 ) ~ 1967 MIT Deep Thought ~ 1989 Carnegie Mellon Slate ( 2070 ) ~ 1970’s Northwestern Deep Blue ~ 1996 IBM Deep Blue rematch ~ 1997 IBM

Computers’ strategy… early programs ~ 1960’s Strategic thinking was considered essential for intelligence Computer Chess has a long history: Ranking beginner amateur world ranked world champion MacHack ( 1100 ) ~ 1967 MIT Deep Thought ~ 1989 Carnegie Mellon Slate ( 2070 ) ~ 1970’s Northwestern Deep Blue ~ 1996 IBM Deep Blue rematch ~ 1997 IBM 100’s of moves/sec 10,000’s of moves/sec 100,000,000 moves/sec 200,000,000 moves/sec how far ahead is this?

Games’ Branching Factors early programs ~ 1960’s Branching Factor Estimates for different two-player games Tic-tac-toe 4 Connect Four 7 Checkers 10 Othello 30 Chess 40 Go 300 On average, there are about 40 possible moves that a chess player can make from any board configuration… Ranking beginner amateur world ranked world champion MacHack ( 1100 ) ~ 1967 MIT Deep Thought ~ 1989 Carnegie Mellon Slate ( 2070 ) ~ 1970’s Northwestern Deep Blue ~ 1996 IBM Deep Blue rematch ~ 1997 IBM 0 Ply 1 Ply 2 Ply game tree for C4

Games’ Branching Factors early programs ~ 1960’s Branching Factor Estimates for different two-player games Tic-tac-toe 4 Connect Four 7 Checkers 10 Othello 30 Chess 40 Go 300 On average, there are about 40 possible moves that a chess player can make from any board configuration… Ranking beginner amateur world ranked world champion MacHack ( 1100 ) ~ 1967 MIT Deep Thought ~ 1989 Carnegie Mellon Slate ( 2070 ) ~ 1970’s Northwestern Deep Blue ~ 1996 IBM Deep Blue rematch ~ 1997 IBM 0 Ply 1 Ply 2 Ply

Games’ Branching Factors early programs ~ 1960’s Branching Factor Estimates for different two-player games Tic-tac-toe 4 Connect Four 7 Checkers 10 Othello 30 Chess 40 Go 300 On average, there are about 40 possible moves that a chess player can make from any board configuration… Ranking beginner amateur world ranked world champion MacHack ( 1100 ) ~ 1967 MIT Deep Thought ~ 1989 Carnegie Mellon Slate ( 2070 ) ~ 1970’s Northwestern Deep Blue ~ 1996 IBM Deep Blue rematch ~ 1997 IBM “solved” games computer-dominated human-dominated 0 Ply 1 Ply 2 Ply

Winning: Details public boolean winsFor(char ch) { for (int r=0 ; r<this.nrows-3 ; ++r) { for (int c=0 ; c<this.ncols-3 ; ++c) { if (this.data[r+0][c+0] == ch && this.data[r+1][c+1] == ch && this.data[r+2][c+2] == ch && this.data[r+3][c+3] == ch) { return true; } … same idea for vert., horiz., other diag. … return false; } which diagonals? which board piece? which curly braces?

public boolean winsFor(char ch) { for (int r=0 ; r<this.nRows-3 ; ++r) for (int c=0 ; c<this.nCols-3 ; ++c) if (this.data[r+0][c+0] == ch && this.data[r+1][c+1] == ch && this.data[r+2][c+2] == ch && this.data[r+3][c+3] == ch) return true; … same idea for vert., horiz., other diag. … return false; } Winning: Details (compact version)

Objects hide details! Class: Board Object: b b.winsFor(‘X’) b.addMove(3,‘X’) ‘X’ ‘O’ capabilities of b so that important things aren’t lost in the shuffle… b.removeMove(3) b.isOver() (the last 3 are new for this week) b.clear()

Objects hide details! class CS5App { public static void main(String[] args) { H.pl("Hi! Welcome to Connect 4..."); H.pl("How many rows/columns ? (4-15)"); int R = H.ni(); int C = H.ni(); Board b = new Board(R,C); char player = 'X'; while (true) { b.print(); int c = H.ni(); // gets next move b.addMove(c,player); if (b.winsFor(player)) break; if (player == 'X') player = '0'; else player = 'X'; } // end of while } Hw10Hw11

Where we’re headed… Player playerForX Details (data and methods) Player playerForO Details (data and methods) Ask what kind of players should play for X and O Create two objects of class Player with appropriate inputs Ask each of these objects to findScores for X and O and then breaktie s. See who wins! demo… what details are needed?

char checker Picture of a Player object Player int lookahead Player playerForX Player(char ch, int lk, int tbk) int tiebreakType void printScores(double[] s) double evaluate(Board b) double[] plyHuman(Board b) double[] ply0(Board b) int breaktie(double[] s) double[] findScores(Board b) Imagine if Board weren’t a Class… ! double[] ply1,2,3,4,N(Board b) methods

Player code private char checker; private int lookahead; private int tiebreakType; public Player(char ch, int la, int tbk) // constructor { } public char getChecker() // accessor “getter” method { } public char me() // short for getChecker() { } public char opp() // returns the opponent’s checker { } class Player {

Where we’re headed… Player playerForX Details (data and methods) Player playerForO Details (data and methods) Ask what kind of players should play for X and O Create two objects of class Player with appropriate inputs Ask each of these objects to findScores for X and O and then breaktie s. See who wins! demo… what details are needed?

Hw10 class CS5App { public static void main(String[] args) { H.pl("Hi! Welcome to Connect 4..."); int R = H.ni(); int C = H.ni(); Board b = new Board(R,C); char player = 'X'; while (true) { b.print(); int uc = H.ni(); // user’s column b.addMove(uc,player); if (b.winsFor(player)) break; if (player == 'X') player = '0'; else player = 'X'; } // end of while } Hw11

Choosing a move 1) Find scores at appropriate lookahead… 2) Print the scores. 3) Break ties to determine the next move. ply0 : 0 ply of lookahead ply1 : 1 ply of lookahead ply2,3,4 : 2,3,4 ply of lookahead plyHuman : ask the user printScores : prints the scores to each column breaktie : chooses ONE maximum score findScores chooses one of these methods to run

ply0 class Player { // returns scores with no lookahead // public double[] ply0(Board b) { char checker int lookahead int tiebreakType this b

ply1 class Player { // returns scores with 1ply lookahead // public double[] ply1(Board b) { char checker int lookahead int tiebreakType this b Which column should have the best score? Lookahead 1 move Evaluate the results for each column Later, we’ll choose the best column to move…

Evaluating a board Assigns a score to any Board b Score for X Score for O Score for X Score for O Score for X Score for O for a win -1.0 for an invalid move 0.0 for a loss 50.0 for a “tie” not possible in evaluate

evaluate class Player { // returns the appropriate score for b // remember: all of Player’s methods are available public double evaluate(Board b) { for a win -1.0 for an invalid move 0.0 for a loss 50.0 for a “tie” Improvements? Write tournamentEvaluate for Ex. Cr.!

b 0-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 1-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 2-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 3-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 “Quiz” It is X’s move.. Compute the score that X would find for each column for each of these lookaheads: no moves at all! X moves O moves X moves O moves X moves

class Player { private int tiebreakType; private int lookahead; private char checker; public int breaktie(double[] s) { double maxScore = getMax(s); /* assume getMax is already written */ if (this.tiebreakType == 2) /* random tie breaker is tiebreakType == 2 */ { } Write breaktie to return a randomly chosen best score (max score) from an array of scores named s.

‘X’ ‘O’ new‘X’ b Looking ahead 1 ply… (1) For each possible move (2) Add the column’s move (3) Evaluate the boards (4) Choose one of the best ‘X’ to move

‘X’ ‘O’ new‘X’ Col 6 Col 5 Col 4 Col 3 Col 2 Col 1 Col 0 b Looking ahead 1 ply… ‘X’ to move (1) For each possible move (2) Add the column’s move

‘X’ ‘O’ new‘X’ Col 6 Col 5 Col 4 Col 3 Col 2 Col 1 Col 0 b Looking ahead 1 ply… (1) For each possible move (2) Add the column’s move (3) Evaluate the boards ‘X’ to move NONE

‘X’ ‘O’ new‘X’ Col 6 Col 5 Col 4 Col 3 Col 2 Col 1 Col 0 b Looking ahead 1 ply… (1) For each possible move (2) Add the column’s move (3) Evaluate the boards ‘X’ to move NONE

‘X’ ‘O’ new‘X’ Col 6 Col 5 Col 4 Col 3 Col 2 Col 1 Col 0 b Looking ahead 1 ply… (1) For each possible move (2) Add the column’s move (3) Evaluate the boards (4) Choose one of the best ‘X’ to move NONE

ply1 public double[] ply1(Board b) {

Two-player games have been a key focus of AI as long as computers have been around… Strategic thinking = intelligence ? Humans and computers have different relative strengths in these games:

Two-player games have been a key focus of AI as long as computers have been around… Strategic thinking = intelligence ? computers good at looking ahead in the game to find winning combinations of moves Humans and computers have different relative strengths in these games: this week…

Two-player games have been a key focus of AI as long as computers have been around… Strategic thinking = intelligence ? humanscomputers good at evaulating the strength of a board for a player good at looking ahead in the game to find winning combinations of moves Humans and computers have different relative strengths in these games: this week… (extra credit)

How humans play games… - experts could reconstruct these perfectly - novice players did far worse… An experiment (by deGroot) was performed in which chess positions were shown to novice and expert players…

How humans play games… - experts could reconstruct these perfectly - novice players did far worse… Random chess positions (not legal ones) were then shown to the two groups - experts and novices did just as badly at reconstructing them! An experiment (by deGroot) was performed in which chess positions were shown to novice and expert players…

Looking further ahead … 0 ply: 2 ply:3 ply: random (but legal) choice of move ! (1) player will win (2) player will avoid losing (3) player will set up a win by forcing the opponent to avoid losing 1 ply: X ’s move

ply2 public double[] ply2(Board b) { depends on ply1 !

Extra Credit: the plyN method ! Lab this week You’ll need to write (and use) Last Names Problem 1: A Connect Four Player … Extra Credit: tournamentEvaluate & a C4 round-robin 2, 4, 6, and 8-ply lookahead for O will all produce different scores! Player(char ch, int lk, int tbk) char getChecker() char me() char opp() void printScores() double evaluate(Board b) double[] plyHuman(Board b) double[] ply0(Board b) int breaktie(double[] s) int go(Board b) (and the others listed on the HW) M-Z double[] findScores(Board b) O to move

b 0-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 1-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 2-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 3-ply scores for X: col 0col 1col 2col 3col 4col 5col 6 “Quiz” It is X’s move.. Compute the score that X would find for each column for each of these lookaheads: no moves at all! X moves O moves X moves O moves X moves

class Player { private int tiebreakType; private int lookahead; private char checker; public int breaktie(double[] s) { double maxScore = getMax(s); /* assume getMax is already written */ if (this.tiebreakType == 2) /* random tie breaker is tiebreakType == 2 */ { } Write breaktie to return a randomly chosen best score (max score) from an array of scores named s.

‘X’ ‘O’ new‘X’ Col 6 Col 5 Col 4 Col 3 Col 2 Col 1 Col 0 b Looking ahead 1 ply… (1) For each possible move (2) Add the column’s move (3) Evaluate the boards (4) Choose one of the best ‘X’ to move NONE

Winning -- details public boolean winsFor(char ox) { for (int r=0 ; r<this.nRows-3 ; ++r) { for (int c=0 ; c<this.nCols-3 ; ++c) { if (this.data[r+0][c+0] == ox && this.data[r+1][c+1] == ox && this.data[r+2][c+2] == ox && this.data[r+3][c+3] == ox) { return true; } … same idea for vert., horiz., SW-NE diag. … return false; } | | | | | |X| | | | | | | |O|X|O| | | | | |O|X|X| |O|O| |X|O|O|X|X|O|X| finds this diagonal: complete HW10PR2 solutions at

static static methods belong to a class, not an object H.pl(“I’m a static method”); // lots double av = averageArray(stocks); // HW 7 int syl = numSyllables(word); // HW 6 double d = Math.sqrt(343.0); If the static method is in another class, the class name is needed!

opp() and ?: class Player { private char checker; // data member public char opp() // returns opponent’s checker { } ? : is shorthand for if … else …, but only for deciding between values if else

addMove Class: Board Object: b b.addMove(3,‘X’) ‘X’ ‘O’ changes b by adding checker ‘X’ into row 3 new‘X’ b before b after

Adding a move without changing b ! b before b after Board nextb = b.newAddMove(3,‘X’); a new Board with the move added