/*---------------------------------------------------------------------------- File: FocusedR.java ----------------------------------------------------------------------------*/ /** * The FocusedR mouse will use a strategy that moves in the same * direction (if possible) turning right if blocked. Because it is * derived from the base class Smarty, it has a memory. * * @version 1.0 11/25/2000 * * @author Andrew Bridges ... Copyright (c) 2001 * */ public class FocusedR extends Smarty { ////////////////////////////////////////////////////////////////////////////// // makeAMove ///////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// /** * For each turn the makeAMove method is called. The FocusedR mouse * will use a strategy that moves in the same direction (if * possible) turning right if blocked. * * @return the direction that we should move. * */ protected Direction makeAMove() { /*------------------------------------------------------------------------ 1. Attempt to go in the same direction. ------------------------------------------------------------------------*/ Direction d = curPosition_.getEnteredDir(); /*------------------------------------------------------------------------ 2. If we are just starting, pick a direction. ------------------------------------------------------------------------*/ if (d.equals(Direction.Undefined)) d = Direction.North; /*------------------------------------------------------------------------ 3. Insure passageway is open ... if not look clockwise. ------------------------------------------------------------------------*/ if (!passagewayOpenAt(d)) d = Direction.clockWiseDir(d); if (!passagewayOpenAt(d)) d = Direction.clockWiseDir(d); if (!passagewayOpenAt(d)) d = Direction.clockWiseDir(d); /*------------------------------------------------------------------------ 4. If all passageways are blocked, retreat. ------------------------------------------------------------------------*/ if (!passagewayOpenAt(d)) d = Direction.Retreat; /*------------------------------------------------------------------------ 5. Return the direction. ------------------------------------------------------------------------*/ return d; /*------------------------------------------------------------------------ Processing End (makeAMove) ------------------------------------------------------------------------*/ } } // end of ... FocusedR class definition