Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. package pacman.entries.pacman;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import pacman.controllers.Controller;
  7. import pacman.game.Constants.DM;
  8. import pacman.game.Constants.GHOST;
  9. import pacman.game.Constants.MOVE;
  10. import pacman.game.Game;
  11.  
  12. public class GregoryKerr201503119 extends Controller<MOVE>
  13. {
  14. private MOVE myMove = MOVE.NEUTRAL;
  15.  
  16. public MOVE getMove(Game game, long timeDue){
  17.  
  18. for(GHOST ghost : GHOST.values()){
  19. if(game.getGhostLairTime(GHOST.BLINKY) > 0 && game.getGhostLairTime(GHOST.INKY) > 0 && game.getGhostLairTime(GHOST.PINKY) > 0 && game.getGhostLairTime(GHOST.SUE) > 0){
  20. myMove = getNextMoveTowardsNormalPills(game.getPacmanCurrentNodeIndex(), game);
  21. }else if(game.getShortestPathDistance(game.getPacmanCurrentNodeIndex(), game.getGhostCurrentNodeIndex(ghost)) < 20){
  22. myMove = getNextMoveAwayFromGhost(ghost, game.getPacmanCurrentNodeIndex(), game);
  23. }else if(game.getGhostEdibleTime(ghost) > 0 && game.getShortestPathDistance(game.getPacmanCurrentNodeIndex(), game.getGhostCurrentNodeIndex(ghost)) < 20){
  24. myMove = getNextMoveTowardsGhost(ghost, game.getPacmanCurrentNodeIndex(), game);
  25. }else if(game.getActivePillsIndices().length > 0){
  26. myMove = getNextMoveTowardsPowerPills(game.getPacmanCurrentNodeIndex(), game);
  27. }else{
  28. myMove = getNextMoveTowardsNormalPills(game.getPacmanCurrentNodeIndex(), game);
  29. }
  30. }
  31.  
  32. return myMove;
  33.  
  34. }
  35.  
  36. public MOVE getNextMoveTowardsPills(GHOST ghost, int pacmanNodeIndex, Game game){
  37.  
  38. int pills[] = game.getPillIndices();
  39. int powerPills[] = game.getPowerPillIndices();
  40. ArrayList<Integer> activePills = new ArrayList<Integer>();
  41.  
  42. for(int i = 0; i < pills.length; i++){
  43. if(game.isPillStillAvailable(i) == true){
  44. activePills.add(pills[i]);
  45. }
  46. }
  47. for(int j = 0; j < powerPills.length; j++){
  48. if(game.isPowerPillStillAvailable(j)== true){
  49. activePills.add(powerPills[j]);
  50. }
  51. }
  52.  
  53. int[] activePillsArray = new int[activePills.size()];
  54.  
  55. for(int k = 0; k < activePillsArray.length; k++){
  56. activePillsArray[k] = activePills.get(k);
  57. }
  58.  
  59. for(int l = 0; l < activePillsArray.length; l++){
  60. if(game.getShortestPathDistance(pacmanNodeIndex, game.getGhostCurrentNodeIndex(ghost)) < game.getShortestPathDistance(pacmanNodeIndex, activePillsArray[l])){
  61. myMove = getNextMoveAwayFromGhost(ghost, pacmanNodeIndex, game);
  62. }
  63. }
  64. myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex, game.getClosestNodeIndexFromNodeIndex(pacmanNodeIndex, activePillsArray, DM.PATH), DM.PATH);
  65.  
  66. return myMove;
  67. }
  68.  
  69. public MOVE getNextMoveAwayFromGhost(GHOST ghost, int pacmanNodeIndex, Game game){
  70.  
  71. if(game.getGhostEdibleTime(ghost)==0 && game.getGhostLairTime(ghost)==0){
  72. myMove = game.getNextMoveAwayFromTarget(game.getPacmanCurrentNodeIndex(),game.getGhostCurrentNodeIndex(ghost),DM.PATH);
  73. }
  74. return myMove;
  75. }
  76.  
  77. public MOVE getNextMoveTowardsGhost(GHOST ghost, int pacmanNodeIndex, Game game){
  78.  
  79. int minDistance=Integer.MAX_VALUE;
  80. GHOST minGhost=null;
  81.  
  82. if(game.getGhostEdibleTime(ghost) > 20 && game.getGhostLairTime(ghost) == 0){
  83. int distance=game.getShortestPathDistance(pacmanNodeIndex,game.getGhostCurrentNodeIndex(ghost));
  84. if(distance<minDistance){
  85. minDistance=distance;
  86. minGhost=ghost;
  87. }
  88. if(minGhost!=null){
  89. myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex,game.getGhostCurrentNodeIndex(minGhost),DM.PATH);
  90. }
  91. }
  92. return myMove;
  93. }
  94.  
  95. public MOVE getNextMoveTowardsPowerPills(int pacmanNodeIndex, Game game){
  96.  
  97. int powerPills[] = game.getActivePowerPillsIndices();
  98.  
  99. for(int i = 0; i < powerPills.length; i++){
  100. myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex, powerPills[i], DM.PATH);
  101. }
  102. return myMove;
  103. }
  104.  
  105. public MOVE getNextMoveTowardsNormalPills(int pacmanNodeIndex, Game game){
  106.  
  107. int pills[] = game.getActivePillsIndices();
  108.  
  109. for(int i = 0; i < pills.length; i++){
  110. myMove = game.getNextMoveTowardsTarget(pacmanNodeIndex, pills[i], DM.PATH);
  111. }
  112. return myMove;
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement