Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture evade experiments trial 2 #363

Merged
merged 14 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/app/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void checkForCapture(Agent currentAgent)
if(otherAgent.getType() != currentAgent.getType())
{
double dist = currentAgent.getPosition().dist(otherAgent.getPosition());
if(dist <= (currentAgent.getRadius() + otherAgent.getRadius() + 3))
if(dist <= (currentAgent.getRadius() + otherAgent.getRadius() + 7))
{
deleteAgent(otherAgent);
}
Expand Down Expand Up @@ -239,6 +239,22 @@ public boolean goalReached()
return false;
}

/**
* Method determines if there is an intruder within a Guard's visual field.
* @return True if an intruder is within a Guard's visual field. Else False.
*/
public boolean intruderVisual()
{
for(Agent a: agents)
{
if(a.getType() == Type.GUARD && a.isTypeSeen(Type.INTRUDER))
{
return true;
}
}
return false;
}


public int agentsRemaining(Type type)
{
Expand Down
22 changes: 1 addition & 21 deletions src/main/java/app/model/agents/AgentImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,26 +270,6 @@ public boolean noWallDetected(Vector vector, double moveLength)
@Override
public Agent nextState()
{
// State GUARD
if(this.type == Type.GUARD)
{
if(isTypeSeen(Type.INTRUDER))
return new CaptureAgent(this);

}

// State INTRUDER
else if(this.type == Type.INTRUDER)
{
if(isTypeSeen(Type.GUARD))
return new EvasionAgent(this);

if(isTypeSeen(Type.TARGET))
return new TargetAgent(this);

return this;
}

return this;
return StateTable.lookupState(this);
}
}
5 changes: 5 additions & 0 deletions src/main/java/app/model/agents/AgentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import app.controller.linAlg.Vector;
import app.model.Type;
import app.model.agents.ACO.*;
import app.model.agents.Capture.CaptureAgent;
import app.model.agents.Evasion.EvasionAgent;
import app.model.agents.Evasion.EvasionStrategy;
import app.model.agents.WallFollow.WFMedDirHeuristic;
Expand All @@ -21,6 +22,7 @@ public enum AgentType
EVASION_RANDOM,
EVASION_DIRECTED,
EVASION_RANDOMDIRECTED,
CAPTURE,
WALL_FOLLOW_MED_DIR_HEURISTIC,
WALL_FOLLOW_HIGH_DIR_HEURISTIC,
RANDOM;
Expand Down Expand Up @@ -59,6 +61,9 @@ public static Agent agentOf(AgentType agentType, Vector position, Vector directi
case EVASION_RANDOMDIRECTED -> {
return new EvasionAgent(position, direction, radius, type, EvasionStrategy.RANDOMDIRECTED);
}
case CAPTURE -> {
return new CaptureAgent(position, direction, radius, type);
}
case WALL_FOLLOW_MED_DIR_HEURISTIC ->
{
return new WFMedDirHeuristic(position, direction, radius, type, 20);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/app/model/agents/Capture/CaptureAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import app.model.agents.ACO.AcoAgent;
import app.model.agents.Agent;
import app.model.agents.AgentImp;
import app.model.agents.AgentType;
import app.model.agents.StateTable;
import app.model.agents.WallFollow.WallFollowAgent;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -224,7 +226,7 @@ public Vector checkMomentum(ArrayList<Vector> intruderHistory)
public Agent nextState()
{
if(maxTicsReached())
return new AcoAgent(this);
return StateTable.acoTableSearch(this);

return this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/app/model/agents/Evasion/EvasionAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import app.model.Type;
import app.model.agents.Agent;
import app.model.agents.AgentImp;
import app.model.agents.StateTable;
import app.model.agents.WallFollow.WallFollowAgent;

public class EvasionAgent extends AgentImp
Expand Down Expand Up @@ -150,7 +151,7 @@ private boolean maxTicsReached()
@Override public Agent nextState()
{
if(maxTicsReached())
return new WallFollowAgent(this);
return StateTable.wfTableSearch(this);

return this;
}
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/app/model/agents/StateTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package app.model.agents;

import app.model.Type;
import app.model.agents.ACO.*;
import app.model.agents.Capture.CaptureAgent;
import app.model.agents.Evasion.EvasionAgent;
import app.model.agents.WallFollow.WFHighDirHeuristic;
import app.model.agents.WallFollow.WFMedDirHeuristic;
import app.model.agents.WallFollow.WallFollowAgent;
import lombok.Getter;
import lombok.Setter;

public class StateTable
{
@Setter private static AgentType defaultCaptureAgent = AgentType.CAPTURE;
@Setter private static AgentType defaultEvasionAgent = AgentType.EVASION_DIRECTED;
@Getter private static AgentType defaultAcoAgent = AgentType.ACO_MOMENTUM;
@Getter private static AgentType defaultWFAgent = AgentType.WALL_FOLLOW_MED_DIR_HEURISTIC;

/**
* Encodes state changes for all types of agents, returning either the current class
* or creates a new class of the required type for the desired next state
* @param currentState The current agent state
* @return The next state of the agent
*/
public static Agent lookupState(Agent currentState)
{
//State GUARD
if(currentState.getType() == Type.GUARD)
{
if(currentState.isTypeSeen(Type.INTRUDER))
return captureTableSearch(currentState);
}

//State INTRUDER
else if(currentState.getType() == Type.INTRUDER)
{
if(currentState.isTypeSeen(Type.GUARD))
return evasionTableSearch(currentState);

if(currentState.isTypeSeen(Type.TARGET))
return new TargetAgent(currentState);

return currentState;
}
return currentState;
}

public static Agent captureTableSearch(Agent currentState)
{
switch(defaultCaptureAgent)
{
case CAPTURE -> {return new CaptureAgent(currentState);}
default -> throw new RuntimeException("Capture agent not specified");
}
}

public static Agent evasionTableSearch(Agent currentState)
{
//TODO Modify table when Evasion Agents are separated.
switch(defaultEvasionAgent)
{
case EVASION_RANDOM -> {return new EvasionAgent(currentState);}
case EVASION_DIRECTED -> {return new EvasionAgent(currentState);}
case EVASION_RANDOMDIRECTED -> {return new EvasionAgent(currentState);}
default -> throw new RuntimeException("Evasion agent not specified");
}
}

public static Agent acoTableSearch(Agent currentState)
{
switch(defaultAcoAgent)
{
case ACO -> {return new AcoAgent(currentState);}
case ACO_COLONY -> {return new AcoColony(currentState);}
case ACO_MOMENTUM -> {return new AcoMomentum(currentState);}
case ACO_MIDI -> {return new AcoMid(currentState);}
case ACO_RANKING -> {return new AcoRanking(currentState);}
case ACO_MOMENTUM_SPIRAL_AVOIDANCE -> {return new AcoMomentumSpiralAvoidance(currentState);}
default -> throw new RuntimeException("ACO agent not specified");
}
}

public static Agent wfTableSearch(Agent currentState)
{
switch(defaultWFAgent)
{
case WALL_FOLLOW -> {return new WallFollowAgent(currentState);}
case WALL_FOLLOW_HIGH_DIR_HEURISTIC -> {return new WFHighDirHeuristic(currentState);}
case WALL_FOLLOW_MED_DIR_HEURISTIC -> {return new WFMedDirHeuristic(currentState);}
default -> throw new RuntimeException("WF agent not specified");
}
}

public static String getDefaultCaptureAgent()
{
return defaultCaptureAgent.name() + " ";
}

public static String getDefaultEvasionAgent()
{
return defaultEvasionAgent.name();
}
}
4 changes: 2 additions & 2 deletions src/main/java/app/model/agents/TargetAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ private boolean updateTargetRay()
public Agent nextState()
{
if(isTypeSeen(Type.GUARD))
return new EvasionAgent(this);
return StateTable.evasionTableSearch(this);
if(targetLost || moveFailed)
return new WallFollowAgent(this);
return StateTable.wfTableSearch(this);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import app.controller.linAlg.Vector;
import app.model.Type;
import app.model.agents.Agent;

public class WFHighDirHeuristic extends WallFollowAgent
{
Expand All @@ -11,4 +12,10 @@ public WFHighDirHeuristic(Vector position, Vector direction, double radius, Type
super(position, direction, radius, type, moveLen);
directionHeuristicWeight = 4;
}

public WFHighDirHeuristic(Agent other)
{
super(other);
directionHeuristicWeight = 4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import app.controller.linAlg.Vector;
import app.model.Type;
import app.model.agents.Agent;

public class WFMedDirHeuristic extends WallFollowAgent
{
Expand All @@ -12,4 +13,9 @@ public WFMedDirHeuristic(Vector position, Vector direction, double radius, Type
directionHeuristicWeight = 2;
}

public WFMedDirHeuristic(Agent other)
{
super(other);
directionHeuristicWeight = 2;
}
}
77 changes: 75 additions & 2 deletions src/test/java/experiments/Experiments.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package experiments;

import app.controller.io.FileManager;
import app.controller.settings.RandomSettingsGenerator;
import app.controller.settings.Settings;
import app.model.Map;
import app.model.agents.AgentType;
import app.model.agents.StateTable;
import jogging.Logger;

import java.util.Arrays;
Expand All @@ -17,7 +19,7 @@ public class Experiments
*/
public static void main(String[] args)
{
runInfiltration("experiment_map_1");
runEvasion();
}

private static void runCoverage(String map_name)
Expand Down Expand Up @@ -63,9 +65,10 @@ private static void runCoverage(String map_name)
}
}

@Deprecated
private static void runCapture(String map_name)
{
final int iterations = 10;
final int iterations = 100;
final int[] no_of_guards = {1, 2, 3, 4 ,5, 6};

System.out.println("Loading map: " + map_name);
Expand Down Expand Up @@ -93,6 +96,66 @@ private static void runCapture(String map_name)
}
}

/**
* Experiment provides a 1 vs 1 | Capture vs Evasion situation within the thunder-dome.
* Specify the default Capture and Evasion agents within the method to alter the pairings.
* Experiment output is the number of ticks until the Evasion agent is captured
*/
private static void runCapture()
{
StateTable.setDefaultCaptureAgent(AgentType.CAPTURE);
StateTable.setDefaultEvasionAgent(AgentType.EVASION_RANDOM);

final String testName = "Capture_Experiment_" +
StateTable.getDefaultCaptureAgent() + "_" +
StateTable.getDefaultEvasionAgent();
final int iterations = 100;

Logger logger = new Logger(testName);
logger.setOutputCsv();

for(int i = 0; i < iterations; i++)
{
String test_heading = "Iteration: " + i + "/" + iterations + " ";

Map map = generateRandomMap();

TestingEngine gameEngine = new TestingEngine(map, test_heading);
int data = (int) gameEngine.runCaptureTest();
logger.log(test_heading + ", " + data);
}
}

/**
* Experiment provides a 1 vs 1 | Capture vs Evasion situation within the thunder-dome.
* Specify the default Capture and Evasion agents within the method to alter the pairings.
* Experiment output is the number of ticks until the Capture agent has lost visual sighting of the Evading agent.
*/
public static void runEvasion()
{
StateTable.setDefaultCaptureAgent(AgentType.CAPTURE);
StateTable.setDefaultEvasionAgent(AgentType.EVASION_DIRECTED);

final String testName = "Evasion_Experiment_" +
StateTable.getDefaultCaptureAgent() + "_" +
StateTable.getDefaultEvasionAgent();
final int iterations = 10;

Logger logger = new Logger(testName);
logger.setOutputCsv();

for(int i =0; i < iterations; i++)
{
String test_heading = "Iteration: " + i + "/" + iterations + " ";

Map map = generateRandomMap();

TestingEngine gameEngine = new TestingEngine(map, test_heading);
int data = (int) gameEngine.runEvasionTest();
logger.log(test_heading + "," + data);
}
}

private static void runInfiltration(String map_name)
{
final int iterations = 10;
Expand Down Expand Up @@ -122,4 +185,14 @@ private static void runInfiltration(String map_name)
}
}
}

private static Map generateRandomMap()
{
Settings settings = RandomSettingsGenerator.generateRandomSettings();
settings.setNoOfGuards(1);
settings.setNoOfIntruders(1);

Map map = new Map(settings);
return map;
}
}
Loading