this.showText = "Ignate!";
this.fuseAgent = new HashSet<FuseAgent>();
}
for (Vector2D v : relativePositions) {
PacmanAgent2D agent;
if (agentType.equals("dynamite")) {
DynamiteAgent da = new DynamiteAgent(0, this, this.getParCollection());
this.dynamiteAgent.add(da);
agent = da;
this.nextAgentType = "fuse";
} else if (agentType.equals("fuse")) {
FuseAgent fa = new FuseAgent(0, this, this.getParCollection());
this.fuseAgent.add(fa);
agent = fa;
this.nextAgentType = "normal";
} else {
agent = new PacmanAgent2D(0, this, this.getParCollection(), agentColor);
}
agent.addSensor(new GenericSensor<Long, PolytrisEnvironment, PacmanAgent2D>() {
/**
*
*/
private static final long serialVersionUID = -1927354872920066113L;
@Override
public Long sense(PolytrisEnvironment env,
PacmanAgent2D agent) {
return env.score;
}
@Override
public String id() {
return "YOUR SCORE";
}
});
agent.addSensor(new GenericSensor<Long, PolytrisEnvironment, PacmanAgent2D>() {
/**
*
*/
private static final long serialVersionUID = -219056252893169910L;
@Override
public Long sense(PolytrisEnvironment env,
PacmanAgent2D agent) {
return -1l;
}
private ArrayList<Vector2D> nextSensingAgent = null;
private VectorVersionOfAgent currentAgent;
@Override
public BufferedImage getSensorView(
PolytrisEnvironment env, PacmanAgent2D agent) {
try {
if (this.nextSensingAgent != PolytrisEnvironment.this.nextAgent) {
currentAgent = new VectorVersionOfAgent(
PolytrisEnvironment.this.nextAgent,
PolytrisEnvironment.this.getParCollection());
this.nextSensingAgent = PolytrisEnvironment.this.nextAgent;
}
return currentAgent.generateImage();
} catch (Exception e) {
return new BufferedImage(50, 50, BufferedImage.TYPE_3BYTE_BGR);
}
}
@Override
public String id() {
return "Next agent";
}
});
wholeAgent.addPartAgent(agent);
Vector2D pos = new Vector2D(position);
pos.translate(v);
float angle;
if (!agentType.equals("normal")) {
angle = 0;
} else {
angle = (float) ((rand.nextFloat() - 0.5) * 360);
}
if (!this.addCollidingAgent(agent, pos, angle)) {
for (int i : successfullyAddedAgents) {
this.removeAgent(i);
}
return false;
} else {
successfullyAddedAgents.add(agent.id());
}
this.pacmanToTetrisAgentMapping.put(agent.id(), wholeAgent);
}
this.agents.put(agents.size(), wholeAgent);
return true;
}