com.barrybecker4.simulation.cave.model.kernal.BasicKernel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bb4-cave Show documentation
Show all versions of bb4-cave Show documentation
bb4-simulations java code.
package com.barrybecker4.simulation.cave.model.kernal;
import com.barrybecker4.simulation.cave.model.Cave;
/**
* Looks only at immediate neighbors
* @author Barry Becker
*/
public class BasicKernel extends AbstractKernel {
private static final double TOTAL_WEIGHT = 8;
public BasicKernel(Cave cave) {
super(cave);
}
public double countNeighbors(int x, int y) {
double count = 0;
for (int i = -1; i < 2; i++) {
int neighborX = x + i;
for (int j = -1; j < 2; j++) {
int neighborY = y + j;
// If we're looking at the middle point
if (i == 0 && j == 0) {
// Do nothing, we don't want to add ourselves in!
continue;
}
// In case the index we're looking at it off the edge of the map, or a filled neighbor
if (isOffEdge(neighborX, neighborY)) {
count += 1.0;
}
else {
count += cave.getValue(neighborX, neighborY);
}
}
}
return count / 8;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy