diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 51011c5..9b75f59 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,15 @@
-
+
+
+
+
+
+
+
+
+
@@ -15,8 +23,8 @@
-
-
+
+
@@ -25,18 +33,37 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -62,26 +89,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -95,18 +102,28 @@
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -114,6 +131,16 @@
+
+
+
+
+
+
@@ -124,6 +151,7 @@
+
@@ -141,11 +169,12 @@
-
+
-
+
+
@@ -284,6 +313,9 @@
+
+
+
@@ -418,27 +450,26 @@
1522399004038
-
+
-
+
-
-
+
-
+
-
+
-
-
+
+
@@ -448,7 +479,7 @@
-
+
@@ -472,31 +503,68 @@
-
+
+
+ file://$PROJECT_DIR$/src/main/java/ReinaudLovesPacman/MyPacMan.java
+ 92
+
+
+
+
+
- game.getGhostLairTime(Constants.GHOST.BLINKY)
+ game.getGhostCurrentNodeIndex(Constants.GHOST.PINKY)
+ JAVA
+ pacman.game.Constants
+ EXPRESSION
+
+
+ game.getGhostCurrentNodeIndex(Constants.GHOST.INKY)
+ JAVA
+ pacman.game.Constants
+ EXPRESSION
+
+
+ game.getGhostCurrentNodeIndex(Constants.GHOST.SUE)
JAVA
pacman.game.Constants
EXPRESSION
- game.ghosts
+ ghostScores
+ JAVA
+ EXPRESSION
+
+
+ ghostScore(game, index)
JAVA
EXPRESSION
- game.ghosts
+ game.getGhostLairTime(Constants.GHOST.PINKY)
JAVA
pacman.game.Constants
EXPRESSION
- game.isGhostEdible(Constants.GHOST.BLINKY)
+ game.getGhostLairTime(Constants.GHOST.SUE)
+ JAVA
+ pacman.game.Constants
+ EXPRESSION
+
+
+ game.getGhostLairTime(Constants.GHOST.BLINKY)
+ JAVA
+ pacman.game.Constants
+ EXPRESSION
+
+
+ game.isGhostEdible(Constants.GHOST.SUE)
JAVA
pacman.game.Constants
EXPRESSION
@@ -525,8 +593,8 @@
-
-
+
+
@@ -584,8 +652,8 @@
-
-
+
+
@@ -894,34 +962,67 @@
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 3502fbb..77813ea 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -12,6 +12,8 @@
import java.util.EnumMap;
+import static pacman.game.internal.POType.RADIUS;
+
/**
* Created by pwillic on 06/05/2016.
@@ -22,6 +24,7 @@ public static void main(String[] args) {
Executor executor = new Executor.Builder()
.setVisual(true)
+ .setPOType(RADIUS)
.setTickLimit(4000)
.build();
diff --git a/src/main/java/ReinaudLovesPacman/MyPacMan.java b/src/main/java/ReinaudLovesPacman/MyPacMan.java
index 89aea95..954a9e6 100644
--- a/src/main/java/ReinaudLovesPacman/MyPacMan.java
+++ b/src/main/java/ReinaudLovesPacman/MyPacMan.java
@@ -1,18 +1,17 @@
package ReinaudLovesPacman;
-import pacman.controllers.MASController;
+import ReinaudLovesPacman.resource.NextStep;
import pacman.controllers.PacmanController;
-import pacman.controllers.examples.po.POCommGhosts;
import pacman.game.Constants;
import pacman.game.Game;
import pacman.game.info.GameInfo;
import pacman.game.internal.Ghost;
-import pacman.game.internal.Maze;
+import sun.security.krb5.internal.crypto.CksumType;
import java.util.*;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
+import java.util.stream.Collectors;
+import static java.util.stream.Collectors.summarizingDouble;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
@@ -23,41 +22,83 @@ public class MyPacMan extends PacmanController {
@Override
public Constants.MOVE getMove(Game game, long timeDue) {
- Game coGame;
- GameInfo info = game.getPopulatedGameInfo();
- info.fixGhosts((ghost) -> new Ghost(
- ghost,
- game.getCurrentMaze().lairNodeIndex,
- -1,
- -1,
- Constants.MOVE.NEUTRAL
- ));
- coGame = game.getGameFromInfo(info);
-
List eatThem = Arrays.stream(Constants.GHOST.values())
- .filter(ghost -> game.getGhostLairTime(ghost) >= 0)
- .filter(ghost -> game.isGhostEdible(ghost))
+ .filter(ghost -> Optional.ofNullable(game.isGhostEdible(ghost)).orElse(false))
.map(ghost -> game.getGhostCurrentNodeIndex(ghost))
.collect(toList());
- return getBestOptionToIndexies(game, eatThem.size() > 0 ? eatThem.stream().mapToInt(i->i).toArray() : game.getActivePillsIndices());
+ return getBestOptionToIndexies(game, ghostsOrPill(game, eatThem));
+ }
+
+ private int[] ghostsOrPill(Game game, List eatThem) {
+ if(eatThem.size() >= 4) {
+ System.out.println("Ghosts --> ");
+ return eatThem.stream().mapToInt(i->i).toArray();
+ } else {
+ System.out.println("Pill --> ");
+ return game.getActivePillsIndices();
+ }
}
private Constants.MOVE getBestOptionToIndexies(Game game, int[] indexes) {
int pacManIndex = game.getPacmanCurrentNodeIndex();
- Map closestPill = new HashMap<>();
+ List closestIndex = new ArrayList<>();
+
+ for(Integer index : indexes) {
+ int distance = game.getShortestPathDistance(pacManIndex, index);
+ Constants.MOVE move = game.getNextMoveTowardsTarget(pacManIndex, index, Constants.DM.PATH);
+ int neighbourIndex = game.getNeighbour(pacManIndex, move);
+ double score = distance + ghostScore(game, neighbourIndex);
+ if(score > 100) {
+ move = game.getNextMoveAwayFromTarget(pacManIndex, neighbourIndex, Constants.DM.PATH);
+ }
+ closestIndex.add(new NextStep(index, move, neighbourIndex, score));
+ }
+
+ return closestIndex.stream()
+ .sorted(Comparator.comparing(NextStep::getScore))
+ .findFirst()
+ .map(NextStep::getFirstMove)
+ .orElseGet(() -> getClosetsJunction(game, pacManIndex));
+ }
- for(Integer pillIndex : indexes) {
- int distance = game.getShortestPathDistance(pacManIndex, pillIndex, game.getPacmanLastMoveMade());
- closestPill.put(pillIndex, distance);
+ private Constants.MOVE getClosetsJunction(Game game, int pacManIndex) {
+
+ List closestIndex = new ArrayList<>();
+
+ for(Integer index : game.getJunctionIndices()) {
+ if(pacManIndex != index) {
+ double distance = game.getShortestPathDistance(pacManIndex, index, game.getPacmanLastMoveMade());
+ Constants.MOVE move = game.getNextMoveTowardsTarget(pacManIndex, index, Constants.DM.PATH);
+ int neighbourIndex = game.getNeighbour(pacManIndex, move);
+ closestIndex.add(new NextStep(index, move, neighbourIndex, distance + ghostScore(game, neighbourIndex)));
+ }
}
- Integer pillIndex = closestPill.entrySet().stream()
- .sorted(Map.Entry.comparingByValue())
- .map(integerIntegerEntry -> integerIntegerEntry.getKey())
- .findFirst().orElse(0);
+ return closestIndex.stream()
+ .sorted(Comparator.comparing(NextStep::getScore))
+ .map(NextStep::getFirstMove)
+ .findFirst().orElse(Constants.MOVE.NEUTRAL);
+
+ }
+
+ private Double ghostScore(Game game, int index) {
+ Set ghostScores = Arrays.stream(Constants.GHOST.values())
+ .filter(ghost -> !Optional.ofNullable(game.isGhostEdible(ghost)).orElse(false))
+ .map(ghost -> game.getGhostCurrentNodeIndex(ghost))
+ .filter(ghostIndex -> ghostIndex > 0)
+ .map(ghostIndex -> game.getDistance(index, ghostIndex, Constants.DM.MANHATTAN))
+ .collect(Collectors.toSet());
+
+ double score = 0;
+ for (double ghostScore: ghostScores) {
+ if(ghostScore < 30) {
+ score += 100;
+ }
+ score -= ghostScore;
+ }
- return game.getNextMoveTowardsTarget(pacManIndex, pillIndex, game.getPacmanLastMoveMade(), Constants.DM.PATH);
+ return score;
}
}
\ No newline at end of file
diff --git a/src/main/java/ReinaudLovesPacman/resource/NextStep.java b/src/main/java/ReinaudLovesPacman/resource/NextStep.java
new file mode 100644
index 0000000..d2d73cd
--- /dev/null
+++ b/src/main/java/ReinaudLovesPacman/resource/NextStep.java
@@ -0,0 +1,33 @@
+package ReinaudLovesPacman.resource;
+
+import pacman.game.Constants;
+
+public class NextStep {
+ Integer goalIndex;
+ Constants.MOVE firstMove;
+ Integer neighbourIndex;
+ Double score;
+
+ public NextStep(Integer goalIndex, Constants.MOVE firstMove, Integer neighbourIndex, Double score) {
+ this.goalIndex = goalIndex;
+ this.firstMove = firstMove;
+ this.neighbourIndex = neighbourIndex;
+ this.score = score;
+ }
+
+ public Integer getGoalIndex() {
+ return goalIndex;
+ }
+
+ public Constants.MOVE getFirstMove() {
+ return firstMove;
+ }
+
+ public Integer getNeighbourIndex() {
+ return neighbourIndex;
+ }
+
+ public Double getScore() {
+ return score;
+ }
+}
diff --git a/target/classes/Main.class b/target/classes/Main.class
index 5d8eb61..cb89cfb 100644
Binary files a/target/classes/Main.class and b/target/classes/Main.class differ
diff --git a/target/classes/ReinaudLovesPacman/MyPacMan.class b/target/classes/ReinaudLovesPacman/MyPacMan.class
index 5eb564d..8fc7510 100644
Binary files a/target/classes/ReinaudLovesPacman/MyPacMan.class and b/target/classes/ReinaudLovesPacman/MyPacMan.class differ
diff --git a/target/classes/ReinaudLovesPacman/resource/NextStep.class b/target/classes/ReinaudLovesPacman/resource/NextStep.class
new file mode 100644
index 0000000..94ae3a7
Binary files /dev/null and b/target/classes/ReinaudLovesPacman/resource/NextStep.class differ