public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
int result = -1;
Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
angle.rotate(Vector2D.NULL_VECTOR, -45+0*(90/(3-1.0))*Math.PI/180);
CollisionData coll = env.nearestRayCollision(
env.getAgentPosition(agent.id()),
angle,
agent);
if ((coll.getCollisionPoint()!=null&&coll.getCollisionPoint().distance(env.getAgentPosition(agent.id()))<15)){
result = coll.getAgent().id();
}
return result;
}
});
this.addSensor(new GenericSensor<Integer, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {
/**
*
*/
private static final long serialVersionUID = 187236060508880836L;
@Override
public String id() {
return "sensing-agent-1";
}
@Override
public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
int result = -1;
Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
angle.rotate(Vector2D.NULL_VECTOR, -45+1*(90/(3-1.0))*Math.PI/180);
CollisionData coll = env.nearestRayCollision(
env.getAgentPosition(agent.id()),
angle,
agent);
if ((coll.getCollisionPoint()!=null&&coll.getCollisionPoint().distance(env.getAgentPosition(agent.id()))<15)){
result = coll.getAgent().id();
}
return result;
}
});
this.addSensor(new GenericSensor<Integer, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {
/**
*
*/
private static final long serialVersionUID = -2034243692637537731L;
@Override
public String id() {
return "sensing-agent-2";
}
@Override
public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
int result = -1;
Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
angle.rotate(Vector2D.NULL_VECTOR, -45+2*(90/(3-1.0))*Math.PI/180);
CollisionData coll = env.nearestRayCollision(
env.getAgentPosition(agent.id()),
angle,
agent);
if ((coll.getCollisionPoint()!=null&&coll.getCollisionPoint().distance(env.getAgentPosition(agent.id()))<15)){
result = coll.getAgent().id();
}
return result;
}
});