Tags

, , , , , , ,

Berkeley CS61B Project 1: Sharks and Fish (Sharks are red dots, fish are green dots)

Course: Berkeley’s CS 61B: Data Structures.

Project 1: Sharks and Fish

Project 1 (mirror) is due before lecture 14.

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!

Entire project: gotfu_pj1.zip

Individual .java files:

Creature.java (view | download)
Ocean.java (view | download)
RunLengthEncoding.java (view | download)
RunLengthNode.java (view | download)

In my solution I’ve done a few things not specifically required by the assignment.

The entire 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 Creature: creature.equals(OtherCreature);. My 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.

Test Code

Coordinate folding for looping game board.

Java’s remainder operator is sometimes naughty… see source.

MyTestfold.java (view | download)

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.

Test Ocean, Creature behaviours.

MyTest.java (view | download)
see sample output: MyTest.Output.txt

Test RunLengthEncoding(Ocean ocean) constructor and toOcean() method.

MyTest2.java (view | download)
see sample output: MyTest2.Output.txt

Test RunLengthEncoding methods: addShark, addFish

Comparing this output, with the output of Test.class, my code appears to match the expected behavior, and yet still fails the test.

MyTest3.java (view | download)
see sample output: MyTest3.Output.txt

Enjoy!

Advertisements