We gona open champain, LoopingBorder Working YAY
This commit is contained in:
parent
383a3c1cd7
commit
7d2d708e1a
|
|
@ -60,6 +60,7 @@ public class Table {
|
|||
// NEED A STRONG OPTIMISATION
|
||||
public int countNear(int row, int column){
|
||||
int count = 0;
|
||||
boolean loopingBorder = isLoopingBorder();
|
||||
// Define the relative positions of neighboring cells (assuming 8 neighbors)
|
||||
int[][] neighbors = {
|
||||
{-1, -1}, {-1, 0}, {-1, 1},
|
||||
|
|
@ -70,14 +71,22 @@ public class Table {
|
|||
for (int[] neighbor : neighbors) {
|
||||
int x = row + neighbor[0];
|
||||
int y = column + neighbor[1];
|
||||
// Check if the new indices are within the table boundaries
|
||||
if (x >= 0 && x < this.width && y >= 0 && y < this.height) {
|
||||
count+= this.getCell(x, y).getValue();
|
||||
|
||||
if (loopingBorder) {
|
||||
x = (x + width) % width;
|
||||
y = (y + height) % height;
|
||||
}
|
||||
|
||||
if (!loopingBorder && (x < 0 || x >= width || y < 0 || y >= height)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count += this.getCell(x, y).getValue();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//TODO : set agent (x y agent) load an agent to coordinates x,y
|
||||
|
||||
//TODO : set random (density) create a random table of determined density
|
||||
|
|
|
|||
Loading…
Reference in New Issue