#Collision of fish in a fish tank leads to them disappearing

1 messages · Page 1 of 1 (latest)

silent plinth
#

This is a Fish Tank, where certain variants of fish can "swim" in. They move horizontally and vertically (the vertical movement is random). But one aspect is not covered yet. When two fish collide one fish just disappears and never gets shown again. I would like to cover this case in the moveFish method or in a separate method, where the larger fish covers up the smaller one until they have different positions again.

pine sailBOT
#

<@&987246399047479336> please have a look, thanks.

#

Great! Please provide the code that you would like assistance with, and I'll do my best to help you.

silent plinth
#

Collision of fish in a fish tank leads to them disappearing

velvet breach
#

That's because each space can only contain one fish. If you change that to an array of fish (or in your case, a 3D array as you already have a 2D array, or a 2D array of List<Fish>), then you can store multiple fish for the same indices

silent plinth
#

Is there any way to keep it a 2D Array and just set one fish tempory to null and then print it again, when they again have different positions?

brave elm
#

You could use a temp list for that, but that seems more cumbersome.

silent plinth
#

i fixed it like this, but theres just one "error" left. When they collide, for 1 output only the small fish gets shown, but it should be the larger one. HEres an example:| |
| ><><()><
|
|
+--------------------+

|
| ><>
|
|
+--------------------+

|
| <()><
|
|
+--------------------+

|
| <()><
|
|
+--------------------+

|
|<()><><>
|
|
+--------------------+

|
|><()> ><>
|
|
+--------------------+

pine sailBOT
silent plinth
#

(Fix inside the moveFIsh() method)

tranquil saffron
silent plinth
tranquil saffron
#

Im not judging you in the basis

#

I like “nice”

#

Damn u misunderstood me🤧🥲