Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void ejectAgents(Agent tracer) {
Cell beforeDeathCell = tracer.getUnit().getLastOccupiedCell();
short xleft = beforeDeathCell.getX();
short xright = beforeDeathCell.getX();
short yleft = beforeDeathCell.getY();
short yright = beforeDeathCell.getY();
short direction = tracer.getLastDirection();
short cols = tracer.getWorld().getParams().getCols();
short rows = tracer.getWorld().getParams().getRows();
switch (direction) {
case 0:
xleft--;
xright++;
if (xleft < 0) {
xleft = (short) (cols - 1);
}
if (xright >= cols) {
xright = 0;
}
break;
case 1:
xleft--;
yleft--;
xright++;
yright++;
if (xleft < 0) {
xleft = (short) (cols - 1);
}
if (xright >= cols) {
xright = 0;
}
if (yleft < 0) {
yleft = (short) (rows - 1);
}
if (yright >= rows) {
yright = 0;
}
break;
case 2:
yleft--;
yright++;
if (yleft < 0) {
yleft = (short) (rows - 1);
}
if (yright >= rows) {
yright = 0;
}
break;
case 3:
xleft++;
yleft--;
xright--;
yright++;
if (xleft >= cols) {
xleft = 0;
}
if (xright < 0) {
xright = (short) (cols - 1);
}
if (yleft < 0) {
yleft = (short) (rows - 1);
}
if (yright >= rows) {
yright = 0;
}
break;
case 4:
xleft++;
xright--;
if (xright < 0) {
xright = (short) (cols - 1);
}
if (xleft >= cols) {
xleft = 0;
}
break;
case 5:
xleft++;
yleft++;
xright--;
yright--;
if (xright < 0) {
xright = (short) (cols - 1);
}
if (xleft >= cols) {
xleft = 0;
}
if (yright < 0) {
yright = (short) (rows - 1);
}
if (yleft >= rows) {
yleft = 0;
}
break;
case 6:
yleft++;
yright--;
if (yright < 0) {
yright = (short) (rows - 1);
}
if (yleft >= rows) {
yleft = 0;
}
break;
case 7:
xleft--;
yleft++;
xright++;
yright--;
if (xright >= cols) {
xright = 0;
}
if (xleft < 0) {
xleft = (short) (cols - 1);
}
if (yright < 0) {
yright = (short) (rows - 1);
}
if (yleft >= rows) {
yleft = 0;
}
break;
default:
break;
}
Cell rightCell = tracer.getWorld().getCell(xright, yright);
Cell leftCell = tracer.getWorld().getCell(xleft, yleft);
int leftOrRight = tracer.getLeftOrRight();
Cell internalCell = null, externalCell = null;
if (leftOrRight == -1) {
internalCell = leftCell;
externalCell = rightCell;
} else if (leftOrRight == 1) {
internalCell = rightCell;