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

365 baseline evasion agents #369

Merged
merged 8 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 10 additions & 0 deletions src/main/java/app/controller/linAlg/Intersection.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ public static boolean hasIntersection(Vector p_1, Vector p_2, Vector p_3, Vector
return findIntersection(p_1, p_2, p_3, p_4) != null;
}

public static boolean hasIntersection(Line l1, Line l2)
{
return findIntersection(l1.a, l1.b, l2.a, l2.b) != null;
}

public static Vector findIntersection(Line l1, Line l2)
{
return findIntersection(l1.a, l1.b, l2.a, l2.b);
}

public static boolean hasIntersection(Vector a, Vector b, Ray r)
{
return findIntersection(a, b, r) != null;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/app/controller/linAlg/Line.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app.controller.linAlg;

import app.model.agents.Agent;
import lombok.AllArgsConstructor;
import lombok.ToString;

@AllArgsConstructor
@ToString
public class Line
{
private Vector a;
private Vector b;
public Vector a;
public Vector b;

public boolean liesOn(Vector v)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/app/model/agents/AgentImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import app.model.Move;
import app.model.Type;
import app.model.agents.Capture.CaptureAgent;
import app.model.agents.Evasion.EvasionAgent;
import app.model.agents.Evasion.*;
import app.view.agentView.AgentView;
import app.view.simulation.Info;
import javafx.scene.canvas.GraphicsContext;
Expand Down Expand Up @@ -282,7 +282,7 @@ public Agent nextState()
else if(this.type == Type.INTRUDER)
{
if(isTypeSeen(Type.GUARD))
return new EvasionAgent(this);
return new RunAwayAgent(this);

if(isTypeSeen(Type.TARGET))
return new TargetAgent(this);
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/app/model/agents/AgentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import app.controller.linAlg.Vector;
import app.model.Type;
import app.model.agents.ACO.*;
import app.model.agents.Evasion.EvasionAgent;
import app.model.agents.Evasion.EvasionStrategy;
import app.model.agents.Evasion.*;
import app.model.agents.WallFollow.WFMedDirHeuristic;
import app.model.agents.WallFollow.WFHighDirHeuristic;
import app.model.agents.WallFollow.WallFollowAgent;
Expand All @@ -20,7 +19,9 @@ public enum AgentType
WALL_FOLLOW,
EVASION_RANDOM,
EVASION_DIRECTED,
EVASION_RANDOMDIRECTED,
EVASION_DISTANCE_MAX,
EVASION_HIDEY,
EVASION_RUNAWAY,
WALL_FOLLOW_MED_DIR_HEURISTIC,
WALL_FOLLOW_HIGH_DIR_HEURISTIC,
RANDOM;
Expand Down Expand Up @@ -51,24 +52,27 @@ public static Agent agentOf(AgentType agentType, Vector position, Vector directi
return new WallFollowAgent(position, direction, radius, type, 20);
}
case EVASION_RANDOM -> {
return new EvasionAgent(position, direction, radius, type, EvasionStrategy.RANDOM);
return new EvasionRandom(position, direction, radius, type);
}
case EVASION_DIRECTED -> {
return new EvasionAgent(position, direction, radius, type, EvasionStrategy.DIRECTED);
return new EvasionDirected(position, direction, radius, type);
}
case EVASION_RANDOMDIRECTED -> {
return new EvasionAgent(position, direction, radius, type, EvasionStrategy.RANDOMDIRECTED);
case EVASION_DISTANCE_MAX -> {
return new EvasionDistanceMax(position, direction, radius, type);
}
case WALL_FOLLOW_MED_DIR_HEURISTIC ->
{
case EVASION_HIDEY -> {
return new HideyAgent(position, direction, radius, type);
}
case EVASION_RUNAWAY -> {
return new RunAwayAgent(position, direction, radius, type);
}
case WALL_FOLLOW_MED_DIR_HEURISTIC -> {
return new WFMedDirHeuristic(position, direction, radius, type, 20);
}
case WALL_FOLLOW_HIGH_DIR_HEURISTIC ->
{
case WALL_FOLLOW_HIGH_DIR_HEURISTIC -> {
return new WFHighDirHeuristic(position, direction, radius, type, 20);
}
case RANDOM ->
{
case RANDOM -> {
return new AgentImp(position, direction, radius, type);
}
default -> throw new RuntimeException("Agent type not recognized");
Expand Down
157 changes: 0 additions & 157 deletions src/main/java/app/model/agents/Evasion/EvasionAgent.java

This file was deleted.

66 changes: 66 additions & 0 deletions src/main/java/app/model/agents/Evasion/EvasionDirected.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package app.model.agents.Evasion;

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

public class EvasionDirected extends EvasionRandom
{
protected Vector intelligentDirection;
protected boolean intelligenceFlag = false;

public EvasionDirected(Vector position, Vector direction, double radius, Type type)
{
super(position, direction, radius, type);
}

public EvasionDirected(Agent other)
{
super(other);
}

@Override
public Move move()
{
if(moveFailed)
{
direction = direction.rotate(90);
return super.nextMove();
}
else
{
updateKnowledge();
return nextMove();
}
}

@Override
protected Move nextMove()
{
if(intelligenceFlag)
{
return new Move(intelligentDirection.normalise(), intelligentDirection);
}
return super.nextMove();
}

@Override
protected void updateKnowledge()
{
Vector closestGuardSeen = closestTypePos(Type.GUARD);

if(closestGuardSeen != null)
{
counter = 0;
Vector safeDirection = position.sub(closestGuardSeen);
intelligentDirection = safeDirection.normalise().scale(moveLength);
intelligenceFlag = true;
}
else
{
counter ++;
intelligenceFlag = false;
}
}
}
Loading