use of aima.core.agent.Agent in project aima-java by aimacode.
the class VacuumEnvironmentViewCtrl method updateEnvStateView.
@Override
protected void updateEnvStateView(Environment env) {
if (env instanceof VacuumEnvironment) {
VacuumEnvironment vEnv = (VacuumEnvironment) env;
for (String loc : locations) {
BorderPane pane = getLocPane(loc);
if (vEnv.getLocationState(loc).equals(LocationState.Dirty))
pane.setStyle("-fx-background-color: lightgrey");
else
pane.setStyle("-fx-background-color: white");
pane.setCenter(null);
}
for (Agent agent : vEnv.getAgents()) {
BorderPane pane = getLocPane(vEnv.getAgentLocation(agent));
pane.setCenter(createAgentRep(agent == agentInAction));
}
}
}
use of aima.core.agent.Agent in project aima-java by aimacode.
the class MapEnvironmentViewCtrl method update.
protected void update() {
envStateView.getChildren().clear();
if (env != null) {
double scale = adjustTransform();
Map map = env.getMap();
// print connections
for (String loc1 : map.getLocations()) {
Point2D pt1 = map.getPosition(loc1);
for (String loc2 : map.getPossibleNextLocations(loc1)) {
Point2D pt2 = map.getPosition(loc2);
Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
line.setStroke(Color.LIGHTGRAY);
envStateView.getChildren().add(line);
}
}
// print track of first agent
if (!env.getAgents().isEmpty()) {
String aLoc = env.getAgentLocation(env.getAgents().get(0));
if (track.isEmpty() || !Objects.equals(track.get(track.size() - 1), aLoc))
track.add(aLoc);
for (int i = 1; i < track.size(); i++) {
Point2D pt1 = map.getPosition(track.get(i - 1));
Point2D pt2 = map.getPosition(track.get(i));
Shape line = new Line(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY());
line.setStroke(Color.RED);
line.setStrokeWidth(2);
envStateView.getChildren().add(line);
}
}
// print locations
for (String loc : map.getLocations()) {
Point2D point = map.getPosition(loc);
Text text = new Text(point.getX() + 10 / scale, point.getY(), loc);
text.setFont(new Font(12.0 / scale));
envStateView.getChildren().add(text);
envStateView.getChildren().add(new Circle(point.getX(), point.getY(), 2 / scale));
}
// print agent locations
for (Agent agent : env.getAgents()) {
String loc = env.getAgentLocation(agent);
if (loc != null) {
Point2D pt = map.getPosition(loc);
envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 8 / scale, Color.RED));
}
}
// print goal
if (goal != null) {
Point2D pt = map.getPosition(goal);
envStateView.getChildren().add(new Circle(pt.getX(), pt.getY(), 6 / scale, Color.GREEN));
}
}
}
use of aima.core.agent.Agent in project aima-java by aimacode.
the class AbstractEnvironment method step.
/**
* Central template method for controlling agent simulation. The concrete
* behavior is determined by the primitive operations
* {@link #getPerceptSeenBy(Agent)}, {@link #executeAction(Agent, Action)},
* and {@link #createExogenousChange()}.
*/
public void step() {
for (Agent agent : agents) {
if (agent.isAlive()) {
Percept percept = getPerceptSeenBy(agent);
Action anAction = agent.execute(percept);
executeAction(agent, anAction);
notifyEnvironmentViews(agent, percept, anAction);
}
}
createExogenousChange();
}
use of aima.core.agent.Agent in project aima-java by aimacode.
the class TrivialVacuumDemo method main.
public static void main(String[] args) {
// create environment with random state of cleaning.
Environment env = new VacuumEnvironment();
EnvironmentView view = new SimpleEnvironmentView();
env.addEnvironmentView(view);
Agent a = null;
a = new ModelBasedReflexVacuumAgent();
// a = new ReflexVacuumAgent();
// a = new SimpleReflexVacuumAgent();
// a = new TableDrivenVacuumAgent();
env.addAgent(a);
env.step(16);
env.notifyViews("Performance=" + env.getPerformanceMeasure(a));
}
use of aima.core.agent.Agent in project aima-java by aimacode.
the class MapAgentView method getAgentLocs.
/** Returns the locations of all agents. */
protected List<String> getAgentLocs() {
List<String> result = new ArrayList<String>();
MapEnvironment mEnv = getMapEnv();
for (Agent a : mEnv.getAgents()) result.add(mEnv.getAgentLocation(a));
return result;
}
Aggregations