pacman.controllers.examples.RandomGhosts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pacman-main Show documentation
Show all versions of pacman-main Show documentation
The main code for Ms. Pac-Man Vs Ghosts
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