Remove sort destinations from AI class

Change enemy to 600ms sleep
Change chest number back to 2
Turn lock back on for enemies

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-26 20:23:31 -03:00
parent 5510f132b7
commit 38bf713562
6 changed files with 5 additions and 14 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 = 3; int CHESTS = 2;
/** /**
* The amount of enemies to draw * The amount of enemies to draw
*/ */

View File

@ -195,7 +195,7 @@ public class Scene extends JComponent implements Constants {
} }
} }
final Lock lock = new ReentrantLock(false); final Lock lock = new ReentrantLock(true);
for (int i = 0; i < ENEMIES; i++) { for (int i = 0; i < ENEMIES; i++) {
random = randomCoordinates(); random = randomCoordinates();
cells.get(random[0]).get(random[1]).setObject(new Enemy(this, cells.get(random[0]).get(random[1]), lock)); cells.get(random[0]).get(random[1]).setObject(new Enemy(this, cells.get(random[0]).get(random[1]), lock));

View File

@ -87,15 +87,6 @@ public class AI implements Runnable {
throw new AIException("The addDestination method should be run by the child only!"); throw new AIException("The addDestination method should be run by the child only!");
} }
/**
* Sort the destinations
*
* @throws AIException Thrown when the parent method is called directly
*/
public void sortDestinations() throws AIException {
throw new AIException("The addDestination method should be run by the child only!");
}
/** /**
* The AI should run in a loop * The AI should run in a loop
*/ */

View File

@ -215,7 +215,7 @@ public class EnemyAI extends AI implements Runnable, Constants {
public void run() { public void run() {
while (getActive()) { while (getActive()) {
try { try {
Thread.sleep(700); Thread.sleep(600);
} }
catch (InterruptedException e) { catch (InterruptedException e) {
logger.info(e.getMessage()); logger.info(e.getMessage());

View File

@ -89,7 +89,6 @@ public interface PlayerAI extends Runnable, Constants {
* @return Returns the new sorted destinations * @return Returns the new sorted destinations
*/ */
default List<State> sortDestinations(List<State> destinations, State initial) { default List<State> sortDestinations(List<State> destinations, State initial) {
// TODO: make the AI look for the goal farthest from the enemy
destinations.sort((state1, state2) -> { destinations.sort((state1, state2) -> {
if (state1.getImportance() > state2.getImportance()) { if (state1.getImportance() > state2.getImportance()) {
// The first state is more important // The first state is more important
@ -103,7 +102,9 @@ public interface PlayerAI extends Runnable, Constants {
// The states have equal importance, so let's compare distances between them // The states have equal importance, so let's compare distances between them
if (initial != null) { if (initial != null) {
double state1Distance = heuristic(initial, state1); double state1Distance = heuristic(initial, state1);
// TODO: Find closest enemy to state 1, if player distance is closer than enemy, go for it
double state2Distance = heuristic(initial, state2); double state2Distance = heuristic(initial, state2);
// TODO: Find closest enemy to state 2, if player distance is closer than enemy, go for it
return Double.compare(state1Distance, state2Distance); return Double.compare(state1Distance, state2Distance);
} }
else { else {

View File

@ -445,7 +445,6 @@ public class PlayerAStarAI 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
*/ */
@Override
public void sortDestinations() { public void sortDestinations() {
if (initial == null) { if (initial == null) {
initial = new State(player.getCell().getX(), player.getCell().getY(), State.Type.PLAYER, null, 0); initial = new State(player.getCell().getX(), player.getCell().getY(), State.Type.PLAYER, null, 0);