Termination of the run() method

1 view
Skip to first unread message

Karan Bhatia

unread,
Nov 24, 2010, 12:44:57 AM11/24/10
to cornell-cs2110
Hello,
 
I have a question regarding my run() method. Everytime I run it I get the same point total (-248806) and same amount of moves (210858). I scan the board and notice that all animals are gone and that my random variable (when called) actually spits out a random cell when I inserted a println statement to test that. My while statement looks to make sure that every node in the graph has been visited (by adding each new node to a treeSet and comparing to nodeCount). With that said, I notice that my run() method ends once all animals have been picked up, but NOT every node has been visited (319/920) every time. My program seems to run fine as the goal is seemingly accomplished, but I ask what exactly causes run to terminate? Does it know to exit the loop once all animals are picked up and in the ship? After getting the same results every time I start to think that something is weird. Also, I know score isn't a direct factor in the grade, but what general score range reflects good algorithms and code?
 
Thanks

--
Karan Bhatia
College of Engineering '13
Cornell University

Victor Janas

unread,
Nov 24, 2010, 12:52:15 AM11/24/10
to Cornell CS 2110
Win conditions are explicitly when every animal has been collected,
and have nothing to do with visiting nodes. And, assuming you use
random numbers in your code somewhere, your code will run the same way
each time if you have the same map and the same random seed (and if
you don't supply one I'm pretty sure this program gives the same
random seed). And if you aren't using random numbers, your code should
usually run exactly the same on the same map, barring weirdness.

Karan Bhatia

unread,
Nov 24, 2010, 1:04:22 AM11/24/10
to cornell...@googlegroups.com
I set up my code so that a node is only counted as "visited" if it has been visited and every animal on it has been delivered to the ship. So by visiting each node, I would guarantee that every animal has been picked up, and just try to gain some extra points for the nodes I may never have otherwise visited. However, I do not get the opportunity to visit every node because run figures out that every animal has been picked up.
 
Is that what should happen? The program knows when every animal has been dropped off right?
 
Or should the case for termination be altered? Because it seems that my trying to get every node visited is futile
 
Thanks

--
You received this message because you are subscribed to the Google Groups "Cornell CS 2110" group.
To post to this group, send email to cornell...@googlegroups.com.
To unsubscribe from this group, send email to cornell-cs211...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cornell-cs2110?hl=en.

Lonnie Princehouse

unread,
Nov 24, 2010, 1:17:37 AM11/24/10
to cornell...@googlegroups.com
getNodeCount() returns the total number of cells in the map, including water and trees.  You can't get to all of them with the naturalist, so if you're trying to use getNodeCount() as a termination condition it's not going to work.

That said, there are actually four cases in which the simulation ends:

1. TriumphException is thrown by dropAll() when the last animal is dropped at the ship.  The simulator catches this exception and ends the simulation. This is how the simulator is breaking out of your while loop.

2. Your run() method returns.

3. Your program throws an exception that is not TriumphException (NOT recommended)

4. The simulator decides you're taking too long and interrupts your thread. This isn't implemented in the a5.jar we distributed, but it will be for the competition. The time limit will be generous, 10 minutes or so in headless mode.


So if you want to keep on going after you drop the last animal, wrap dropAll() in a try-catch block and suppress the TriumphException.  Then you can finish exploring the map and return when you're finished.

Karan Bhatia

unread,
Nov 24, 2010, 1:30:28 AM11/24/10
to cornell...@googlegroups.com
Great, Thanks a lot for the help
Reply all
Reply to author
Forward
0 new messages