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

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

/**
*
*/
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 AStarStrategy implements MazeCharacterStrategy{
 
  private long memoryInMiliseconds;
 
  public AStarStrategy(long memoryInMiliseconds) {
    super();
    this.memoryInMiliseconds = memoryInMiliseconds;
  }

  /* (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();
    if (destination == null) return;
    MazeSpace actualSpace = mazeCharacter.getActualSpace();
    if (actualSpace == null) return;

    /*
     * calculates the next step
     */
    MazeSpace newSpace = actualSpace.getMinOriginalRoute(mazeCharacter, destination, memoryInMiliseconds);
    if (newSpace == null) return;

    /*
     * update the actual step
     */
    actualSpace.removeCharacter(mazeCharacter);

    /*
     * setup the new step
     */
    mazeCharacter.setActualSpace(newSpace);
    newSpace.putCharacter(mazeCharacter);


  }

}
 
TOP

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

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.