Grid World Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Location class constructor:

A

public Location(int row, int col)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Location accessor methods:

A

public int getRow();

public int getCol();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Location objects are _______

A

immutable. Once created, a Location object CANNOT change.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Location implements ________ and provides a _________ method that compares locations first by ____ and then, if equal, by _____.

A

Comparable, compareTo, row, column. Location also overrides Object’s equals method in a manner consistent with compareTo.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Location’s toString method converts a ____ into a ____

A

location, string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The Location class defines eight public constants:

A
public static final int NORTH = 0;
public static final int NORTHEAST = 45;
public static final int EAST = 90;
public static final int SOUTHEAST = 135;
public static final int SOUTH = 180;
public static final int SOUTHWEST = 225;
public static final int WEST = 270;
public static final int NORTHWEST = 315;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Seven more constants represent turns, with right turns being ______ and left turns _____

A

positive, negative.

public static final int AHEAD = 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Location’s getAdjacentLocation(int dir) method:

A

returns the location that is adjacent to this location in the compass direction dir. Locations that touch in a corner are considered adjacent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Location’s getDirectionToward(Location other) method:

A

returns the compass direction (in degrees) from this location to other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Grid int numRows() method:

A

returns the number of rows for a bounded grid; -1 for an unbounded grid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Grid int numCols() method:

A

returns the number of columns for a bounded grid; -1 for an unbounded grid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Grid boolean isValid(Location loc) method:

A

returns true if loc is valid in this grid (always true for an unbounded grid). DOES NOT tell whether or not the space is occupied

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Grid E get(Location loc) method:

A

returns the object at loc (or null if loc is empty)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Grid E put(Location loc, E obj) method:

A

puts obj at loc and returns the object previously at loc (or null if loc was empty)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Grid E remove(Location loc) method:

A

Removes the object at loc and returns that object (or null if loc was empty)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Grid ArrayList getOccupiedLocations() method:

A

returns the list of all occupied locations in the grid

17
Q

Grid ArrayList getValidAdjacentLocations(Location loc) method:

A

Returns a list of all valid locations adjacent to loc

18
Q

Grid ArrayList getEmptyAdjacentLocations(Location loc) method:

A

returns a list of all valid empty locations adjacent to loc

19
Q

Grid ArrayList getOccupiedAdjacentLocations(Location loc) method:

A

returns a list of all valid occupied locations adjacent to loc

20
Q

Grid ArrayList getNeighbors(Location loc) method:

A

returns a list of all objects in the occupied locations adjacent to loc