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

Map visualizer #7

Merged
merged 7 commits into from
Jan 6, 2024
Merged

Map visualizer #7

merged 7 commits into from
Jan 6, 2024

Conversation

Gabriela-Dumanska
Copy link
Collaborator

No description provided.

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.

Make sure to copy and paste GenotypeTests from main branch.


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

this.minNumberOfMutations=mother.getGenotype().minNumberOfMutations;
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 method we are calling mother.getGenotype() 5 times. It is better to make a local variable motherGenotype.


private String drawObject(Vector2d currentPosition) {
Object object = this.globe.objectAt(currentPosition);
if (object instanceof List<?>) {
Copy link
Owner

Choose a reason for hiding this comment

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

List<Animal>
We don't except any other lists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

'Object' cannot be safely cast to 'List'

Copy link
Owner

Choose a reason for hiding this comment

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

We probably should ask our teacher about it because Idzik said that using instanceof shows that code is structured incorrectly.

if (object instanceof List<?>) {
StringBuilder result = new StringBuilder();
for (Object item : (List<?>) object) {
result.append(((Animal) item).toShortString()); //many animals in the same position will cause problems with display
Copy link
Owner

Choose a reason for hiding this comment

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

We can append only first one for now. Either way we have to add class that resolves priority.

@@ -36,7 +42,7 @@ public Globe(int width, int height, PlantConfig plantConfig, AnimalConfig animal


for (int i = 0; i < animalConfig.startingCount(); i++) {
place(new Animal());
place(new Animal(new Vector2d(RandomInteger.getRandomInt(width), RandomInteger.getRandomInt(height)), animalConfig));
Copy link
Owner

Choose a reason for hiding this comment

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

(RandomInteger.getRandomInt(width), RandomInteger.getRandomInt(height))

(RandomInteger.getRandomInt(width) + 1, RandomInteger.getRandomInt(height) + 1)

Copy link
Owner

Choose a reason for hiding this comment

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

There are less tests than on the main branch.
Just copy and paste file from main instead of this.

@@ -27,7 +27,7 @@ public void testGlobe() {
public void testCanMoveTo() {
Globe globe = new Globe(36, 200, new PlantConfig(0, 22, 51),
new AnimalConfig(8, 9, 93, 0, 0, 0, 2));

//System.out.println(globe);
Copy link
Owner

Choose a reason for hiding this comment

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

You forgot to clean tests.

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.

Only thing left to correct is in Globe.


private String drawObject(Vector2d currentPosition) {
Object object = this.globe.objectAt(currentPosition);
if (object instanceof List<?>) {
Copy link
Owner

Choose a reason for hiding this comment

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

We probably should ask our teacher about it because Idzik said that using instanceof shows that code is structured incorrectly.

@@ -42,7 +42,7 @@ public Globe(int width, int height, PlantConfig plantConfig, AnimalConfig animal


for (int i = 0; i < animalConfig.startingCount(); i++) {
place(new Animal(new Vector2d(RandomInteger.getRandomInt(width), RandomInteger.getRandomInt(height)), animalConfig));
place(new Animal(new Vector2d(RandomInteger.getRandomInt(width)+1, RandomInteger.getRandomInt(height)+1), animalConfig));
Copy link
Owner

Choose a reason for hiding this comment

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

getRandomInt() is inclusive so now the value is from (1, width + 1) you should change it to:
place(new Animal(new Vector2d(RandomInteger.getRandomInt(1, width), RandomInteger.getRandomInt(1, height)), animalConfig));

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.

After u fix the last mistake you can merge it.

Comment on lines 32 to 35
Assertions.assertTrue(globe.canMoveTo(new Vector2d(0, 0)));
Assertions.assertTrue(globe.canMoveTo(new Vector2d(0, 199)));
Assertions.assertFalse(globe.canMoveTo(new Vector2d(0, 0)));
Assertions.assertFalse(globe.canMoveTo(new Vector2d(0, 199)));
Assertions.assertTrue(globe.canMoveTo(new Vector2d(35, 199)));
Assertions.assertTrue(globe.canMoveTo(new Vector2d(35, 0)));
Assertions.assertFalse(globe.canMoveTo(new Vector2d(35, 0)));
Copy link
Owner

Choose a reason for hiding this comment

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

Those tests are meant to test each corner so correct code would be:

Assertions.assertTrue(globe.canMoveTo(new Vector2d(1, 1)));
Assertions.assertTrue(globe.canMoveTo(new Vector2d(1, 200)));
Assertions.assertTrue(globe.canMoveTo(new Vector2d(36, 200)));
Assertions.assertTrue(globe.canMoveTo(new Vector2d(36, 1)));

@karmatys8 karmatys8 merged commit 3e45f61 into main Jan 6, 2024
@karmatys8 karmatys8 deleted the map-visualizer branch January 6, 2024 18:36
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