From 0d3c62f142b021651a81b7311e502a3c8c1252c2 Mon Sep 17 00:00:00 2001 From: "guillaume.bonabau" Date: Thu, 25 Apr 2024 11:16:55 +0200 Subject: [PATCH] fixing merge errors --- src/backend/Simulator.java | 4 ++-- src/backend/Table.java | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index debb37a..ed43d97 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -48,7 +48,7 @@ public class Simulator extends Thread { this.width=COL_NUM; this.height=LINE_NUM; enableLogs = true; // for debugging purposes - table = new Table(height, width); + table = new Table(height, width, this); //Default rule : Survive always, birth never @@ -114,7 +114,7 @@ public class Simulator extends Thread { } //then evolution of the field // TODO-INPROGRESS : apply game rule to all cells of the field - Table tempTable = new Table(this.height, this.width); + Table tempTable = new Table(this.height, this.width, this); for(int x=0; x> table; private Simulator simulator; - //TODO-INPROGRESS : create constructor - public Table(int height, int width) { + public Table(int height, int width, Simulator tempSimulator) { this.height = height; this.width = width; - this.simulator = simulator; - + this.simulator = tempSimulator; //initialize the table int vertexCount = 3; @@ -28,16 +26,35 @@ public class Table { public int getwidth() { return this.width; } + public boolean isLoopingBorder() { + return simulator.isLoopingBorder(); + } //TODO-COMPLETE : create getCell public Cell getCell(int x,int y) { //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).set(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 (!(i == j)){ + cellCount += this.getCell(i,j).getValue(); + } + } + + } + return 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