Archive for January, 2008


January 20, 2008

If my hierarchies weren’t clear from my first post, here they are, more explicitly defined: 

Animate object hierarchy:

Base: Organism

SubClasses: Predator and Prey

Inanimate Object Hierarchy:

Base Class: Energy

Subclasses: Heat and Nutrients

Location Hierarchy:

Base Class: Topological Map

Subclasses:  Peaks and Valleys

Action Hierarchy:

Base Class: Action

Subclasses:  Reproduction, Searching, Feeding, Hunting, Trading

Assignment 2

January 20, 2008

1.  The standard OOP inheritance pattern is simple and effective but somewhat inflexible.  With many classes and frequent anticipated changes a pattern like the stategy pattern becomes more appealing.   Having to possibly override an inherited method for every new class added to a project would be extremely inefficient,  so the Strategy pattern adds flexibility at the cost of added complexity.   In Joe’s case, every modification to the base class affected every class, so he needed to make multiple changes for every new request.  His idea of using an interface would have been even more inefficient, because in Java interfaces do no allow for code reuse.

This is why the strategy pattern encapsulates the parts of the program that change.  In this way, code reuse and unintentional changes to other parts of the program are avoided.

2.   To use the strategy pattern, take the methods from the base class that frequently need to be changed and put them in their own classes.  These can be abstract classes or interfaces.  Then create subclasses that implement these interfaces.  The subclasses represent different ways of implementing the behavior of the interface.  In my own project, the SearchBehavior interface is implemented in two different ways by predator and prey – SearchNutrients looks for inanimate food, while SearchPrey hunts animate prey. 

In the base class, delegate the aforementioned behaviors to their respective interfaces.  Next put setter methods in to allow easy access to the interfaces.  Now any new object should be able to use the appropriate behavior by invoking its inherited setter method.

Experiences with Eclipse

January 11, 2008

I’ve been playing around with eclipse and have actually found its features to be quite helpful.   I haven’t programmed much in it yet but I’m slowly figuring out how to take advantage of all of them.  I wish I’d used this last term instead of textpad.

Assignment Description

January 9, 2008

I’m interested in evolutionary computing and artificial life, so I plan to do a project that applies natural selection to reproducing, mutating organisms. Simply making abstract “organisms” that evolve would be relatively easy (?) if the mutation were a small randomization of the parameters passed on to offspring. The goal of this project would be for true evolution to occur, and I would consider proof of true evolution to be some kind of unpredictable adaptation made by the organisms. A predictable adaptation would be for an organism whose speed parameter was randomly increased to be better adapted to catching prey – I could simply have programmed it that way at the beginning. An unpredictable adaptation would be for a prey organism to suddenly develop the ability to kill other prey organisms and become a predator. I suppose speciation of any other kind would also qualify.

So I imagine the animate objects to be predator and prey organisms. Since I hope for them to evolve, it doesn’t really make sense to give them names beyond that. They would be able to sense one another through proximity, which would represent the sense of smell or hearing.

Since genetic isolation is a prerequisite for speciation I should create some sort of hazard or barrier. I think a random heat pattern spread over the map would work well. The organisms could have heat tolerance among their parameters. So “heat” would be the first inanimate object. The second would be food. It could be interesting to make the predators cold-tolerant and the prey heat-tolerant, but put the prey’s food source in the cold regions.

Now to make the terrain interesting I would go 3-D and allow peaks and valleys. I could represent height the way maps do with color coding. So “peaks” and “valleys” are my places.

And as for actions … the prey would eat. I would like for them to be able to store and even trade excess food for heat or cold. I can imagine a hot region of the map full of bustling, starving prey organisms, with a few, cold-resistant yet heat-vulnerable specialists burning in the heat and periodically darting out to retrieve food and returning to trade food for cold, which would entail the starving organism allowing the burning organism to drain its excess heat on to it.  Reproduction would be asexual for simplicity.   Another action would be killing, as the predators would have to have a method to kill the prey.  This could either be done by simple proximity or using simulated physics that required some kind of impact determined by speed, mass, and surface area.  The latter would be much more difficult but allow for much greater flexibility of adaptation.