loadAgent
This commit is contained in:
parent
a3a36239ed
commit
7a3716e537
|
|
@ -36,5 +36,7 @@ public abstract class Agent {
|
||||||
// see step function in Simulator
|
// see step function in Simulator
|
||||||
public abstract boolean liveTurn(ArrayList<Agent> neighbors, Simulator world);
|
public abstract boolean liveTurn(ArrayList<Agent> neighbors, Simulator world);
|
||||||
|
|
||||||
|
public String save() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -354,14 +354,53 @@ public class Simulator extends Thread {
|
||||||
//DONE
|
//DONE
|
||||||
|
|
||||||
public ArrayList<String> getAgentsSave() {
|
public ArrayList<String> getAgentsSave() {
|
||||||
//TODO : Same idea as the other save method, but for agents
|
ArrayList<String> agentsSave = new ArrayList<>();
|
||||||
return null;
|
for (Agent agent : agents) {
|
||||||
|
agentsSave.add(agent.save());
|
||||||
|
}
|
||||||
|
return agentsSave;
|
||||||
}
|
}
|
||||||
|
//DONE
|
||||||
|
|
||||||
public void loadAgents(ArrayList<String> stringArray) {
|
public void loadAgents(ArrayList<String> agentData) {
|
||||||
//TODO : Same idea as other load methods, but for agent list
|
synchronized (agents) {
|
||||||
|
agents.clear();
|
||||||
|
for (String data : agentData) {
|
||||||
|
Agent agent = createAgent(data);
|
||||||
|
if (agent != null) {
|
||||||
|
agents.add(agent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Agent createAgent(String agentData) {
|
||||||
|
String[] parts = agentData.split(",");
|
||||||
|
if (parts.length < 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String agentType = parts[0];
|
||||||
|
switch (agentType) {
|
||||||
|
case "Sheep":
|
||||||
|
return createSheep(parts);
|
||||||
|
default:
|
||||||
|
System.out.println("Unknown agent type: " + agentType);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Sheep createSheep(String[] parts) {
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
int x = Integer.parseInt(parts[1]);
|
||||||
|
int y = Integer.parseInt(parts[2]);
|
||||||
|
return new Sheep(x, y);
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid Sheep data: " + String.join(",", parts));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//DONE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used by label in interface to show the active click action
|
* used by label in interface to show the active click action
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue