Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e1396d5
Added: Utils, Plant, Animal + Genes demo
jkbstepien Dec 18, 2022
d67c431
Merge pull request #1 from jkbstepien/development
jkbstepien Dec 18, 2022
d25f1f2
Added: class structure + builder for WorldMap.
jkbstepien Dec 23, 2022
26750f6
Merge pull request #2 from jkbstepien/development
jkbstepien Dec 23, 2022
faddf6b
implemented Genes + started implementing WorldMap
MagrosThornrime Dec 31, 2022
728c58f
Added: reading from resources/conf1.json file and basic gui.
jkbstepien Jan 3, 2023
29cf3fa
...
MagrosThornrime Jan 3, 2023
3529499
Merge branch 'mateusz'
jkbstepien Jan 3, 2023
8ce47b6
Added: WorldMap functionality (animal and plants).
jkbstepien Jan 3, 2023
1dbf647
Added: WorldMap functionality (animal and plants) v2.
jkbstepien Jan 3, 2023
dfea564
small fix
MagrosThornrime Jan 4, 2023
06d8246
a beautiful mess
MagrosThornrime Jan 4, 2023
3a521d7
small fix
MagrosThornrime Jan 4, 2023
7736b1a
new version
MagrosThornrime Jan 4, 2023
57bad61
Added: SimulationEngine and SimulationStage.
jkbstepien Jan 4, 2023
f154f9e
Now Animals die during the simulation + fixed PlantsEquator
MagrosThornrime Jan 5, 2023
b0fafc1
Added: Read preferences from user.
jkbstepien Jan 5, 2023
91dd00a
Added: Statistics logic and rendering.
jkbstepien Jan 5, 2023
105c129
Added: Saving Statistics to csv file.
jkbstepien Jan 5, 2023
fc07b30
Added: most popular genotype is now visible in GUI.
jkbstepien Jan 5, 2023
728a58c
Fixed GeneChoice to reset after using all genes
jkbstepien Jan 5, 2023
8b6d3ab
Fixed correct display of animals with most popular genotypes.
jkbstepien Jan 6, 2023
2771c7d
Added: view of Animal details after selecting it.
jkbstepien Jan 6, 2023
c308b25
Added: code cleanup.
jkbstepien Jan 6, 2023
a515495
Added: more tracking stats (born day, age, children).
jkbstepien Jan 6, 2023
4e4d621
IPlants rework + cleaned up the codebase
MagrosThornrime Jan 6, 2023
664df48
removed binaries and workspace files
MagrosThornrime Jan 6, 2023
5a4a5f9
cleanup
jkbstepien Jun 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.gradle/
/.idea/
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.13'
}

group 'org.example'
Expand All @@ -9,9 +10,16 @@ repositories {
mavenCentral()
}

javafx {
version = "17"
modules = [ 'javafx.controls' ]
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.4'
}

test {
Expand Down
Binary file added build/classes/java/main/org/example/Main.class
Binary file not shown.
Binary file added build/classes/java/main/org/example/gui/App.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions build/resources/main/conf1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"width": 1,
"height": 1,
"iEdge": "earth",
"numberOfPlantsAtStart": 10,
"plantEnergy": 0,
"plantsSeededEachDay": 2,
"iPlants": "toxic",
"numberOfAnimalsAtStart": 1,
"animalEnergy": 2000000,
"animalEnergyBreedingThreshold": 50,
"animalBreedingCost": 50,
"animalMinMutations": 2,
"animalMaxMutations": 5,
"genesLength": 10,
"isCrazyBehavior": false,
"isFullRandom": true
}
18 changes: 18 additions & 0 deletions build/resources/main/conf2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"width": 10,
"height": 16,
"iEdge": "earth",
"numberOfPlantsAtStart": 20,
"plantEnergy": 50,
"plantsSeededEachDay": 6,
"iPlants": "equator",
"numberOfAnimalsAtStart": 6,
"animalEnergy": 100,
"animalEnergyBreedingThreshold": 50,
"animalBreedingCost": 50,
"animalMinMutations": 2,
"animalMaxMutations": 5,
"genesLength": 32,
"isCrazyBehavior": true,
"isFullRandom": true
}
18 changes: 18 additions & 0 deletions build/resources/main/conf3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"width": 10,
"height": 10,
"iEdge": "earth",
"numberOfPlantsAtStart": 20,
"plantEnergy": 50,
"plantsSeededEachDay": 6,
"iPlants": "equator",
"numberOfAnimalsAtStart": 11,
"animalEnergy": 100,
"animalEnergyBreedingThreshold": 50,
"animalBreedingCost": 50,
"animalMinMutations": 2,
"animalMaxMutations": 5,
"genesLength": 1,
"isCrazyBehavior": false,
"isFullRandom": false
}
Binary file added build/resources/main/strawberry_resized_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
6 changes: 5 additions & 1 deletion src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.example;

import javafx.application.Application;
import org.example.gui.App;


public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Application.launch(App.class, args);
}
}
82 changes: 82 additions & 0 deletions src/main/java/org/example/gui/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.example.gui;

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import org.example.utils.GetFromFile;
import org.example.utils.Preferences;

import java.io.IOException;

public class App extends Application {

private final GridPane layout = new GridPane();
private final Scene configScene = new Scene(this.layout, 500, 500);

private final GetFromFile getFromFile = new GetFromFile();

private final TextField textField = new TextField("Give path to file");


public void start(Stage primaryStage) {
Button startSimulationButton1 = getButton("src/main/resources/conf1.json", 1);
Button startSimulationButton2 = getButton("src/main/resources/conf2.json", 2);
Button startSimulationButton3 = getButton("src/main/resources/conf3.json", 3);

// Position buttons at center.
GridPane.setHalignment(startSimulationButton1, HPos.CENTER);
GridPane.setHalignment(startSimulationButton2, HPos.CENTER);
GridPane.setHalignment(startSimulationButton3, HPos.CENTER);

layout.addRow(1, startSimulationButton1);
layout.addRow(2, startSimulationButton2);
layout.addRow(3, startSimulationButton3);
customPath(layout);

primaryStage.setTitle("EvolutionSimulator");
primaryStage.setScene(configScene);
primaryStage.show();

}

private Button getButton(String path, int number) {
Button startSimulationButton = new Button("Go to simulation " + number);
startSimulationButton.setOnMouseClicked(event -> {
Preferences preferences;
try {
preferences = getFromFile.getPreferencesFromFile(path);
} catch (IOException e) {
throw new RuntimeException(e);
}

var simulationStage = new SimulationStage(preferences);
simulationStage.setTitle("World Map");

// primaryStage.close();
});
return startSimulationButton;
}

private void customPath(GridPane layout) {

Button button = new Button("Read simulation from file");
GridPane.setHalignment(button, HPos.CENTER);
button.setOnMouseClicked(event -> {
Preferences preferences;
try {
preferences = getFromFile.getPreferencesFromFile(textField.getText());
var simulationStage = new SimulationStage(preferences);
simulationStage.setTitle("World Map");
} catch (IOException e) {
textField.setText("Wrong path");
}

});

layout.addRow(4, textField, button);
}
}
42 changes: 42 additions & 0 deletions src/main/java/org/example/gui/GuiElementBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.example.gui;

import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import org.example.map.options.IMapElement;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class GuiElementBox {
private final IMapElement mapElement;

public GuiElementBox(IMapElement mapElement) {
this.mapElement = mapElement;
}

public VBox getGuiVisualization() {
if (this.mapElement == null)
return new VBox();

Image image = null;
try {
image = new Image(new FileInputStream(this.mapElement.getSourceAddress()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ImageView imageView = new ImageView(image);
imageView.setFitWidth(30);
imageView.setFitHeight(30);

Label label = new Label(this.mapElement.toString());
VBox vBox = new VBox(imageView, label);
vBox.setAlignment(Pos.CENTER);

return vBox;
}
}


6 changes: 6 additions & 0 deletions src/main/java/org/example/gui/IEngineRefreshObserver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.example.gui;

public interface IEngineRefreshObserver {
// TODO can we delete this?
void refreshNeeded();
}
46 changes: 46 additions & 0 deletions src/main/java/org/example/gui/SimulationEngine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.example.gui;


import javafx.application.Platform;
import org.example.map.Statistics;
import org.example.map.WorldMap;
import org.example.map.objects.animal.AnimalStatistics;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class SimulationEngine extends Thread {
private final WorldMap map;
private final SimulationStage simulationStage;
private final List<Statistics> statistics = new ArrayList<>();
private final int dayCounter = 0;

public SimulationEngine(WorldMap map, SimulationStage simulationStage) {
this.map = map;
this.simulationStage = simulationStage;
}

private void day() {
Statistics currentStats = map.day();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nie jestem przekonany, czy realizacja wszystkich zadań dnia to odpowiedzialność modelu mapy, która powinna się zajmowac przede wszystkim przechowywaniem rzeczy i dbaniem o ich pozycje.

Optional<AnimalStatistics> animalStatistics = map.getTrackedAnimalStatistics();

Platform.runLater(() -> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a to można by połączyć akurat obserwatorem, podobnie jak na Lab8

simulationStage.displayMap();
simulationStage.displayStats(currentStats);
animalStatistics.ifPresent(simulationStage::displayAnimalStats);
});
}

@Override
public void run() {
while (true) {
day();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
return;
}
}
}
}
Loading