The central idea of OOP is message passing. To develop an appreciation for computing with objects, we'll make objects mobile in this assignment. Mobile objects are also called "mobile agents". Since objects are autonomous, each object maintains its own thread of execution. So multithreading is an essential requirement. In an open environment, you might run into unknown objects. How do you find information about these objects? And finally, when a mobile object transports itself to another location, how does it package itself -- keeping its state intact?
The features neeed for this project - mobility, multithreading, runtime object identification, and object packaging -- are known in Java as RMI (remote method invocation), threads, reflection, and serialization.
You have to hunt for a Treasure object which can be in one of five sites. Each of the five sites has some distinctive characteristics. During the search, you should also learn something about the characteristics of these sites. If you find the Treasure object, you extract its secret message. That's your reward. What you do in case you do not find the treasure is discussed below.
Each of the five sites is managed by its Site Manager. The Site Manager keeps a pool of objects. This pool is populated by objects of type: Snake, Unicorn, Frog, and Flower. These objects are not mobile.
There is one Treasure object which is mobile. It visits one of these sites, stays in the object pool for a while, and then leaves for another site. The Treasure object can also decide to vanish altogether.
And finally a Player object. This is the object which searches for the Treasure object. It visits each site, interacts with the object pool through the Site Manager at that site. If it interacts with the Treasure object, the search is over; it extracts the secret message. Otherwise, it should request more interactions or visit another site. The Player starts with a limited amount of time (hops) and cash.
There is exactly one Player object and one Treasure object.
What does "interaction" mean? The player chooses an index into the pool, sends it to the Site Manager and asks the Site Manager for the corresponding object. The Site Manager returns the object. If the Player gets a Snake, it loses a hop. If it gets an Unicorn, it gains a hop. If it gets a Frog, it loses 10 units of money. If it gets a Flower, it gains 10 units of money. There is a fee for staying at a site: the site manager charges 5 units of money for each interaction. (This applies only to the Player, not to the Treasure object.)
Can the Player find the Treasure object without running out of running (hop count) and cash?
The sites are known by their names: "Site0", ... "Site4". The site manager of each site contains an array (pool) of objects. The size of this array is available in a config file. This array is initialized with objects of type: Flower, Frog, Unicorn, and Snake. Each site has a different distribution of these objects. For example, Site0 might be infested with Snakes. This distribution is given by probabilitites. (In this example, in Site0 the probability of finding a Snake is 0.8.) The probabilities for each site are available in the config file.
If the Treasure object visits the site, the site manager puts it into a random position in the array. When the Treasure object leaves the site, the site manager removes it from the array.
Player's starting site is: "Site0". The Player chooses an index into the array and send it to the site manager. The site manager returns the object at that index position. Depending on the type of object returned, the player updates its state (cash and hops).
The Player can decide to leave at any time; it chooses one of the other sites and goes there. A good player has a strategy. For example, a good Player avoids sites having lots of Snakes and/or Frogs. The Player learns from experience where to stay and where to go in case of cash shortage. You need not do this. But you should keep track of the characteristics of each site: the approximate probability of finding a Snake, Unicorn, etc.
Note the Player is responsbile for reducing and increasing the cash and hops in hand based on the interactions. (There is a possibility of the Player cheating. To avoid this, one should to work with electronic cash which in turn needs Java Cryptographic Extension. We'll not be doing this in this project. You should write an honest Player.)
If the Player runs out of cash or hops, it should return to "Site0" and print the information it learned about the environment: the approximate probabilities of finding Snake, etc. in each of the sites and the hops and cash left. If it finds the Treasure object, it should again return to "Site0", print the message the Treasure object contains, and also other information like hops and site information.
The class of the treasure object is Treasure. This class
contains exactly one public method of zero arguments
which returns a string. You should not
assume anything about the name of this method.
You should discover this method using Reflection.
Using this method you should extract the string.
You should use Java for this assignment. Here's what you write.
Site.java (code provided below).
The Player and the Treasure object use RMI to hop among sites.
You should keep all your Java sources and a Makefile
(which compiles your code) in a
tar file called object.tar and use bundleP3 to
submit the tar file.
This assignment involves lot of ideas: objects, threads, reflection, RMI, etc. You should carefully evaluate each of these features in terms of need, complexity, and the abstraction provided by Java.
You should also write about the complexity of doing this in C++. You should comment on: feasibility of doing this in C++, extra libraries required like networking, remote procedure calls, language support required, etc.
What class of real world problems are similar to the one in this assignment? How are the other frameworks like procedural and functional programming suitable for solving this class of problems? What the advantages of OOP features: abstraction, message passing, inheritance, reflection, etc.
Do you think the need for runtime support will increase in the future?
There are multiple theads running in this example. You should write about the shared resources and how your design ensures the consistency of shared resources and avoids deadlocks.
The minimum length of your report should be five pages.
This project is due: Feb 25, 2000. You should submit the report, hardcopy of your code, and the self-evaluation form to Renata Teixeira on Feb 25, 2000 during her office hours. Your report should contain the name of the account from which the code was turned in.
Some useful code and pointers can be found here