Category Image Fun with an ants simulation in Squeak


 


Remember the joy you experienced the first time you started to "get it" programming Smalltalk?  It's easy to become jaded after years of design, implementation and deployment.  All you need for a refreshing perspective is to spend some time mentoring someone who is new to Smalltalk. We did a little Smalltalk work together and had a discussion about how it's easy to think of biological systems when working with a good object design. That reminded me of an article...

I read yet another article talking about Java or some other variant of this year's Hoola Hoop and it just frustrated me.  Here's an example.

JavaAntz - A Boid Ant Simulator

When I saw this I immediately remembered the Ant Simulation referenced at Star Squeak. This was available in Squeak 3.1, in 2004.

That's enough background, back to the discussion about the joys of working with Smalltalk...

Recently, one of the team partners I occasionally work with completed a Smalltalk training class.  When he returned from his week-long training he was full of enthusiasm about the world of programming available to him with his newly emerging Smalltalk skills.  It was nice to experience.  We started chatting about fun things he could try.  He has a lot of enthusiasm for a wide range of topics, and just like I have often done, having aquired a new kind of "hammer" he sees "nails" he can go after in almost everything.  So we brainstormed about interesting programming ideas he could try using his new Smalltalk skills.  Listening, I was reminded that I've gained the perspective of years of experience and knowing what kinds of tasks are easied to reach than others.  To a certain extent I reminded myself to be careful not to dowse fresh ideas with too much realism.  After all, fresh ideas are always welcome.
 
When he mentioned a keen interest in simulating things, like maybe an any colony, I was reminded of two things.  There was an article in Wired on-line in the past month about an ant simulation written in Java.  I saw that simulation and was unimpressed.  In fact I thought the one I'd seen in Squeak many years ago was much more interesting.  So I went looking and dug up the Squeak ants simulation and fired it up as a demo and discussion point.

And we started to explore how making trivial changes to this code you could experiment with the ideas. Just like it was always planned back when Smalltalk was created.

While he wants to work on the underlying simulation model, which is a really fun project, I realized that there were some improvements that could be made to the basic UI. So I have attached here a change set which will work fine with Squeak 3.9 (and 3.7) that produces the following new morph:



It also includes some enhancements to the base simulation, as a sub-class. The work was broken into 2 areas of attention.

1. A new model subclass which has random nest and random food counts.  It stops when all the food is picked up.  Color of background is softer. At this point the model still behaves like a GUI since it contains presentation information.

2. A new visual morph to conveniently hold start/stop, reset buttons, visual counters for ants, food and steps, and a tool button for a future inspection pane.

Just file it in to try it and then open up a new Morph called AntColonySimulation.

ants.7.cs ChangeSet

Posted: Sunday - August 06, 2006 at 06:12 PM           |


©