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

Added: Animal, AnimalTree, Genotype, GenotypeTests. #3

Merged
merged 2 commits into from
Dec 29, 2023

Conversation

Gabriela-Dumanska
Copy link
Collaborator

Things to change: make findMostCommonGenotype() dynamic, make AnimalTree more dynamic, check if AnimalTree class is even needed- maybe we could squish it into Animal class?, tests for Animal class. Work in progress...

… make findMostCommonGenotype() dynamic, tests for Animal class. Work in progress
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.

In the future, it would be better if you split your commits into smaller ones.

import agh.ics.oop.model.worldMaps.Globe;

public class Animal {
private final Globe globe;
Copy link
Owner

Choose a reason for hiding this comment

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

There is no reason to keep Globe in Animal.
You use it to:

  1. Get specific values in constructor - they can just be passed
  2. Check genotype length - you can pass it to Genotype as attribute or check the length of parent's genotype

public Genotype(Animal mother, Animal father) {
validateParents(mother, father);

int divisionPoint = (int) (((double) mother.getEnergy() / (father.getEnergy() + mother.getEnergy())) * mother.getGenotype().genes.size());
Copy link
Owner

Choose a reason for hiding this comment

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

You access genotype length twice in this constructor. Imo it would be better to either add an attribute for it or create a local variable to make code more readable.

private static final Random random = new Random();

public static int getRandomInt(int bound) {
return random.nextInt(bound);
Copy link
Owner

Choose a reason for hiding this comment

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

This method is exclusive but it's overload with 2 variables is inclusive. It will lead to confusion and mistakes in the future.

}
}

public void switchGenes(int firstGeneIndex, int secondGeneIndex) {
Copy link
Owner

Choose a reason for hiding this comment

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

You can use Collections.swap() to do this.

return genotypeToString.toString();
}

public Integer getCurrentGene(int currentGeneIndex) {
Copy link
Owner

Choose a reason for hiding this comment

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

In this case it is better to use int instead of Integer.

@@ -21,7 +21,9 @@ public class Globe {
private final int energyUsedToReproduce;
private final int minNumberOfMutations;
private final int maxNumberOfMutations;
private final int genomeLength;
private final int genotypeLength;
private final Map<Genotype, Integer> genotypeCount = new HashMap<>();
Copy link
Owner

Choose a reason for hiding this comment

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

You are using a map but there is neither equals nor hash in Genotype

Vector2d position = animal.getPosition();
List<Animal> animalsAtThisPosition = animals.get(position);

if (animalsAtThisPosition != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

I would replace it with try catch because we expect that position in animal is kept correctly.

private void removeGenotype(Animal animal) {
Genotype animalGenotype = animal.getGenotype();

genotypeCount.put(animalGenotype, genotypeCount.getOrDefault(animalGenotype, 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.

Same as above we expect that genotypes are also tracked correctly so no need for getOrDefault().

genotypeCount.remove(animalGenotype);
}
}
public Genotype findMostCommonGenotype() { //niedynamiczne- do poprawy
Copy link
Owner

Choose a reason for hiding this comment

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

To me it sounds like heap.

return children.size();
}

public int getDescendantsCount() {
Copy link
Owner

Choose a reason for hiding this comment

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

My idea is that once you choose a specific animal, you get all of its children and add an observer to them that updates out count whenever a new animal is born (from an observed animal).

Not sure if it is the correct solution.

@Gabriela-Dumanska Gabriela-Dumanska merged commit 421add6 into main Dec 29, 2023
@karmatys8 karmatys8 deleted the animal branch December 30, 2023 15:17
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