Skip to content

Commit

Permalink
Found bug where there are no more normal pills left, now pacman heads…
Browse files Browse the repository at this point in the history
… for power pills in normal mode
  • Loading branch information
tylorr committed Feb 2, 2012
1 parent 161beeb commit f762d0d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
3 changes: 2 additions & 1 deletion game/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static void main(String[] args)
//exec.runMyExperiment(new Legacy2TheReckoning(), 100, 80, 95, 1);

//this can be used for numerical testing (non-visual, no delays)
exec.runExperiment(new MyPacMan(),new MyGhosts(),100);
//exec.runExperiment(new MyPacMan(),new RandomGhosts(),100);
exec.runGameTimed(new MyPacMan(), new RandomGhosts(), true);


//run game without time limits (un-comment if required)
Expand Down
56 changes: 32 additions & 24 deletions game/entries/pacman/NearestPillAvoidPowerAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,43 @@ public int act(Game game) {
//get all active power pills
int[] activePowerPills = game.getPowerPillIndicesActive();

// find closest pill
int target = game.getTarget(current, activePills, true, Game.DM.PATH);

// find path from pacman to pill
int[] path = game.getPath(current, target);

boolean powerExists = false;
int powerLocation = -1;

// Check for a power pill in the path
for (int i = 0; (i < path.length) && !powerExists; i++) {
for (int j = 0; j < activePowerPills.length; j++) {
if (path[i] == activePowerPills[j]) {
powerExists = true;
powerLocation = activePowerPills[j];
break;
if (activePills.length > 0) {

// find closest pill
int target = game.getTarget(current, activePills, true, Game.DM.PATH);

// find path from pacman to pill
int[] path = game.getPath(current, target);

boolean powerExists = false;
int powerLocation = -1;

// Check for a power pill in the path
for (int i = 0; (i < path.length) && !powerExists; i++) {
for (int j = 0; j < activePowerPills.length; j++) {
if (path[i] == activePowerPills[j]) {
powerExists = true;
powerLocation = activePowerPills[j];
break;
}
}
}

// if power pill in path
// move away from power pill
if (powerExists) {
return game.getNextPacManDir(powerLocation, false, Game.DM.PATH);
}

// otherwise, head straight for the pill
else {
return game.getNextPacManDir(target, true, Game.DM.PATH);
}
}

// if power pill in path
// move away from power pill
if (powerExists) {
return game.getNextPacManDir(powerLocation, false, Game.DM.PATH);
}

// otherwise, head straight for the pill
// only power pills left
else {
return game.getNextPacManDir(target, true, Game.DM.PATH);
return game.getNextPacManDir(game.getTarget(current, activePowerPills, true, Game.DM.PATH), true, Game.DM.PATH);
}
}
}

0 comments on commit f762d0d

Please sign in to comment.