Improve the AI some more

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-26 18:49:28 -03:00
parent 4067055af4
commit cb7fe3767d
6 changed files with 59 additions and 285 deletions

View File

@ -40,11 +40,9 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;
/**
@ -309,10 +307,10 @@ public class Canvas extends java.awt.Canvas implements Constants {
*/
private void setupPlayerAI() {
try {
player.getAi().addDestination(new State(2, 0, State.Type.EXIT, null, 3));
player.getAi().addDestination(new State(2, 0, State.Type.EXIT, null, 4));
// Shuffle the chests so that the AI doesn't open the correct chests on the first go
Collections.shuffle(chests, new Random(23));
//Collections.shuffle(chests, new Random(23));
for (Chest chest : chests) {
player.getAi().addDestination(new State(chest.getCell().getX(), chest.getCell().getY() + 1, State.Type.CHEST, null, 2));
}
@ -320,8 +318,6 @@ public class Canvas extends java.awt.Canvas implements Constants {
for (Key key : keys) {
player.getAi().addDestination(new State(key.getCell().getX(), key.getCell().getY(), State.Type.KEY, null, 1));
}
player.getAi().sortDestinations();
}
catch (AIException e) {
logger.warning(e.getMessage());

View File

@ -85,7 +85,7 @@ public interface Constants {
/**
* Generates the scene manually instead of from the JSON file if true
*/
boolean GENERATE_SCENE = true;
boolean GENERATE_SCENE = false;
/**
* Exports the scene to a JSON file if true
*/

View File

@ -136,7 +136,7 @@ public interface PlayerAI extends Runnable, Constants {
}
player.interact();
if (!portalWasActive) {
addDestination(new State(portal.getCell().getX(), portal.getCell().getY(), State.Type.PORTAL, null, 1));
addDestination(new State(portal.getCell().getX(), portal.getCell().getY(), State.Type.PORTAL, null, 3));
}
sortDestinations();
return true;

View File

@ -208,7 +208,7 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants {
22222
*/
EnemyCost enemyCost = EnemyCost.DIRECT_CORNERS;
EnemyCost enemyCost = EnemyCost.FAR_CORNERS;
if (enemyCost.getLevel() == EnemyCost.NONE.getLevel()) {
return EnemyCost.NONE.getCost();
@ -359,6 +359,7 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants {
*/
public void addDestination(State destination) {
destinations.add(destination);
sortDestinations();
}
/**
@ -385,7 +386,6 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants {
if (checkCondition(scene, destination)) {
getLogger().info("Check A* Search goal!");
found = search(initial, destination);
}
if (initial.equals(destination)) {
if (destinationArrived(scene, destination)) {
@ -400,11 +400,17 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants {
//destinationArrived(objective);
}
}
}
else {
clearStates();
}
if (destinations.isEmpty()) {
getLogger().info("No more destinations for A* Search!");
setActive(false);
return;
}
if (!found) {
destinationIndex++;
if (destinationIndex >= destinations.size()) {
getLogger().info("None of the destinations are reachable for A* Search!");
@ -413,15 +419,13 @@ public class PlayerAStarAI extends AI implements PlayerAI, Constants {
steps.add(0, State.Type.PLAYER);
}
steps.add(1, getOpenSpaceAroundPlayer(scene));
found = true;
break;
}
}
while (!found && !destinations.isEmpty());
if (found) {
doAction(scene, steps);
}
while (!found);
doAction(scene, steps);
}
}

View File

@ -219,6 +219,7 @@ public class PlayerBreadthFirstAI extends AI implements PlayerAI, Constants {
*/
public void addDestination(State destination) {
destinations.add(destination);
sortDestinations();
}
/**
@ -279,7 +280,6 @@ public class PlayerBreadthFirstAI extends AI implements PlayerAI, Constants {
if (checkCondition(scene, destination)) {
getLogger().info("Check Breadth-First Search goal!");
found = search(initial, destination);
}
if (initial.equals(destination)) {
if (destinationArrived(scene, destination)) {
@ -294,11 +294,17 @@ public class PlayerBreadthFirstAI extends AI implements PlayerAI, Constants {
//destinationArrived(objective);
}
}
}
else {
clearStates();
}
if (destinations.isEmpty()) {
getLogger().info("No more destinations for Breadth-First Search!");
setActive(false);
return;
}
if (!found) {
destinationIndex++;
if (destinationIndex >= destinations.size()) {
getLogger().info("None of the destinations are reachable for Breadth-First Search!");
@ -307,16 +313,14 @@ public class PlayerBreadthFirstAI extends AI implements PlayerAI, Constants {
steps.add(0, State.Type.PLAYER);
}
steps.add(1, getOpenSpaceAroundPlayer(scene));
found = true;
break;
}
}
while (!found && !destinations.isEmpty());
}
while (!found);
if (found) {
doAction(scene, steps);
}
}
}
}
}

View File

@ -59,14 +59,6 @@
65
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
0,
49,
255
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -126,12 +118,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -190,12 +176,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -256,12 +236,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -321,12 +295,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -386,12 +354,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -451,12 +413,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -516,12 +472,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -580,12 +530,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -645,12 +589,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -710,12 +648,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -775,12 +707,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -840,12 +766,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -905,12 +825,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -970,142 +884,6 @@
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
0,
98,
207
]
}
],
[
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
0,
35
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
0,
99
]
}
],
[
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
0,
34,
222
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "null",
"textures": [
0
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
@ -1175,14 +953,6 @@
69
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [
0,
53,
238
]
},
{
"type": "cl.cromer.azaraka.object.Obstacle",
"textures": [