int oldX = getUnit().getCell().getX();
int oldY = getUnit().getCell().getY();
Cell cell = getUnit().move(getDnaParams().getSpecies(), downMove, rightMove, getProgenitor());
if (oldX != cell.getX() || oldY != cell.getY()) {
Color resultantColor = null;
Resource resource = getUnit().getCell().getResource();
int artisticType = resource.getType();
if (artisticType == ResourceConstants.ARTISTIC_COLOR_RESOURCE) {
// colore dell'agente in RGB
Color agentColor = getDnaParams().getColor();
int redAgent = agentColor.getRed();
int greenAgent = agentColor.getGreen();
int blueAgent = agentColor.getBlue();
// colore dell'agente in HSB
float[] hsbvalsAgent = Color.RGBtoHSB(redAgent, greenAgent, blueAgent, null);
float hAgent = hsbvalsAgent[0];
float sAgent = hsbvalsAgent[1];
float bAgent = hsbvalsAgent[2];
// colore della risorsa in RGB
Color resourceColor = resource.getColor();
int redResource = resourceColor.getRed();
int greenResource = resourceColor.getGreen();
int blueResource = resourceColor.getBlue();
// colore della risorsa in HSB
float[] hsbvalsRes = Color.RGBtoHSB(redResource, greenResource, blueResource, null);
float hRes = hsbvalsRes[0];
float sRes = hsbvalsRes[1];
// avvicinamento del colore dell'agente al colore della cella
if (sRes > 0.5) {
float diff = hAgent - hRes;
if (Math.abs(diff) > 0.5f) {
hAgent += diff / 50f;
} else {
hAgent -= diff / 50f;
}
// normalizzazione
if (hAgent > 1f) {
hAgent = hAgent - 1f;
} else if (hAgent < 0f) {
hAgent = hAgent + 1f;
}
}
if (getParams().isHunger()) {
// si verifica se c'e' almeno un bordo nelle vicinanze
boolean nearBorder = false;
Set<Cell> surroundings = EnvironmentFunction.getSurroundings(getWorld().getGrid(), getUnit().getCell(), 5, getWorld().getParams().getCols(), getWorld().getParams().getRows(), false);
for (Cell c : surroundings) {
Resource artres = c.getResource();
if (artres.getType() == ResourceConstants.ARTISTIC_TRACE_RESOURCE) {
nearBorder = true;
break;
}
}