All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pacman.controllers.examples.RandomGhosts Maven / Gradle / Ivy

There is a newer version: 2.0.1.0
Show newest version
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