1 / 44

Intelligent CS 5 ?

Today’s Lab:. Intelligent CS 5 ?. M-Z. Chess is the Drosophila of artificial intelligence. - Alexander Kronrod. The computer that defeated Garry Kasparov 1997. Games: computers vs. humans…. due Sunday, 11/14 at midnight. M/T sections. HW 11 ( 1 problem ! ).

mayda
Télécharger la présentation

Intelligent CS 5 ?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

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

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

  7. 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?

  8. Winning: Details (compact version) 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; }

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

  10. Hw10 Hw11 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 } } Objects hide details!

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

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

  13. class Player { 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 { }

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

  15. Hw10 Hw11 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 } }

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

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

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

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

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

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

  22. Write breaktie to return a randomly chosen best score (max score) from an array of scores named s. 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 */ { } } }

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

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

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

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

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

  28. ply1 public double[] ply1(Board b) {

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

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

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

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

  33. How humans play games… An experiment (by deGroot) was performed in which chess positions were shown to novice and expert players… - 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!

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

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

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

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

  38. Write breaktie to return a randomly chosen best score (max score) from an array of scores named s. 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 */ { } } }

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

  40. Winning -- details complete HW10PR2 solutions athttp://www.cs.hmc.edu/courses/2002/fall/cs5/week_10/sols.html 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; } finds this diagonal: | | | | | | | | | | | | | | | | | |X| | | | | | | |O|X|O| | | | | |O|X|X| |O|O| |X|O|O|X|X|O|X| --------------- 0 1 2 3 4 5 6.

  41. 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!

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

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

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

More Related