gridworld questions

3
Michael Yoo Matt Brown Robert Hwang GridWorld Problems Part 3 and 4 Set 3 1. Loc1.getRow(); 2. False 3. 4,4 4. 135 degrees 5. The method tells it which direction to turn because it returns the direction to the neighbor that’s closest to the direction it is facing Set 4 1. Gr.getOccupiedLocations().size() shows filled spots in the grid Gr.getNumRows() times gr.getNumCols() minus the gr.getOccupidLocations().size() shows the empty spots in the grid 2. Gr.isValid(new Location(10,10)); 3. The grid is an interface. Find them in abstractGrid, unboundedgrid, and boundedgrid. 4. No because the grid doesn’t know how many objects are in it, so you’d have to go back and count how many. Set 5 1. Color, direction, location 2. Color – blue, direction – north 3. An actor runs methods and uses variables, whereas an interface doesn’t 4. No, the program will compile but error (IllegalStateException). The actor cannot be removed again. The actor can remove itself then replace itself though. 5. By using the setDirection method setDirection(getLocation() + 90). The 90 is a full turn right indicating that it will turn 90 degrees to the right. Set 6

Upload: michael-yoo

Post on 28-Apr-2015

18 views

Category:

Documents


1 download

DESCRIPTION

ff

TRANSCRIPT

Page 1: GridWorld Questions

Michael YooMatt BrownRobert HwangGridWorld Problems Part 3 and 4

Set 31. Loc1.getRow();2. False3. 4,44. 135 degrees5. The method tells it which direction to turn because it returns the direction to the neighbor

that’s closest to the direction it is facing

Set 41. Gr.getOccupiedLocations().size() shows filled spots in the grid

Gr.getNumRows() times gr.getNumCols() minus the gr.getOccupidLocations().size() shows the empty spots in the grid

2. Gr.isValid(new Location(10,10));3. The grid is an interface. Find them in abstractGrid, unboundedgrid, and boundedgrid. 4. No because the grid doesn’t know how many objects are in it, so you’d have to go back

and count how many.

Set 51. Color, direction, location2. Color – blue, direction – north3. An actor runs methods and uses variables, whereas an interface doesn’t4. No, the program will compile but error (IllegalStateException). The actor cannot be

removed again. The actor can remove itself then replace itself though.5. By using the setDirection method

setDirection(getLocation() + 90). The 90 is a full turn right indicating that it will turn 90 degrees to the right.

Set 61. if(!gr.isValid(next)){

return false;}

2. Actor neighbor = gr.get(next); return (neighbor == null) || (neighbor instanceof Flower);

3. isValid because it checks if the space ahead is validget because it ensures if the next spot is empty or taken up by an object

4. getAdjacentLocation() – this finds the next possible spot5. getLocation, getGrid, getDirection6. bug is removed7. loc is a variable used to place the flower after the bug moves, so yes it is needed8. So you know where the bug has been and for how long, so you can see if all the flowers

are wilting at the same pace

Page 2: GridWorld Questions

9. No, unless the method that removes the bug from the grid is called10. Flower flower = new Flower(getColor());

flower.putSelfInGrid(gr, loc);11. 4

Set 71. act, getActors, processActors, getMoveLocations, selectMoveLocation, makeMove2. same as answer to 1, excluding act3. Yes because actors are from different places4. Make them move, eat them and get rid of them, or change the colors5. getMoveLocation – first called and reveals all possible adjacent locations to move to

selectMoveLocation – selects a move to random possible adjacent locationmakeMove – moves to the location selected

6. Critter extends actor which has a constructor

Set 81. Chameleon critter overrides processActor and makeMove methods2. makeMove finds the location but super.makeMove actually moves to the location3. use a variable to track current location and if the current location changes then add a

flower to the previous location (the variable)4. Chameleon critter doesn’t define new behaviors5. Actor6. getGrid

Set 91. inherits everything from critter class2. Eats anything adjacent to it and that is either in front of it or to the 2 corners, in other

words the 3 spaces in front of it. Anything else unaffected3. Determines valid locations it can eat from4. 4,3 4,4 4,55. They both move in a random direction that is valid. A crab critter moves either left or

right and turns. A normal critter can move any direction6. When the location and the parameter loc are the same7. CrabCritter belongs to the Critter family and inherits all the information from it, and thus

will not eat any other critter since critters aren’t allowed to eat other critters