Skip to content

Commit f1b9ce5

Browse files
committed
some simple code changes to improve
1 parent f2ff2b3 commit f1b9ce5

File tree

13 files changed

+83
-89
lines changed

13 files changed

+83
-89
lines changed

src/entities/generic/AnimalTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ void testEat_EntityAlreadyDead() {
9999
assertFalse(prey.isAlive());
100100
assertEquals(animal.hungerController.getFoodLevel(), initialFoodLevel);
101101
}
102-
103-
@Test
104-
void testEat_NullList() {
105-
double initialFoodLevel = animal.hungerController.getFoodLevel();
106-
animal.hungerController.eat(null);
107-
assertTrue(animal.isAlive());
108-
assertEquals(animal.hungerController.getFoodLevel(), initialFoodLevel);
109-
}
110102

111103
@Test
112104
void testMoveToNearestFood_NoNearbyEntities() {

src/simulation/FieldBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class FieldBuilder {
2020
private ArrayList<Entity> entities; // The list of entities.
2121

2222
/**
23-
* Constructor.
23+
* Constructor -- Create a FieldBuilder with the given width and height and create all entities.
2424
* @param width The width of the field.
25-
* @param height The height of the field
25+
* @param height The height of the field.
2626
*/
2727
public FieldBuilder(int width, int height) {
2828
this.width = width;

src/simulation/environment/Environment.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,30 @@ public Environment() {
2323
}
2424

2525
/**
26-
* Update the weather effects on the display.
26+
* Draws the weather effects on the display.
2727
* @param display The display to update the weather effects on.
2828
*/
2929
public void drawWeatherEffects(Display display) {
3030
weatherController.drawWeatherEffects(display);
3131
}
3232

3333
/**
34-
* Update the weather that affects the simulation.
34+
* Draws the weather that affects the simulation.
3535
*/
3636
public void updateWeather() {
3737
weatherController.updateWeather();
3838
}
3939

40+
/**
41+
* Draws the weather text onto the display.
42+
* @param display The display to draw.
43+
*/
4044
public void drawWeatherText(Display display) {
4145
weatherController.drawWeatherText(display);
4246
}
4347

4448
/**
45-
* Update the time of day, and if the day has changed, change the weather.
49+
* Updates the time of day, and if the day has changed, change the weather.
4650
* @param dayNightCycleRate The amount of time to pass per update.
4751
*/
4852
public void updateTime(double dayNightCycleRate) {
@@ -53,15 +57,15 @@ public void updateTime(double dayNightCycleRate) {
5357
}
5458

5559
/**
56-
* Draw the darkness effect onto the display.
60+
* Draws the darkness effect onto the display.
5761
* @param display The display to draw the effects on.
5862
*/
5963
public void drawDarknessEffect(Display display) {
6064
timeController.drawDarknessEffect(display);
6165
}
6266

6367
/**
64-
* Update the time effects on the display; mainly time text.
68+
* Draws the time effects on the display; mainly time text.
6569
* @param display The display to update the time effects on.
6670
*/
6771
public void drawTimeText(Display display) {

src/simulation/quadTree/QuadTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ private void queryInternal(Circle queryRange, List<Entity> foundEntities) {
118118
}
119119
}
120120

121-
// Recursively query children
122121
if (!hasSubdivided) return;
122+
// Recursively query children:
123123
topLeftTree.queryInternal(queryRange, foundEntities);
124124
topRightTree.queryInternal(queryRange, foundEntities);
125125
bottomLeftTree.queryInternal(queryRange, foundEntities);

src/simulation/quadTree/Rectangle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*/
1111
public record Rectangle(double x, double y, double w, double h) {
1212
/**
13-
* @param point The point to check inside the rectangle
14-
* @return True if the point is in the rectangle, false otherwise
13+
* @param point The point to check inside the rectangle.
14+
* @return True if the point is in the rectangle, false otherwise.
1515
*/
1616
public boolean hasPoint(Vector point) {
1717
double px = point.x();

src/simulation/simulationData/AnimalData.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
* @version 1.0
1515
*/
1616
public class AnimalData extends EntityData{
17-
public int[] maxLitterSize; // Maximum number of offspring per breeding
18-
public double[] maxSpeed; // Speed of the entity
19-
public double[] sight; // Range at which the entity can see other entities
20-
public String[] eats; // List of entities that this entity can eat
17+
public int[] maxLitterSize; // Maximum number of offspring per breeding.
18+
public double[] maxSpeed; // Speed of the entity.
19+
public double[] sight; // Range at which the entity can see other entities.
20+
public String[] eats; // List of entities that this entity can eat.
2121
/**
2222
* @return A random set of genetics for an animal based on the data provided.
2323
*/
2424
public AnimalGenetics generateRandomGenetics() {
25-
Color convertedColour = new Color(this.colour[0], this.colour[1], this.colour[2]); // Convert RGB data to java.swing.Color
26-
Color mutatedColour = Utility.mutateColor(convertedColour, 1); // Change the colour slightly
25+
Color convertedColour = new Color(this.colour[0], this.colour[1], this.colour[2]); // Convert RGB data to java.awt.Color.
26+
Color mutatedColour = Utility.mutateColor(convertedColour, 1); // Change the colour slightly.
2727

2828
return new AnimalGenetics(
2929
generateRandomNumberBetween(multiplyingRate[0], multiplyingRate[1]),

src/simulation/simulationData/Data.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* @version 1.0
1010
*/
1111
public class Data {
12-
public static final String PATH = System.getProperty("user.dir"); // The main directory of the project
12+
public static final String PATH = System.getProperty("user.dir"); // The main directory of the project.
1313

14-
// The data of the simulation
14+
// The data of the simulation:
1515
private static final SimulationData simulationData = Parser.parseSimulationData(Parser.getContentsOfFile(PATH + "/src/simulation_data.json"));
1616

1717
// Getters:

src/simulation/simulationData/EntityData.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
* @version 1.0
99
*/
1010
public abstract class EntityData {
11-
public String name; // Name of the entity
12-
public int numberOfEntitiesAtStart; // Number of entities at the start of the simulation
13-
public int[] maxAge; // Maximum age of the entity
14-
public int[] matureAge; // Age at which the entity can start breeding
15-
public double[] multiplyingRate; // Rate at which the entity can multiply
16-
public int[] size; // Size of the entity
17-
public int[] colour; // RGB colour of the entity
18-
public int[] overcrowdingThreshold; // Number of entities at which the entity will die
19-
public double[] overcrowdingRadius; // Radius inside of which the threshold is checked
20-
public double[] maxOffspringSpawnDistance; // Maximum distance offspring can spawn from the parent entity
21-
public double[] mutationRate; // The rate at which the genetics will mutate
11+
public String name; // Name of the entity.
12+
public int numberOfEntitiesAtStart; // Number of entities at the start of the simulation.
13+
public int[] maxAge; // Maximum age of the entity.
14+
public int[] matureAge; // Age at which the entity can start breeding.
15+
public double[] multiplyingRate; // Rate at which the entity can multiply.
16+
public int[] size; // Size of the entity.
17+
public int[] colour; // RGB colour of the entity.
18+
public int[] overcrowdingThreshold; // Number of entities at which the entity will die.
19+
public double[] overcrowdingRadius; // Radius inside of which the threshold is checked.
20+
public double[] maxOffspringSpawnDistance; // Maximum distance offspring can spawn from the parent entity.
21+
public double[] mutationRate; // The rate at which the genetics will mutate.
2222

2323
/**
2424
* @return A random number between the given double min and max values.

src/simulation/simulationData/PlantData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
* @version 1.0
1414
*/
1515
public class PlantData extends EntityData {
16-
public int[] numberOfSeeds; // Number of seeds produced by the plant -- when multiplied
17-
public double rainingGrowthFactor; // Growth factor when raining (affects number of seeds and range of growth)
16+
public int[] numberOfSeeds; // Number of seeds produced by the plant -- when multiplied.
17+
public double rainingGrowthFactor; // Growth factor when raining (affects number of seeds and range of growth).
1818

1919
/**
2020
* @return A random set of genetics for a plant based on the data provided.
2121
*/
2222
public PlantGenetics generateRandomGenetics() {
23-
Color convertedColour = new Color(this.colour[0], this.colour[1], this.colour[2]); // Convert rgRGB data to java.swing.Color
24-
Color mutatedColour = Utility.mutateColor(convertedColour, 1); // Change the colour slightly
23+
Color convertedColour = new Color(this.colour[0], this.colour[1], this.colour[2]); // Convert array RGB data to java.awt.Color.
24+
Color mutatedColour = Utility.mutateColor(convertedColour, 1); // Change the colour slightly.
2525

2626
return new PlantGenetics(
2727
generateRandomNumberBetween(maxAge[0], maxAge[1]),

src/simulation/simulationData/SimulationData.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package simulation.simulationData;
22

33
public class SimulationData {
4-
public AnimalData[] preysData; // An array of prey species data
5-
public AnimalData[] predatorsData; // An array of predator species data
6-
public PlantData[] plantsData; // An array of plant types data
4+
public AnimalData[] preysData; // An array of prey species data.
5+
public AnimalData[] predatorsData; // An array of predator species data.
6+
public PlantData[] plantsData; // An array of plant types data.
77

8-
public double foodValueForAnimals; // Scales the food value of animals
9-
public double foodValueForPlants; // Scales the food value of plants
10-
public double animalHungerDrain; // Controls rate of foodLevel depletion over time
11-
public double animalBreedingCost; // Scales how much food is consumed on breeding; use 0 for no food cost
8+
public double foodValueForAnimals; // Scales the food value of animals.
9+
public double foodValueForPlants; // Scales the food value of plants.
10+
public double animalHungerDrain; // Controls rate of foodLevel depletion over time.
11+
public double animalBreedingCost; // Scales how much food is consumed on breeding; use 0 for no food cost.
1212

13-
public double mutationFactor; // The ratio that the genetics will mutate by
14-
public double entityAgeRate; // Controls how fast the entities age
13+
public double mutationFactor; // The ratio that the genetics will mutate by.
14+
public double entityAgeRate; // Controls how fast the entities age.
1515
public double fieldScaleFactor; // The size of the field, smaller value means more zoomed in.
16-
public double weatherChangeProbability; // The probability of the weather changing
17-
public double windStrength; // The strength of the wind in windy conditions
18-
public double stormMovementSpeedFactor; // When a storm happens, the factor that hinders the entities' speed
19-
public double dayNightCycleSpeed; // The speed of the day-night cycle -- how fast the time passes
20-
public boolean doDayNightCycle; // Whether the day-night cycle is enabled
21-
public boolean doWeatherCycle; // Whether the weather cycle is enabled
22-
public boolean showQuadTrees; // Whether the quad trees are shown
16+
public double weatherChangeProbability; // The probability of the weather changing.
17+
public double windStrength; // The strength of the wind in windy conditions.
18+
public double stormMovementSpeedFactor; // When a storm happens, the factor that hinders the entities' speed.
19+
public double dayNightCycleSpeed; // The speed of the day-night cycle -- how fast the time passes.
20+
public boolean doDayNightCycle; // Whether the day-night cycle is enabled.
21+
public boolean doWeatherCycle; // Whether the weather cycle is enabled.
22+
public boolean showQuadTrees; // Whether the quad trees are shown.
2323

2424
public double animalHungerThreshold; // Animals will look for food at this threshold.
2525
public double animalDyingOfHungerThreshold; // Animals will prioritise looking for food at this threshold.

0 commit comments

Comments
 (0)