diff --git a/src/main/java/app/model/agents/Cells/BooleanCell.java b/src/main/java/app/model/agents/Cells/BooleanCell.java new file mode 100644 index 00000000..fc854632 --- /dev/null +++ b/src/main/java/app/model/agents/Cells/BooleanCell.java @@ -0,0 +1,27 @@ +package app.model.agents.Cells; + +public class BooleanCell implements Cell +{ + private boolean explored; + private boolean obstacle; + + public void explored() + { + explored = true; + } + + public void obstacle() + { + obstacle = true; + } + + public boolean getExploredState() + { + return explored; + } + + public boolean getObstacleState() + { + return obstacle; + } +} diff --git a/src/main/java/app/model/agents/Cells/Cell.java b/src/main/java/app/model/agents/Cells/Cell.java new file mode 100644 index 00000000..60acadb9 --- /dev/null +++ b/src/main/java/app/model/agents/Cells/Cell.java @@ -0,0 +1,5 @@ +package app.model.agents.Cells; + +public interface Cell +{ +} diff --git a/src/main/java/app/model/agents/Cells/CellFactory.java b/src/main/java/app/model/agents/Cells/CellFactory.java new file mode 100644 index 00000000..5b134f52 --- /dev/null +++ b/src/main/java/app/model/agents/Cells/CellFactory.java @@ -0,0 +1,19 @@ +package app.model.agents.Cells; + +public abstract class CellFactory +{ + public static Cell make(CellType type) + { + return create(type); + } + + private static Cell create(CellType type) + { + switch(type) + { + case PHERAMONE -> {return new PheramoneCell();} + case BOOLEAN -> {return new BooleanCell();} + } + return null; + } +} diff --git a/src/main/java/app/model/agents/Cells/CellType.java b/src/main/java/app/model/agents/Cells/CellType.java new file mode 100644 index 00000000..83b36aa6 --- /dev/null +++ b/src/main/java/app/model/agents/Cells/CellType.java @@ -0,0 +1,8 @@ +package app.model.agents.Cells; + + public enum CellType + { + PHERAMONE, + BOOLEAN, + } + diff --git a/src/main/java/app/model/agents/Cells/PheramoneCell.java b/src/main/java/app/model/agents/Cells/PheramoneCell.java new file mode 100644 index 00000000..75a21f3f --- /dev/null +++ b/src/main/java/app/model/agents/Cells/PheramoneCell.java @@ -0,0 +1,16 @@ +package app.model.agents.Cells; + +public class PheramoneCell implements Cell +{ + private double value; + + public double getValue() + { + return value; + } + + public void updateValue(double newValue) + { + value = newValue; + } +} diff --git a/src/main/java/app/model/agents/Grid.java b/src/main/java/app/model/agents/Grid.java new file mode 100644 index 00000000..4d86dcba --- /dev/null +++ b/src/main/java/app/model/agents/Grid.java @@ -0,0 +1,44 @@ +package app.model.agents; + +import app.model.agents.Cells.*; + +public class Grid +{ + protected int rowSize; + protected int colSize; + protected Cell[][] grid; + protected double cellSize = 1.0; + protected CellType type; + + + public Grid(double length, double width, CellType type) + { + rowSize = (int)(length / cellSize); + colSize = (int)(width / cellSize); + this.type = type; + + grid = new Cell[rowSize][colSize]; + initializeAllCells(); + } + + public void initializeAllCells() + { + for(int row = 0; row < rowSize; row++) + { + for(int col = 0; col < colSize; col++) + { + grid[row][col] = CellFactory.make(type); + } + } + } + + public Cell getCellAt(int row, int col) + { + switch (type) + { + case BOOLEAN -> {return (BooleanCell)grid[row][col];} + case PHERAMONE -> {return (PheramoneCell)grid[row][col];} + } + return null; + } +} diff --git a/src/test/java/jgfx/javagradlefx/GridTest.java b/src/test/java/jgfx/javagradlefx/GridTest.java new file mode 100644 index 00000000..1ff8da14 --- /dev/null +++ b/src/test/java/jgfx/javagradlefx/GridTest.java @@ -0,0 +1,31 @@ +package jgfx.javagradlefx; + +import app.model.agents.*; +import app.model.agents.Cells.BooleanCell; +import app.model.agents.Cells.CellType; +import app.model.agents.Cells.PheramoneCell; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class GridTest +{ + @Test + void testPheramoneCell() + { + Grid grid = new Grid(100, 100, CellType.PHERAMONE); + PheramoneCell cell = (PheramoneCell)grid.getCellAt(10, 10); + double value = cell.getValue(); + + assertEquals(value, 0.0); + } + + @Test + void testBooleanCell() + { + Grid grid = new Grid(100, 100, CellType.BOOLEAN); + BooleanCell cell = (BooleanCell) grid.getCellAt(10, 10); + boolean value = cell.getExploredState(); + + assertEquals(value, false); + } +}