Tuesday, 22 February 2011

Grid World Part 4 Part 2

        

Gridworld: Part 4: Interacting Objects: Set 9: Page 35





1
Why doesn’t CrabCritter override the processActors() method?  
 It doesn't override the processActors() method because the implementation of the method in the critter class is to eat other actors, and the crab does the same with movement restrictions and eating restrictions.
2
Describe the process a CrabCritter uses to find and eat other actors.

Does it always eat all neighboring actors?

Explain.  
 After moving either left or right (depending on the random value) it will check if a neighbor which is not a rock and is a critter is in front, front left, or front right of it and remove it. It won't eat all neighboring actors if they aren't critters, or if they're a rock. This because of the implementation of the processActors() in the critter class.
3
Why is the getLocationsInDirections() method used in CrabCritter?  
 I am not sure about this question. I can't really understand the getLocationsInDirections() method.
4
If a CrabCritter has location (3, 4) and faces south, what are the possible locations for actors that are returned by a call to the getActors()  method?  
 I was under the impression that getActors() returns all actors in the grid, but I assume it is only the locations around the critter, therefore they would be (2,3), (3,3), (4, 3), (2,4), (4,4), (2,5), (3, 5), (4, 5).
5
What are the similarities and differences between the movements of a CrabCritter and a Critter?  
 CrabCritter moves in each call of act(), just as critter does; however, it can only move right, left, or turn 90 degrees either left or right, and relies on random values in order to determine its movement.
6
How does a CrabCritter determine when it turns instead of moving?  
 It checks whether it's movement is blocked in any direction. If it is, then it turns instead of moving.
7
Why don’t the CrabCritter objects eat each other?  
 I thought CrabCritter objects can eat each other... there seems to be no part of the code which suggests otherwise.















No comments:

Post a Comment