
pacman.controllers.examples.RandomGhosts Maven / Gradle / Ivy
package pacman.controllers.examples;
import pacman.controllers.Controller;
import pacman.game.Constants.GHOST;
import pacman.game.Constants.MOVE;
import pacman.game.Game;
import java.util.EnumMap;
import java.util.Random;
/*
* The Class RandomGhosts.
*/
public final class RandomGhosts extends Controller> {
private EnumMap moves = new EnumMap(GHOST.class);
private MOVE[] allMoves = MOVE.values();
private Random rnd = new Random();
/* (non-Javadoc)
* @see pacman.controllers.Controller#getMove(pacman.game.Game, long)
*/
public EnumMap getMove(Game game, long timeDue) {
moves.clear();
for (GHOST ghostType : GHOST.values())
if (game.doesGhostRequireAction(ghostType))
moves.put(ghostType, allMoves[rnd.nextInt(allMoves.length)]);
return moves;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy