Skip to content

Commit

Permalink
memory keys public
Browse files Browse the repository at this point in the history
  • Loading branch information
wouter.lenaerts committed Mar 27, 2021
1 parent 47f643b commit 3e4bc04
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main/java/agent/behaviour/dropPacket/DropPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class DropPacket extends LTDBehaviour {

private final static Logger LOGGER = Logger.getLogger(DropPacket.class.getName());
// private Coordinate destination;
private final static String destinationKey = "destination";
private final static String searchAllKey = "searchAll";
public final static String DESTINATION_KEY = "destination";
public final static String SEARCH_ALL_KEY = "searchAll";

// private boolean doSearchAll = true; // true because first time no previous

@Override
public void act(AgentImp agent) {
Coordinate destination = Coordinate.fromString(agent.getMemoryFragment(destinationKey));
Coordinate destination = Coordinate.fromString(agent.getMemoryFragment(DESTINATION_KEY));
Coordinate currentCoord = new Coordinate(agent.getX(), agent.getY());
// packet kunt opnemen of afzetten
// geen packet en packet opnemen?
Expand All @@ -42,22 +42,22 @@ public void act(AgentImp agent) {
}
} catch (Exception e) {
System.out.println(e.getMessage());
agent.removeMemoryFragment(destinationKey);
agent.addMemoryFragment(searchAllKey, "true");
agent.removeMemoryFragment(DESTINATION_KEY);
agent.addMemoryFragment(SEARCH_ALL_KEY, "true");
agent.skip();
}
}

private void pickOrPutPacket(AgentImp agent){

Coordinate destination = Coordinate.fromString(agent.getMemoryFragment(destinationKey));
Coordinate destination = Coordinate.fromString(agent.getMemoryFragment(DESTINATION_KEY));
if (agent.hasCarry()){
agent.putPacket(destination.getX(), destination.getY());
}else {
agent.pickPacket(destination.getX(), destination.getY());
}
agent.removeMemoryFragment(destinationKey);
agent.addMemoryFragment(searchAllKey, "true");
agent.removeMemoryFragment(DESTINATION_KEY);
agent.addMemoryFragment(SEARCH_ALL_KEY, "true");
}

private boolean isNeighbour(AgentImp agent, Coordinate c){
Expand All @@ -78,19 +78,19 @@ private void setStep(AgentImp agent) {
List<CellPerception> toSearch;
if (searchAll(agent)){
toSearch = searchAll(perception, perception.getWidth(), perception.getHeight());
agent.addMemoryFragment(searchAllKey, "false");
agent.addMemoryFragment(SEARCH_ALL_KEY, "false");

}
else
toSearch = searchRange(agent, perception.getCellPerceptionOnAbsPos(agent.getX(), agent.getY()), perception.getWidth(), perception.getHeight());
Coordinate destination = findDestination(agent, toSearch);
if (destination != null) {
agent.addMemoryFragment(destinationKey, destination.toString());
agent.addMemoryFragment(DESTINATION_KEY, destination.toString());
System.out.println(agent.getName()+": " + destination);
setStep(agent, destination);
}
else {
agent.removeMemoryFragment(destinationKey);
agent.removeMemoryFragment(DESTINATION_KEY);
moveRandomly(agent);
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ public void communicate(AgentImp agent) {
}

private Boolean searchAll(AgentImp agent) {
String searchAll = agent.getMemoryFragment(searchAllKey);
String searchAll = agent.getMemoryFragment(SEARCH_ALL_KEY);
if (searchAll == null) return true;
return Boolean.parseBoolean(searchAll);
}
Expand Down

0 comments on commit 3e4bc04

Please sign in to comment.