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 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
Get step-by-step solutions from verified subject matter experts
