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 <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-26 19:14:08 -03:00
parent cb7fe3767d
commit 5510f132b7
4 changed files with 10 additions and 1 deletions

View File

@ -69,7 +69,7 @@ public interface Constants {
/** /**
* The amount of chests to draw, if less then 2 the game cannot be won * 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 * The amount of enemies to draw
*/ */

View File

@ -107,8 +107,11 @@ public interface PlayerAI extends Runnable, Constants {
return Double.compare(state1Distance, state2Distance); return Double.compare(state1Distance, state2Distance);
} }
else { else {
// We don't know where the player is, so equal importance
return 0; return 0;
} }
//scene.getCanvas().getEnemies();
} }
}); });
return destinations; return destinations;

View File

@ -447,6 +447,9 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants {
*/ */
@Override @Override
public void sortDestinations() { public void sortDestinations() {
if (initial == null) {
initial = new State(player.getCell().getX(), player.getCell().getY(), State.Type.PLAYER, null, 0);
}
destinations = sortDestinations(destinations, initial); destinations = sortDestinations(destinations, initial);
} }

View File

@ -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 * Sort the destinations by importance, if the importance is the same then sort them by distance
*/ */
public void sortDestinations() { public void sortDestinations() {
if (initial == null) {
initial = new State(player.getCell().getX(), player.getCell().getY(), State.Type.PLAYER, null, 0);
}
destinations = sortDestinations(destinations, initial); destinations = sortDestinations(destinations, initial);
} }