Você está na página 1de 2

Michael Yoo Matt Brown Robert Hwang GridWorld Problems Part 3 and 4 Set 3 1. 2. 3. 4. 5.

Loc1.getRow(); False 4,4 135 degrees The method tells it which direction to turn because it returns the direction to the neighbor thats 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 doesnt know how many objects are in it, so youd have to go back and count how many. Set 5 1. 2. 3. 4.

Color, direction, location Color blue, direction north An actor runs methods and uses variables, whereas an interface doesnt 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 1. 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 valid get because it ensures if the next spot is empty or taken up by an object 4. getAdjacentLocation() this finds the next possible spot 5. getLocation, getGrid, getDirection 6. bug is removed 7. loc is a variable used to place the flower after the bug moves, so yes it is needed 8. 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

9. No, unless the method that removes the bug from the grid is called 10. Flower flower = new Flower(getColor()); flower.putSelfInGrid(gr, loc); 11. 4 Set 7 1. 2. 3. 4. 5.

act, getActors, processActors, getMoveLocations, selectMoveLocation, makeMove same as answer to 1, excluding act Yes because actors are from different places Make them move, eat them and get rid of them, or change the colors getMoveLocation first called and reveals all possible adjacent locations to move to selectMoveLocation selects a move to random possible adjacent location makeMove moves to the location selected 6. Critter extends actor which has a constructor

Set 8 1. Chameleon critter overrides processActor and makeMove methods 2. makeMove finds the location but super.makeMove actually moves to the location 3. 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 doesnt define new behaviors 5. Actor 6. getGrid Set 9 1. inherits everything from critter class 2. 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 unaffected 3. Determines valid locations it can eat from 4. 4,3 4,4 4,5 5. 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 direction 6. When the location and the parameter loc are the same 7. CrabCritter belongs to the Critter family and inherits all the information from it, and thus will not eat any other critter since critters arent allowed to eat other critters

Você também pode gostar