Skip to content

Commit

Permalink
fixed ai selection to include fruits
Browse files Browse the repository at this point in the history
  • Loading branch information
theosirian committed Sep 23, 2016
1 parent 8378eba commit b260fce
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '0.4a'
version = '0.5a'
ext {
appName = 'Pacman'
gdxVersion = '1.6.4'
Expand Down
8 changes: 6 additions & 2 deletions core/src/com/theosirian/pacman/Ai.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
*/
public class Ai {
public static Pacdot decidePacdot(Pacman pacman, List<Pacdot> pacdots) {
Optional<Pacdot> testFruit = pacdots.stream().filter(a -> a instanceof BonusPacdot).findFirst();
if (testFruit.isPresent()) {
return testFruit.get();
}
Optional<Pacdot> nearestOpt = pacdots.stream().min((a, b) -> {
if (a.isDestroy()) return Integer.MIN_VALUE;
else if (b.isDestroy()) return Integer.MAX_VALUE;
else if (a instanceof BonusPacdot) return Integer.MAX_VALUE;
else if (b instanceof BonusPacdot) return Integer.MIN_VALUE;
else if (a.getClass().isInstance(BonusPacdot.class)) return Integer.MAX_VALUE;
else if (b.getClass().isInstance(BonusPacdot.class)) return Integer.MIN_VALUE;
return heuristic_sort(pacman, a.getX(), a.getY(), b.getX(), b.getY());
});
if (nearestOpt.isPresent())
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/theosirian/pacman/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void render() {
aiPacdotTarget = Ai.decidePacdot(pacman, pacdots);
Ai.pathfind(pacmanGraph, pacman, stepQueue, teleportHashes, aiPacdotTarget);
aiTargetPosition.set(pacman.getX(), pacman.getY());
System.out.println("Pathfinding! " + stepQueue.size() + " new steps.");
// System.out.println("Pathfinding! " + stepQueue.size() + " new steps.");
pacman.setDirection(NONE);
} else {
Entity.Direction dir = stepQueue.poll();
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/theosirian/pacman/pacdot/BonusPacdot.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public BonusPacdot(int x, int y, Pacman player) {
setBounds(getX() + 4, getY() + 4, 8, 8);
worth = Math.min(accumalativeBonus >= 1000 ? 500 + accumalativeBonus : 200 + accumalativeBonus, 5000);
accumalativeBonus = worth;
currentFrame = new TextureRegion(sprite, textureIndex * Settings.SPRITE_WIDTH, 0, Settings.SPRITE_WIDTH, Settings.SPRITE_HEIGHT);
targetedFrame = new TextureRegion(sprite, textureIndex * Settings.SPRITE_WIDTH, 16, Settings.SPRITE_WIDTH, Settings.SPRITE_HEIGHT);
currentFrame = new TextureRegion(sprite, textureIndex * Settings.SPRITE_WIDTH, 16, Settings.SPRITE_WIDTH, Settings.SPRITE_HEIGHT);
targetedFrame = new TextureRegion(sprite, textureIndex * Settings.SPRITE_WIDTH, 0, Settings.SPRITE_WIDTH, Settings.SPRITE_HEIGHT);
textureIndex = (textureIndex + 1) % (sprite.getWidth() / 16);
timer = 0;
}
Expand Down

0 comments on commit b260fce

Please sign in to comment.