Package br.com.ema.maze.character.strategy

Source Code of br.com.ema.maze.character.strategy.GreedyStrategy

/**
*
*/
package br.com.ema.maze.character.strategy;

import br.com.ema.maze.agents.MazeCharacter;
import br.com.ema.maze.components.MazeSpace;

/**
* @author Emanuel Cruz Rodrigues -> emanuelcruzrodrigues@gmail.com
*
*/
public class GreedyStrategy implements MazeCharacterStrategy{

  /* (non-Javadoc)
   * @see br.com.ema.maze.character.strategy.MazeCharacterStrategy#executeStrategy(br.com.ema.maze.agents.MazeCharacter)
   */
  @Override
  public void executeStrategy(MazeCharacter mazeCharacter) {
    /*
     * get the destination and the actual space
     */
    MazeSpace destination = mazeCharacter.getDestination();
    MazeSpace actualSpace = mazeCharacter.getActualSpace();
   
    /*
     * calculates the next step
     */
   
    MazeSpace newSpace = actualSpace.getMinRoute(destination);
   
    /*
     * update the actual step
     */
    actualSpace.removeCharacter(mazeCharacter);
   
    /*
     * setup the new step
     */
    mazeCharacter.setActualSpace(newSpace);
    if (newSpace != null){
      newSpace.putCharacter(mazeCharacter);
    }
  }

}
TOP

Related Classes of br.com.ema.maze.character.strategy.GreedyStrategy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.