-
Notifications
You must be signed in to change notification settings - Fork 1
Code Review #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Soamid
wants to merge
28
commits into
review
Choose a base branch
from
master
base: review
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code Review #3
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 d67c431
Merge pull request #1 from jkbstepien/development
jkbstepien d25f1f2
Added: class structure + builder for WorldMap.
jkbstepien 26750f6
Merge pull request #2 from jkbstepien/development
jkbstepien faddf6b
implemented Genes + started implementing WorldMap
MagrosThornrime 728c58f
Added: reading from resources/conf1.json file and basic gui.
jkbstepien 29cf3fa
...
MagrosThornrime 3529499
Merge branch 'mateusz'
jkbstepien 8ce47b6
Added: WorldMap functionality (animal and plants).
jkbstepien 1dbf647
Added: WorldMap functionality (animal and plants) v2.
jkbstepien dfea564
small fix
MagrosThornrime 06d8246
a beautiful mess
MagrosThornrime 3a521d7
small fix
MagrosThornrime 7736b1a
new version
MagrosThornrime 57bad61
Added: SimulationEngine and SimulationStage.
jkbstepien f154f9e
Now Animals die during the simulation + fixed PlantsEquator
MagrosThornrime b0fafc1
Added: Read preferences from user.
jkbstepien 91dd00a
Added: Statistics logic and rendering.
jkbstepien 105c129
Added: Saving Statistics to csv file.
jkbstepien fc07b30
Added: most popular genotype is now visible in GUI.
jkbstepien 728a58c
Fixed GeneChoice to reset after using all genes
jkbstepien 8b6d3ab
Fixed correct display of animals with most popular genotypes.
jkbstepien 2771c7d
Added: view of Animal details after selecting it.
jkbstepien c308b25
Added: code cleanup.
jkbstepien a515495
Added: more tracking stats (born day, age, children).
jkbstepien 4e4d621
IPlants rework + cleaned up the codebase
MagrosThornrime 664df48
removed binaries and workspace files
MagrosThornrime 5a4a5f9
cleanup
jkbstepien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /.gradle/ | ||
| /.idea/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+171 Bytes
build/classes/java/main/org/example/gui/IEngineRefreshObserver.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 added
BIN
+2.58 KB
build/classes/java/main/org/example/map/objects/animal/AnimalStatistics.class
Binary file not shown.
Binary file added
BIN
+326 Bytes
build/classes/java/main/org/example/map/objects/animal/IAnimalObserver.class
Binary file not shown.
Binary file added
BIN
+739 Bytes
build/classes/java/main/org/example/map/objects/animal/behavior/AnimalBehaviorCrazy.class
Binary file not shown.
Binary file added
BIN
+586 Bytes
...sses/java/main/org/example/map/objects/animal/behavior/AnimalBehaviorPredestination.class
Binary file not shown.
Binary file added
BIN
+183 Bytes
build/classes/java/main/org/example/map/objects/animal/behavior/IAnimalBehavior.class
Binary file not shown.
Binary file added
BIN
+1.21 KB
build/classes/java/main/org/example/map/objects/animal/genes/GeneChoice.class
Binary file not shown.
Binary file added
BIN
+5.61 KB
build/classes/java/main/org/example/map/objects/animal/genes/Genes.class
Binary file not shown.
Binary file added
BIN
+2.05 KB
build/classes/java/main/org/example/map/objects/animal/genes/GenesFactory.class
Binary file not shown.
Binary file added
BIN
+1.29 KB
build/classes/java/main/org/example/map/objects/animal/genes/GenesFullRandom.class
Binary file not shown.
Binary file added
BIN
+1.39 KB
build/classes/java/main/org/example/map/objects/animal/genes/GenesSlightCorrection.class
Binary file not shown.
Binary file added
BIN
+429 Bytes
build/classes/java/main/org/example/map/objects/plants/CannotPlacePlantException.class
Binary file not shown.
Binary file added
BIN
+227 Bytes
build/classes/java/main/org/example/map/objects/plants/IPlantObserver.class
Binary file not shown.
Binary file added
BIN
+260 Bytes
build/classes/java/main/org/example/map/objects/plants/IPlants.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.63 KB
build/classes/java/main/org/example/map/objects/plants/PlantsEquator.class
Binary file not shown.
Binary file added
BIN
+5.53 KB
build/classes/java/main/org/example/map/objects/plants/PlantsToxicCorpses.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| Optional<AnimalStatistics> animalStatistics = map.getTrackedAnimalStatistics(); | ||
|
|
||
| Platform.runLater(() -> { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.