Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pacman.entries.pacman;
- import pacman.controllers.Controller;
- import pacman.game.Constants.DM;
- import pacman.game.Constants.GHOST;
- import pacman.game.Constants.MOVE;
- import pacman.game.Game;
- /*
- * This is the class you need to modify for your entry. In particular, you need to
- * fill in the getAction() method. Any additional classes you write should either
- * be placed in this package or sub-packages (e.g., game.entries.pacman.mypackage).
- */
- public class MyPacMan extends Controller<MOVE>{
- //private MOVE myMove = MOVE.NEUTRAL;
- @Override
- public MOVE getMove(Game game, long timeDue) {
- int MIN_DISTANCE=12;
- int next;
- int current = game.getPacmanCurrentNodeIndex();
- int[] activePills = game.getActivePillsIndices();
- int[] activePowerPills = game.getActivePowerPillsIndices();
- int[] targetNodes = new int[activePills.length+activePowerPills.length];
- int minDistance=Integer.MAX_VALUE;
- GHOST minGhost=null;
- //chase power pills
- for(int i=0; i<activePowerPills.length;i++){
- targetNodes[activePills.length+i] = activePowerPills[i];
- }
- //chase pills
- for(int i=0; i<activePills.length;i++){
- targetNodes[i]=activePills[i];
- }
- //if ghosts can be eaten, eat them
- for(GHOST ghost : GHOST.values()){
- if(game.getGhostEdibleTime(ghost)>0 && game.isGhostEdible(ghost)==true)
- {
- int distance=game.getShortestPathDistance(current,game.getGhostCurrentNodeIndex(ghost));
- if(distance<minDistance)
- {
- minDistance=distance;
- minGhost=ghost;
- }
- }
- }
- if(minGhost!=null){
- return game.getNextMoveTowardsTarget(current,game.getGhostCurrentNodeIndex(minGhost),DM.PATH);
- }
- //run away from ghosts
- for(GHOST ghost : GHOST.values()){
- if(game.getGhostEdibleTime(ghost)==0 && game.getGhostLairTime(ghost)==0 && game.isGhostEdible(ghost)==false){
- if(game.getShortestPathDistance(current,game.getGhostCurrentNodeIndex(ghost))<MIN_DISTANCE){
- return game.getNextMoveAwayFromTarget(current,game.getGhostCurrentNodeIndex(ghost),DM.PATH);
- }
- }
- }
- //chase pills until 4 ghosts out of den and within 12 units
- //then once out and near go for power pill
- //if ghost was eaten, run away
- for(GHOST ghost : GHOST.values()){
- if(game.wasGhostEaten(ghost)==true){
- return game.getNextMoveAwayFromTarget(current,game.getGhostCurrentNodeIndex(ghost),DM.PATH);
- }
- }
- next = game.getClosestNodeIndexFromNodeIndex(current, targetNodes, DM.PATH);
- return game.getNextMoveTowardsTarget(current, next, DM.PATH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement