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

goal-direction #256

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion src/main/java/app/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Map(Settings settings)
if (srt != null)
{
Vector dir = randDirection();
AcoAgentLimitedVision guard = new AcoAgentLimitedVision(srt, dir, 10, Team.GUARD);
Agent guard = new AcoAgentLimitedVision(srt, dir, 10, Team.GUARD);
guard.setMaxWalk(settings.getWalkSpeedGuard());
guard.setMaxSprint(settings.getSprintSpeedGuard());
agents.add(guard);
Expand All @@ -91,6 +91,7 @@ public Map(Settings settings)
{
Vector dir = randDirection();
Agent intruder = new WallFollowAgent(srt, dir, 10, Team.INTRUDER);
intruder.setTgtDirection(targetDirection(srt));
intruder.setMaxWalk(settings.getWalkSpeedIntruder());
intruder.setMaxSprint(settings.getSprintSpeedIntruder());
agents.add(intruder);
Expand Down Expand Up @@ -257,4 +258,14 @@ private boolean clearSpot(Vector v)
}
return true;
}

private Vector targetDirection(Vector vector)
{
Vector targetCentre = new Vector(target.getMinX() + (target.getWidth()/2),
target.getMinY() + (target.getHeight()/2));
double dX = targetCentre.getX() - vector.getX();
double dY = targetCentre.getY() - vector.getY();
Vector direction = new Vector(dX, dY);
return direction.normalise();
}
}
2 changes: 2 additions & 0 deletions src/main/java/app/model/agents/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public interface Agent extends Boundary
void addViewWindow(AgentView agentView);

Team getTeam();

void setTgtDirection(Vector tgtDirection);
}
13 changes: 13 additions & 0 deletions src/main/java/app/model/agents/AgentImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class AgentImp implements Agent
@Getter @Setter protected double maxSprint = 10;
@Getter @Setter protected Vector direction;
@Getter @Setter protected boolean moveFailed;
@Setter protected Vector tgtDirection;
@Getter protected Team team;
@Getter protected Vector position;
@Getter protected double radius;
Expand All @@ -33,6 +34,18 @@ public AgentImp(Vector position, Vector direction, double radius, Team team)
this.position = position;
this.radius = radius;
this.team = team;
this.tgtDirection = null;
view = new ArrayList<>();
seen = new VectorSet();
}

public AgentImp(Vector position, Vector direction, double radius, Team team, Vector tgtDirection)
{
this.direction = direction;
this.position = position;
this.radius = radius;
this.team = team;
this.tgtDirection = tgtDirection;
view = new ArrayList<>();
seen = new VectorSet();
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/app/model/agents/WallFollow/WallFollowAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ public enum TurnType
RIGHT,
NO_TURN,
}
@Setter private boolean DEBUG = false;
@Getter @Setter private boolean movedForwardLast = false;
@Getter @Setter private TurnType lastTurn = TurnType.NO_TURN;
@Getter @Setter private double moveLength = 20;
private int maxViewingDistance = 10;
@Setter private boolean DEBUG = false;
@Getter @Setter private boolean wallEncountered = false;
private int maxViewingDistance = 10;
public static Map map;
private final app.model.agents.WallFollow.BooleanCellGraph<BooleanCell, DefaultEdge> cellGraph;
private boolean initialVertexFound = false;
private BooleanCell tempAgentCell;
private boolean noMovesDone = true;
private final List<Vector> directions = Arrays.asList(new Vector(0,1),
new Vector(1,0),
new Vector(0,-1),
new Vector(-1,0));
private List<BooleanCell> currentPathToNextVertex = null;
private boolean explorationDone = false;
private BooleanCell tempAgentCell;
private BooleanCell currentTargetVertex = null;
private List<BooleanCell> currentPathToNextVertex = null;
private ArrayList<BooleanCell> inaccessibleCells = new ArrayList<>();
private boolean explorationDone = false;
private final List<Vector> directions = Arrays.asList(new Vector(0,1),
new Vector(1,0),
new Vector(0,-1),
new Vector(-1,0));

public WallFollowAgent(Vector position, Vector direction, double radius, Team team)
{
Expand Down