From dbcef49fa3d15adac52ccc38482a5625de767391 Mon Sep 17 00:00:00 2001 From: g le-chartier Date: Wed, 10 Apr 2024 16:43:12 +0200 Subject: [PATCH] Added countNear and setCell functions in Table --- src/backend/Table.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/backend/Table.java b/src/backend/Table.java index f2a8fed..a72e15e 100644 --- a/src/backend/Table.java +++ b/src/backend/Table.java @@ -30,10 +30,26 @@ public class Table { //return the Cell object of coordinates x, y return table.get(x).get(y); } - //TODO : set(Cell, x, y) set an object Cell to coordinate x, y - - //TODO : count around (xy) -> return how many around this cell + //TODO-complete : set(Cell, x, y) set an object Cell to coordinate x, y + public void setCell(Cell cell, int x int y){ + this.table.get(x).get(y) = cell; + } + //TODO-complete : count near (xy) -> return how many cells around this cell + public int countNear(int x, int y){ + int cellCount =0; + // if border is true + for (int i = x-1;i<=x+1;i++){ + for (int j = y-1;j<=y+1;y++){ + if not(i == j){ + this.table.getCell(i,j).getValue +=cellCount; + } + } + + } + + //if border is false + } //TODO : set agent (x y agent) load an agent to coordinates x,y //TODO : set random (density) create a random table of determined density