Skip to content
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

Animal highlights #21

Merged
merged 12 commits into from
Jan 21, 2024
Merged

Animal highlights #21

merged 12 commits into from
Jan 21, 2024

Conversation

Gabriela-Dumanska
Copy link
Collaborator

No description provided.

Base automatically changed from GUI-simulation to main January 21, 2024 09:45
Copy link
Owner

@karmatys8 karmatys8 left a comment

Choose a reason for hiding this comment

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

  • If our picked animal is on a certain field but isn't the strongest(shown one), then the field is not highlighted.

It would look much better if regardless of its strength it would always show up.

We can also achieve this by making a selected Animal a priority to show on Map regardless of the fact that there are stronger animals on the same field.
However I believe it to be somewhat of a less desirable approach.

  • Another thing that I found out that if you close a simulation window but still have animals stats open simulation still runs in the background.

It should be an easy fix.

Copy link
Owner

@karmatys8 karmatys8 left a comment

Choose a reason for hiding this comment

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

There are a few optimizations possible but code looks good.

@@ -37,9 +38,9 @@ public class MapDrawer {
private boolean isAlertShown = false;
private Animal observedAnimal;
Label[] animalStats = new Label[7];
Label[] simulationStats;
Node[] simulationStats;
Copy link
Owner

Choose a reason for hiding this comment

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

On main in CSVWriter I am using the fact that simulationStats are Labels.
I can always cast Nodes to Labels, but I want you to know that we have somewhat of a merge conflict.

Comment on lines +188 to +193
for (Animal animal : aliveAnimals) {
if(animal.getGenotype().getGenes().equals(mostCommonGenotype.getGenes())){
Vector2d position = animal.getPosition();
printCell(position.x(), position.y(), "#F3B153");
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

You might have not intended it to be so but I believe that the more animals with said Genotype are on one file the more highlighted it is.
It actually is quite a nice feature.

return childrenComparison;
}

return Math.random() < 0.5 ? -1 : 1;
Copy link
Owner

Choose a reason for hiding this comment

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

Using random.nextBoolean() is slightly more readable.

@@ -100,11 +102,14 @@ private void moveAnimals() {

private void feedAndReproduceAnimals() {
for (Vector2d position : animalsMap.keySet()) {
List<Animal> currAnimals = animalsMap.get(position);

Collections.sort(currAnimals, new AnimalComparator());
Copy link
Owner

Choose a reason for hiding this comment

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

We do not need to initialize new AnimalComparator Object every time.

@@ -30,6 +31,7 @@ public Pair<Vector2d, Integer> howToMove(Vector2d oldPosition, MapDirection dire
public Pair<Node, Optional<Animal>> nodeAt(Vector2d position) {
List<Animal> animalsAtThisPosition = animalsMap.get(position);
if (animalsAtThisPosition != null) {
Collections.sort(animalsAtThisPosition, new AnimalComparator());
Copy link
Owner

Choose a reason for hiding this comment

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

We do not need to initialize new AnimalComparator Object every time.

@@ -53,6 +51,7 @@ public Pair<Vector2d, Integer> howToMove(Vector2d oldPosition, MapDirection dire
public Pair<Node, Optional<Animal>> nodeAt(Vector2d position) {
List<Animal> animalsAtThisPosition = animalsMap.get(position);
if (animalsAtThisPosition != null) {
Collections.sort(animalsAtThisPosition, new AnimalComparator());
Copy link
Owner

Choose a reason for hiding this comment

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

We do not need to initialize new AnimalComparator Object every time.

Copy link
Owner

Choose a reason for hiding this comment

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

Since we need AnimalComparator for both Globe and Tunnels we can initialize it in AbstractWorldMap.

@@ -25,7 +25,7 @@
</VBox.margin>
</Label>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: #B0DA90;">
<Button fx:id="saveConfigs" alignment="CENTER" styleClass="config-button-sm" text="Save configurations">
<Button fx:id="saveConfigs" alignment="CENTER" styleClass="config-button-sm" text="Save configurations " >
Copy link
Owner

Choose a reason for hiding this comment

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

text="Save configurations "

text="Save configurations"

@karmatys8 karmatys8 merged commit bc7c530 into main Jan 21, 2024
@karmatys8 karmatys8 deleted the animal-highlights branch January 21, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants