-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.
Make sure to copy and paste GenotypeTests from main branch.
|
||
public Genotype(Animal mother, Animal father) { | ||
validateParents(mother, father); | ||
|
||
this.minNumberOfMutations=mother.getGenotype().minNumberOfMutations; |
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.
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<?>) { |
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.
List<Animal>
We don't except any other lists.
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.
'Object' cannot be safely cast to 'List'
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.
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 |
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.
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)); |
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.
(RandomInteger.getRandomInt(width), RandomInteger.getRandomInt(height))
(RandomInteger.getRandomInt(width) + 1, RandomInteger.getRandomInt(height) + 1)
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.
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); |
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.
You forgot to clean tests.
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.
Only thing left to correct is in Globe.
|
||
private String drawObject(Vector2d currentPosition) { | ||
Object object = this.globe.objectAt(currentPosition); | ||
if (object instanceof List<?>) { |
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.
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)); |
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.
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));
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.
After u fix the last mistake you can merge it.
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))); |
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.
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)));
No description provided.