Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pacman.entries.pacman;
- import java.util.ArrayList;
- import java.util.Random;
- import pacman.controllers.Controller;
- import pacman.game.Constants.DM;
- import pacman.game.Constants.GHOST;
- import pacman.game.Constants.MOVE;
- import pacman.game.Game;
- public class GregoryKerr201503119 extends Controller<MOVE>
- {
- private MOVE myMove = MOVE.NEUTRAL;
- public MOVE getMove(Game game, long timeDue){
- for(GHOST ghost : GHOST.values()){
- if(game.getGhostLairTime(GHOST.BLINKY) > 0 && game.getGhostLairTime(GHOST.INKY) > 0 && game.getGhostLairTime(GHOST.PINKY) > 0 && game.getGhostLairTime(GHOST.SUE) > 0){
- myMove = getNextMoveTowardsNormalPills(game.getPacmanCurrentNodeIndex(), game);
- }else if(game.getShortestPathDistance(game.getPacmanCurrentNodeIndex(), game.getGhostCurrentNodeIndex(ghost)) < 20){
- myMove = getNextMoveAwayFromGhost(ghost, game.getPacmanCurrentNodeIndex(), game);
- }else if(game.getGhostEdibleTime(ghost) > 0 && game.getShortestPathDistance(game.getPacmanCurrentNodeIndex(), game.getGhostCurrentNodeIndex(ghost)) < 20){
- myMove = getNextMoveTowardsGhost(ghost, game.getPacmanCurrentNodeIndex(), game);
- }else if(game.getActivePillsIndices().length > 0){
- myMove = getNextMoveTowardsPowerPills(game.getPacmanCurrentNodeIndex(), game);
- }else{
- myMove = getNextMoveTowardsNormalPills(game.getPacmanCurrentNodeIndex(), game);
- }
- }
- return myMove;
- }
- public MOVE getNextMoveTowardsPills(GHOST ghost, int pacmanNodeIndex, Game game){
- int pills[] = game.getPillIndices();
- int powerPills[] = game.getPowerPillIndices();
- ArrayList<Integer> activePills = new ArrayList<Integer>();
- for(int i = 0; i < pills.length; i++){
- if(game.isPillStillAvailable(i) == true){
- activePills.add(pills[i]);
- }
- }
- for(int j = 0; j < powerPills.length; j++){
- if(game.isPowerPillStillAvailable(j)== true){
- activePills.add(powerPills[j]);
- }
- }
- int[] activePillsArray = new int[activePills.size()];
- for(int k = 0; k < activePillsArray.length; k++){
- activePillsArray[k] = activePills.get(k);
- }
- for(int l = 0; l < activePillsArray.length; l++){
- if(game.getShortestPathDistance(pacmanNodeIndex, game.getGhostCurrentNodeIndex(ghost)) < game.getShortestPathDistance(pacmanNodeIndex, activePillsArray[l])){
- myMove = getNextMoveAwayFromGhost(ghost, pacmanNodeIndex, game);
- }
- }
- myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex, game.getClosestNodeIndexFromNodeIndex(pacmanNodeIndex, activePillsArray, DM.PATH), DM.PATH);
- return myMove;
- }
- public MOVE getNextMoveAwayFromGhost(GHOST ghost, int pacmanNodeIndex, Game game){
- if(game.getGhostEdibleTime(ghost)==0 && game.getGhostLairTime(ghost)==0){
- myMove = game.getNextMoveAwayFromTarget(game.getPacmanCurrentNodeIndex(),game.getGhostCurrentNodeIndex(ghost),DM.PATH);
- }
- return myMove;
- }
- public MOVE getNextMoveTowardsGhost(GHOST ghost, int pacmanNodeIndex, Game game){
- int minDistance=Integer.MAX_VALUE;
- GHOST minGhost=null;
- if(game.getGhostEdibleTime(ghost) > 20 && game.getGhostLairTime(ghost) == 0){
- int distance=game.getShortestPathDistance(pacmanNodeIndex,game.getGhostCurrentNodeIndex(ghost));
- if(distance<minDistance){
- minDistance=distance;
- minGhost=ghost;
- }
- if(minGhost!=null){
- myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex,game.getGhostCurrentNodeIndex(minGhost),DM.PATH);
- }
- }
- return myMove;
- }
- public MOVE getNextMoveTowardsPowerPills(int pacmanNodeIndex, Game game){
- int powerPills[] = game.getActivePowerPillsIndices();
- for(int i = 0; i < powerPills.length; i++){
- myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex, powerPills[i], DM.PATH);
- }
- return myMove;
- }
- public MOVE getNextMoveTowardsNormalPills(int pacmanNodeIndex, Game game){
- int pills[] = game.getActivePillsIndices();
- for(int i = 0; i < pills.length; i++){
- myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex, pills[i], DM.PATH);
- }
- return myMove;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement