📄 agent.java
字号:
package graph;
import org.jgraph.graph.DefaultGraphCell;
import gui.GUIEventManager;
import java.util.LinkedList;
import java.io.Serializable;
public abstract class Agent implements Serializable
{
public Agent(DefaultGraphCell origin, ResourceQuery searchFor)
{
this.age = 0;
this.origin = origin;
this.searchFor = searchFor;
this.previousNode = origin;
this.progress = 0;
this.status = EXPLORING;
}
public static String getAction()
{
return "Search for resource";
}
public static void startAction(DefaultGraphCell tempCell)
{
GUIEventManager.getReference().eventSearchForResource(tempCell);
}
public abstract void run(DefaultGraphCell currentGraphCell);
public LinkedList getNextNodes(DefaultGraphCell currentGraphCell)
{
if (status == EXPLORING)
{
return GraphEventManager.getReference().getConnectedNodes(currentGraphCell);
}
else
{
return null;
}
}
public DefaultGraphCell getRandomGraphCellFromExcept(DefaultGraphCell currentGraphCell, DefaultGraphCell exceptNode)
{
int aantal = GraphEventManager.getReference().getConnectedNodes(currentGraphCell).size();
DefaultGraphCell choice = null;
if (aantal == 0)
{
return null;
}
else if (aantal == 1 && exceptNode != null)
{
choice = (DefaultGraphCell)GraphEventManager.getReference().getConnectedNodes(currentGraphCell).get(0);
}
else
{
while (choice == null)
{
int numberchoice = (int)((Math.random()*aantal) - 0.001);
//System.out.println(numberchoice);
//System.out.println(GraphEventManager.getReference().getConnectedNodes(currentGraphCell).get(numberchoice));
//System.out.println(exceptNode);
if (GraphEventManager.getReference().getConnectedNodes(currentGraphCell).get(numberchoice) != exceptNode)
{
choice = (DefaultGraphCell)GraphEventManager.getReference().getConnectedNodes(currentGraphCell).get(numberchoice);
}
}
}
return choice;
}
public DefaultGraphCell getDestination()
{
return nextNode;
}
public void setNextNode(DefaultGraphCell nextNode)
{
this.nextNode = nextNode;
}
public void setStatus(int status)
{
this.status = status;
}
public DefaultGraphCell getSource()
{
return previousNode;
}
public void setPreviousNode(DefaultGraphCell previousNode)
{
this.previousNode = previousNode;
}
public double getProgress()
{
return progress;
}
public String getSearchFor()
{
if (searchFor != null)
{
return searchFor.getSearchFor();
}
else
{
return "";
}
}
public ResourceQuery getOriginalQuery()
{
return searchFor;
}
public int getAge()
{
return age;
}
public String getStatus()
{
if (status == MOVING)
{
return "Moving";
}
else if (status == SEARCHING)
{
return "Searching";
}
else if (status == EXPLORING)
{
return "Exploring";
}
else if (status == RETURNING)
{
return "Returning";
}
else if (status == DEAD)
{
return "Dead";
}
return null;
}
public DefaultGraphCell getOrigin()
{
return origin;
}
protected DefaultGraphCell origin;
protected ResourceQuery searchFor;
protected DefaultGraphCell previousNode;
protected DefaultGraphCell nextNode;
protected double progress;
protected int age;
protected int status;
protected static final int MOVING = 1;
protected static final int SEARCHING = 2;
protected static final int EXPLORING = 3;
protected static final int RETURNING = 4;
protected static final int DEAD = 5;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -