diff --git a/core/src/main/java/com/buaisociety/pacman/Main.java b/core/src/main/java/com/buaisociety/pacman/Main.java index 29113e7..7d25997 100644 --- a/core/src/main/java/com/buaisociety/pacman/Main.java +++ b/core/src/main/java/com/buaisociety/pacman/Main.java @@ -103,9 +103,9 @@ public void create() { public @NotNull Neat createNeat() { // Change this to true/false as needed, if you want to load from file - if (false) { + if (true) { // TODO: Change this to the exact file you want to load - File exactFile = new File("saves" + File.separator + "oct26-4" + File.separator + "generation-51.json"); + File exactFile = new File("saves" + File.separator + "oct21-1" + File.separator + "generation-19.json"); // load exactFile contents to string String json; try { @@ -115,7 +115,7 @@ public void create() { } NeatImpl impl = NeatImpl.fromJson(json); // modify this as needed - //impl.updateNodeCounts(8, 4); // Add 4 new inputs + impl.updateNodeCounts(5, 4); // Add 4 new inputs //impl.updateClients(200); // have 200 pacman games at once return impl; } else { diff --git a/core/src/main/java/com/buaisociety/pacman/Tournament.java b/core/src/main/java/com/buaisociety/pacman/Tournament.java index 697fa74..60484c2 100644 --- a/core/src/main/java/com/buaisociety/pacman/Tournament.java +++ b/core/src/main/java/com/buaisociety/pacman/Tournament.java @@ -47,7 +47,7 @@ public class Tournament extends ApplicationAdapter { */ public Behavior setupBehavior() { // TODO: Choose your best client here - File file = new File("saves" + File.separator + "oct20-4" + File.separator + "best-calculator-127.json"); + File file = new File("saves" + File.separator + "oct21-3" + File.separator + "best-calculator-56.json"); if (!file.exists()) { System.err.println("Could not find the file: " + file.getAbsolutePath()); return null; diff --git a/core/src/main/java/com/buaisociety/pacman/entity/behavior/NeatPacmanBehavior.java b/core/src/main/java/com/buaisociety/pacman/entity/behavior/NeatPacmanBehavior.java index d3fd62f..1d541bf 100644 --- a/core/src/main/java/com/buaisociety/pacman/entity/behavior/NeatPacmanBehavior.java +++ b/core/src/main/java/com/buaisociety/pacman/entity/behavior/NeatPacmanBehavior.java @@ -11,6 +11,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.concurrent.ThreadLocalRandom; + public class NeatPacmanBehavior implements Behavior { private final @NotNull Client client; @@ -21,6 +23,9 @@ public class NeatPacmanBehavior implements Behavior { // specific pools of points instead of subtracting from all. private int scoreModifier = 0; + private int numberUpdatesSinceLastScore = 0; + private int lastScore = 0; + public NeatPacmanBehavior(@NotNull Client client) { this.client = client; } @@ -39,7 +44,18 @@ public Direction getDirection(@NotNull Entity entity) { } // SPECIAL TRAINING CONDITIONS - // TODO: Make changes here to help with your training... + + int newScore = pacman.getMaze().getLevelManager().getScore(); + if (newScore > lastScore) { + lastScore = newScore; + numberUpdatesSinceLastScore = 0; + } + + if (numberUpdatesSinceLastScore++ > 60 * 10) { + pacman.kill(); + return Direction.UP; + } + // END OF SPECIAL TRAINING CONDITIONS // We are going to use these directions a lot for different inputs. Get them all once for clarity and brevity @@ -54,11 +70,14 @@ public Direction getDirection(@NotNull Entity entity) { boolean canMoveRight = pacman.canMove(right); boolean canMoveBehind = pacman.canMove(behind); + float randomNumber = ThreadLocalRandom.current().nextFloat(); + float[] outputs = client.getCalculator().calculate(new float[]{ canMoveForward ? 1f : 0f, canMoveLeft ? 1f : 0f, canMoveRight ? 1f : 0f, canMoveBehind ? 1f : 0f, + randomNumber }).join(); int index = 0; diff --git a/core/src/main/java/com/buaisociety/pacman/entity/behavior/TournamentBehavior.java b/core/src/main/java/com/buaisociety/pacman/entity/behavior/TournamentBehavior.java index 22cab50..93d532f 100644 --- a/core/src/main/java/com/buaisociety/pacman/entity/behavior/TournamentBehavior.java +++ b/core/src/main/java/com/buaisociety/pacman/entity/behavior/TournamentBehavior.java @@ -7,6 +7,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.concurrent.ThreadLocalRandom; + public class TournamentBehavior implements Behavior { private final Calculator calculator; @@ -48,9 +50,27 @@ public Direction getDirection(@NotNull Entity entity) { // --- END OF DO NOT REMOVE --- // TODO: Put all your code for info into the neural network here + // We are going to use these directions a lot for different inputs. Get them all once for clarity and brevity + Direction forward = pacman.getDirection(); + Direction left = pacman.getDirection().left(); + Direction right = pacman.getDirection().right(); + Direction behind = pacman.getDirection().behind(); + + // Input nodes 1, 2, 3, and 4 show if the pacman can move in the forward, left, right, and behind directions + boolean canMoveForward = pacman.canMove(forward); + boolean canMoveLeft = pacman.canMove(left); + boolean canMoveRight = pacman.canMove(right); + boolean canMoveBehind = pacman.canMove(behind); + + float randomNumber = ThreadLocalRandom.current().nextFloat(); + float[] inputs = new float[] { - // TODO: Add your inputs here + canMoveForward ? 1f : 0f, + canMoveLeft ? 1f : 0f, + canMoveRight ? 1f : 0f, + canMoveBehind ? 1f : 0f, + randomNumber }; float[] outputs = calculator.calculate(inputs).join();