Homework 12
Download
1 / 16

Homework 12 Due MT sections - PowerPoint PPT Presentation


  • 164 Views
  • Updated On :

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

Related searches for Homework 12 Due MT sections

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Homework 12 Due MT sections ' - ryanadan


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Slide1 l.jpg

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


Slide2 l.jpg

Problem 2 / Final Project

A “film database” application: 5 classes

class name

data member

data member type


Slide3 l.jpg

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


Slide4 l.jpg

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


Slide5 l.jpg

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


Slide6 l.jpg

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


Slide7 l.jpg

Care to Swap ?

Suppose we want to swap the variables x and y …

int x = 42;

int y = 5;

int y

int x


Slide8 l.jpg

Problem 1 - recursion

void sort(double[] arr, int L, int H)

80

97

42

75

23

L

H


Slide9 l.jpg

Iterative vs. Recursive

vs. Recursive

void moveMinToLeft(double[] arr, int L, int H)

80

97

42

75

23

L

H


Slide10 l.jpg

Iterative vs. Recursive

void moveMinToLeft(double[] arr, int L, int H)

80

97

42

75

23

L

H


Slide11 l.jpg

Swapping

Suppose we want to swap the H-1st and the Hth values...

80

97

42

75

23

L

H-1

H


Slide12 l.jpg

Problem 1 - recursion

void sort(double[] arr, int L, int H)

80

97

42

75

23

L

H


Slide13 l.jpg

Problem 1 - recursion

public static double harmonic(int N)


Slide14 l.jpg

Problem 1 - recursion

public static String reverse(int N)


Slide15 l.jpg

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


Slide16 l.jpg

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


ad