[General boards] [Winter 2019 courses] [Fall 2018 courses] [Summer 2018 courses] [Older or newer terms]

When fish should eat seaweed


#1

The length of seaweed will decrease when:
A. fish exists in cells that contains part of seaweed
B. fish is going to move in cells that contains part of seaweed


#2

A is the correct interpretation, though in practice I guess both achieve the same thing


#3

@t6charti I am seeing the following general issue with implementing the logic in Seaweed.

Suppose the seaweed is at (10,10). And there is a fish at (11,9) about to move left.

Tick 1: The seaweed is processed first in FishTank.main(). There is no fish in the Seaweed path, so it’s not cut. The fish is processed second and moves to (10,9).
Tick 2: Now, the fish is processed first in FishTank.main() and, suppose, moves again left to (9,9). The seaweed is processed second, and there is again no fish in its path. The seaweed is never cut.

Does it mean that the logic has to be inside Fish? Or can we just ignore this issue assuming it is caused by the buggy FishTank.main() implementation which we are not required to fix?


#4

Writing the “main loop” consistently is actually really hard, it needs to consistently update entire classes of entities in some well defined ordering to work correctly – we didn’t want to confuse people with this, so it’s just a double for loop

You can see how we’ll actually test this stuff in the provided tests – namely, just calling update() in the two permutations and making sure one of the two passes (fish first, seaweed first) or (seaweed first, fish first), so as long as it works in some case, you don’t need to worry about the weird race conditions in the main method