Question: Look at Rabbit.java. How does Rabbit decide which way to go in doTurn ()? public class Rabbit implements IActor { * char representation of this

 Look at Rabbit.java. How does Rabbit decide which way to go

Look at Rabbit.java. How does Rabbit decide which way to go in doTurn ()?

public class Rabbit implements IActor { * char representation of this type */ public static final char SYMBOL = 'R'; private int hp = getMaxHealth(); @Override public void doTurn(IGameView game) { boolean is Hungry = getMaxHealth()-getCurrentHealth() > 2; if(isHungry) { boolean gotFood = eatifPossible (game); if(!gotFood) { GridDirection dir = selectMove (game, hungry: true); if (game.canGo(dir)) { performMove (game, dir); } else { for (GridDirection randir : GridDirection. EIGHT_DIRECTIONS) { if (randir != dir && randir != GridDirection.CENTER && game.canGo (randir)) { performMove (game, randir); break; } } else { GridDirection dir = selectMove (game, hungry: false); performMove (game, dir); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!