From 5510f132b752bd7f31ac0c9a7338a13cc4f99d1d Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sat, 26 Oct 2019 19:14:08 -0300 Subject: [PATCH] If the player location is not known yet during sort, find it. This only happens when the loop has not been run yet. Signed-off-by: Chris Cromer --- src/main/java/cl/cromer/azaraka/Constants.java | 2 +- src/main/java/cl/cromer/azaraka/ai/PlayerAI.java | 3 +++ src/main/java/cl/cromer/azaraka/ai/PlayerAStarAI.java | 3 +++ src/main/java/cl/cromer/azaraka/ai/PlayerBreadthFirstAI.java | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/cl/cromer/azaraka/Constants.java b/src/main/java/cl/cromer/azaraka/Constants.java index bdeba51..7ad53f6 100644 --- a/src/main/java/cl/cromer/azaraka/Constants.java +++ b/src/main/java/cl/cromer/azaraka/Constants.java @@ -69,7 +69,7 @@ public interface Constants { /** * The amount of chests to draw, if less then 2 the game cannot be won */ - int CHESTS = 2; + int CHESTS = 3; /** * The amount of enemies to draw */ diff --git a/src/main/java/cl/cromer/azaraka/ai/PlayerAI.java b/src/main/java/cl/cromer/azaraka/ai/PlayerAI.java index 397433c..12b2081 100644 --- a/src/main/java/cl/cromer/azaraka/ai/PlayerAI.java +++ b/src/main/java/cl/cromer/azaraka/ai/PlayerAI.java @@ -107,8 +107,11 @@ public interface PlayerAI extends Runnable, Constants { return Double.compare(state1Distance, state2Distance); } else { + // We don't know where the player is, so equal importance return 0; } + + //scene.getCanvas().getEnemies(); } }); return destinations; diff --git a/src/main/java/cl/cromer/azaraka/ai/PlayerAStarAI.java b/src/main/java/cl/cromer/azaraka/ai/PlayerAStarAI.java index caed964..a0b39b3 100644 --- a/src/main/java/cl/cromer/azaraka/ai/PlayerAStarAI.java +++ b/src/main/java/cl/cromer/azaraka/ai/PlayerAStarAI.java @@ -447,6 +447,9 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants { */ @Override public void sortDestinations() { + if (initial == null) { + initial = new State(player.getCell().getX(), player.getCell().getY(), State.Type.PLAYER, null, 0); + } destinations = sortDestinations(destinations, initial); } diff --git a/src/main/java/cl/cromer/azaraka/ai/PlayerBreadthFirstAI.java b/src/main/java/cl/cromer/azaraka/ai/PlayerBreadthFirstAI.java index 458bb82..0e6f421 100644 --- a/src/main/java/cl/cromer/azaraka/ai/PlayerBreadthFirstAI.java +++ b/src/main/java/cl/cromer/azaraka/ai/PlayerBreadthFirstAI.java @@ -242,6 +242,9 @@ public class PlayerBreadthFirstAI extends AI implements PlayerAI, Constants { * Sort the destinations by importance, if the importance is the same then sort them by distance */ public void sortDestinations() { + if (initial == null) { + initial = new State(player.getCell().getX(), player.getCell().getY(), State.Type.PLAYER, null, 0); + } destinations = sortDestinations(destinations, initial); }