Course: Berkeley’s CS 61B: Data Structures.
Project 1: Sharks and Fish
For project 1 you get to implement a simulation of an ocean containing sharks and fish. You will get practice in the use of two dimensional arrays and linked lists.
Unlike the homework assignments, the ‘projects’ are time consuming.
The project comes with two tests; one in
Testalike.java and the other in
Test.class, the later of which is compiled and gives a more detailed report.
My implementation fails the last test in
Test.class (the 13th score point) … and no matter how much I’ve looked at my code I can’t find the reason for that. In my own tests (MyTest3.java) it does behave how I would expect it to (doing what Test.class says it tries to do..).
So, I’m stuck with a ’12 out of 13′ score.
If you happen to figure out what’s amiss with my code please let me know!
Individual .java files:
In my solution I’ve done a few things not specifically required by the assignment.
Creature class could be done away with if its functionality was embedded in the
Ocean class. The
RunLengthNode class could probably have been embedded in
RunLengthEncoding, but I thought that would be ugly. My
Creatures can compare themselves with another
Ocean has a
toString() method. The
compact() method in
RunLengthEncoding and other little details…
But somehow somewhere I’ve missed something… I think it might be in
addCreature() but I can’t ‘see’ it, and since the
Test.class sources are not available (obviously! cause they’d give away the assignment…) I cannot figure out what.
Coordinate folding for looping game board.
Java’s remainder operator is sometimes naughty… see source.
All my tests use ‘.’ for blank tiles and the hunger var instead of ‘S’ for sharks when printing the oceans. That’s only an aesthetics change.
RunLengthEncoding(Ocean ocean) constructor and
Comparing this output, with the output of Test.class, my code appears to match the expected behavior, and yet still fails the test.