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