Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. package pacman.entries.pacman;
  2.  
  3. import pacman.controllers.Controller;
  4. import pacman.game.Constants.DM;
  5. import pacman.game.Constants.GHOST;
  6. import pacman.game.Constants.MOVE;
  7. import pacman.game.Game;
  8.  
  9. /*
  10. * This is the class you need to modify for your entry. In particular, you need to
  11. * fill in the getAction() method. Any additional classes you write should either
  12. * be placed in this package or sub-packages (e.g., game.entries.pacman.mypackage).
  13. */
  14. public class MyPacMan extends Controller<MOVE>{
  15.  
  16. //private MOVE myMove = MOVE.NEUTRAL;
  17.  
  18. @Override
  19. public MOVE getMove(Game game, long timeDue) {
  20.  
  21. int MIN_DISTANCE=12;
  22. int next;
  23. int current = game.getPacmanCurrentNodeIndex();
  24. int[] activePills = game.getActivePillsIndices();
  25. int[] activePowerPills = game.getActivePowerPillsIndices();
  26. int[] targetNodes = new int[activePills.length+activePowerPills.length];
  27. int minDistance=Integer.MAX_VALUE;
  28. GHOST minGhost=null;
  29.  
  30. //chase power pills
  31.  
  32. for(int i=0; i<activePowerPills.length;i++){
  33.  
  34. targetNodes[activePills.length+i] = activePowerPills[i];
  35.  
  36. }
  37.  
  38. //chase pills
  39. for(int i=0; i<activePills.length;i++){
  40.  
  41. targetNodes[i]=activePills[i];
  42.  
  43. }
  44.  
  45.  
  46.  
  47. //if ghosts can be eaten, eat them
  48. for(GHOST ghost : GHOST.values()){
  49. if(game.getGhostEdibleTime(ghost)>0 && game.isGhostEdible(ghost)==true)
  50. {
  51. int distance=game.getShortestPathDistance(current,game.getGhostCurrentNodeIndex(ghost));
  52.  
  53.  
  54. if(distance<minDistance)
  55. {
  56. minDistance=distance;
  57. minGhost=ghost;
  58. }
  59. }
  60. }
  61.  
  62. if(minGhost!=null){
  63. return game.getNextMoveTowardsTarget(current,game.getGhostCurrentNodeIndex(minGhost),DM.PATH);
  64. }
  65.  
  66. //run away from ghosts
  67. for(GHOST ghost : GHOST.values()){
  68. if(game.getGhostEdibleTime(ghost)==0 && game.getGhostLairTime(ghost)==0 && game.isGhostEdible(ghost)==false){
  69. if(game.getShortestPathDistance(current,game.getGhostCurrentNodeIndex(ghost))<MIN_DISTANCE){
  70. return game.getNextMoveAwayFromTarget(current,game.getGhostCurrentNodeIndex(ghost),DM.PATH);
  71. }
  72. }
  73. }
  74.  
  75. //chase pills until 4 ghosts out of den and within 12 units
  76. //then once out and near go for power pill
  77.  
  78. //if ghost was eaten, run away
  79. for(GHOST ghost : GHOST.values()){
  80. if(game.wasGhostEaten(ghost)==true){
  81. return game.getNextMoveAwayFromTarget(current,game.getGhostCurrentNodeIndex(ghost),DM.PATH);
  82. }
  83. }
  84.  
  85. next = game.getClosestNodeIndexFromNodeIndex(current, targetNodes, DM.PATH);
  86.  
  87. return game.getNextMoveTowardsTarget(current, next, DM.PATH);
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement