1 / 16

Homework 12

Homework 12. Sun., 11/24. ( MT sections ). Due . Mon., 11/25. ( WTh sections ). Problems (2 of them). http://www.cs.hmc.edu/courses/2002/fall/cs5/week_12/homework.html. Tutors available. Saturday afternoons Lac Lab Sunday afternoons Lac Lab

ryanadan
Download Presentation

Homework 12

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. Homework 12 Sun., 11/24 ( MT sections ) • Due Mon., 11/25 ( WTh sections ) • Problems (2 of them) http://www.cs.hmc.edu/courses/2002/fall/cs5/week_12/homework.html • Tutors available Saturday afternoons Lac Lab Sunday afternoons Lac Lab Sunday evenings Lac Lab and AC Monday evenings Lac Lab and AC M. Beaumont-Gay & M. Yi in LAC E. Flynn, Y.M. Kim, & A. Klose in AC M. Yi, C. Wottawa, & A. Utter in LAC A. Kangas, P. Scott, A. Pipkin in AC

  2. Problem 2 / Final Project A “film database” application: 5 classes class name data member data member type

  3. Self-referential data ? A film database application: class Director class Director { private String fname; private String lname; private FilmDB filmDB; // method skeletons… FilmDB filmDB String fname FilmDB filmDB String lname class Film class Film { // data members // method skeletons String rating String title double review Director int year Director dir dir class FilmDB class FilmDB { // data members // method skeletons int count Film[] films[0] films[1] Film[] films films

  4. Problem 2 - skeleton code Data Members Methods Classes CS5App public static void main(String[] args) public static void printMenu() none Film public Film(String title, int year, String rating, double review, Director dir) public String getTitle() public int getYear() public String getRating() public double getReview() public void display() String title int year String rating double review Director dir

  5. Data Members Methods Classes Director public Director(String fname, String lname, int capacity) public String getFullName() public FilmDB getFilmDB() String fname String lname FilmDB filmDB public DirectorDB(int capacity) public void displayAllDirectors() public void displayFilmsByDirector(String fname, String lname) public Director findDirectorByName(String fname, String lname) public void addDirector(Director dir) public int getCount() public boolean isFull() int count Director[] dirs DirectorDB FilmDB public FilmDB(int capacity) public boolean isFull() public int getCount() public void addFilm(Film f) public Film findFilmByTitle(String title) public void displayAllFilms() public void displayFilmsByTitle(String titlepiece) public void displayFilmsByYear(int year) public void displayFilmsByRating(String rating) public void displayFilmsByReview(double minreview) int count Film[] Films

  6. Problem 2 • Implement the main menu (in the CS5App class) Please choose an action from the following list: 0 Display All Directors 1 Display All Films 2 Display Films by Title 3 Display Films by Director 4 Display Films by Year 5 Display Films by Rating (G, PG, …) 6 Display Films by Review (0 to 10) 7 Add a New Film 9 Quit • Create skeleton versions of the necessary classes...

  7. Care to Swap ? Suppose we want to swap the variables x and y … int x = 42; int y = 5; int y int x

  8. Problem 1 - recursion void sort(double[] arr, int L, int H) 80 97 42 75 23 L H

  9. Iterative vs. Recursive vs. Recursive void moveMinToLeft(double[] arr, int L, int H) 80 97 42 75 23 L H

  10. Iterative vs. Recursive void moveMinToLeft(double[] arr, int L, int H) 80 97 42 75 23 L H

  11. Swapping Suppose we want to swap the H-1st and the Hth values... 80 97 42 75 23 L H-1 H

  12. Problem 1 - recursion void sort(double[] arr, int L, int H) 80 97 42 75 23 L H

  13. Problem 1 - recursion public static double harmonic(int N)

  14. Problem 1 - recursion public static String reverse(int N)

  15. public static int chooseMove3Ply(Board b, char ox) for (int m=0 ; m<b.getCols() ; ++m) { if (b.allowsMove(m)) { Board b2 = b.newAddMove(m,ox); if ( b2.winsFor(ox) || b2.isFull() ) score = evaluate(b,ox); else { int m2 = chooseMove2Ply(b2,opp(ox)); Board b3 = b2.newAddMove(m2,opp(ox)); if ( b3.winsFor(opp(ox)) || b3.isFull() ) score = evaluate(b,ox); else { int m3 = chooseMove1Ply(b3,ox); Board b4 = b3.newAddMove(m3, ox); score = evaluate(b4, ox); } } if (score > BSSF) { BSSF = score; BMSF = m; } } // end if (b.allowsMove(m)) } // end for (int m=0 ; … return BMSF; Ex. Cr. evaluating move m by finding score remembering the best score and the best move m so far

  16. Looking N Ply ahead! 1-ply search 2-ply search 3-ply search N-ply search chooseMove1Ply chooseMove2Ply chooseMove3Ply evaluate (N-1) - ply ... 2 - ply 1 - ply int chooseMove(Board b, char ox, int ply) With a 4-ply lookahead, X will think every move looks equivalent on this board With a 5-ply lookahead, X will know to move to column 3 ‘X’ ‘O’ 4 6 1 3 0 2 5

More Related