Deprecated: Assigning the return value of new by reference is deprecated in /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php on line 221

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php on line 230

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php on line 254

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php on line 263

Deprecated: Function split() is deprecated in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 456

Deprecated: Function split() is deprecated in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 456

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php:221) in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 314

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php:221) in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 315

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web110/html/Joomla/administrator/components/com_joomfish/classes/JoomfishManager.class.php:221) in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 316
A simple Ant-Simuation in Java

Art & Work

About



Deprecated: Function split() is deprecated in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 591

Deprecated: Function split() is deprecated in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 591

A Study on Artificial Intelligence

During the first Semester, the students on our course are given a simple graphic framework that displays a single ant on a little sand plane. They are then given the task of gradually adding functions to the program and intelligence to the ants. This way they get results quickly and are able to develop additional features into the program if they feel up to it. At the end of the Semester we were allowed to work in teams on a final version of the simulation. The best Version would be honoured with a certificate and a price of one cent :). I worked together with Clas Rurik, and we achieved first place. Click the pictures to enlarge.

An anthill with busy ants An antstreet forming
A beetle beeing attacked by serveral ants The ants win. They start bringing the carcass to their hill.

So this little toy showcases our first project at university. It is not really interactive. After starting it just sit back, zoom around the screen and watch the ants do their work. The focus of the work was to develop an artificial intelligence for the little buggers. The original framework was developed by Simone Huber and Michael Schoell, This framework has been heavily expanded by Keno März and Clas Rurik and will be used for further educational purposes in future courses. I will elaborate on some of the algorithms used here, but do not expect fancy stuff. This is simple code programmed by first-semester students.

Download & Manual

 To start the simulation do either one of the following:

  • Start the software directly using Java Webstart. Follow this link. Requires Java Webstart to be installed.
  • Download the jar file and execute it locally. Follow this link. Requires Java to be installed.
After starting, you are confronted with a profile selection screen. This dialog allows you to to select a scenario. Try "Standardkonfiguration" first and "Large Map" later. After selecting a profile, the simulation starts. Click and drag on the minimap in the bottom right corner to navigate the playfield. The vertical slider to the right controls the speed of the simulation, the horizontal slider at the bottom controls the zoom. The buttons in the bottom left allow you to start, pause and quit the simulation. That's all you can do really. We're talking first Semester here.

Features

Here is a little list of what the simulation can do (Only lists the most important features implemented by Clas and I):

  • Arbitrary playfield size
  • Scrollable and zoomable playfield featuring a Minimap 
  • Bucket System to manage ants and bugs.
  • Simple Ant Intelligence
  • Simple Eco System
  • Ants imigrating into the playfield if other folks die out
  • Bugs hunting the ants
  • Ants hunting bugs and prey
  • Name Generator. We like it close and personal.
  • Struggle between capitalistic and communistic ants on the default map. We like it nonsensical.

Bucketing: Managing many entities on a 2d playfield.

One problem we encountered was to manage the abundance of ants on the playfield. The ants as well as the bugs check for nearby entities depending on their radius of sight. Obviously it would be very unefficient to check each versus each ant for sight-contact if the sight radius is just a fraction of he actual playfield. See the flash graphic below for details.

 

Graph explaining the process of bucketing part 1

 

A naive implementation would be to simply place all ants in a List.  The Beetle (B) can see 4 ants (A) but has to iterate over the whole list, i.e. check for all ants on the playfield. For the Ants the situation is even more drastic: Each ant has to check every other ant for sight contact. This is equivalent to a complexity of n2 and obviously suboptimal. So how could we improve this process? As mentioned before, the typical radii of sight are significantly smaller than the actual size of the playfield. The requirements to the algorithm are as follows:

  • It should decrease the number of sight-checks to a number close to the actual ants in sight.
  • The Ants move quickly. The underlying data structure should not require extensive restructuring due to ants moving.

An easily implementable solution for this problem is the so called bucketing. First, we divide the playfield into equally sized squares - our buckets - and put each ant into the bucket corresponding to the square it stands on.

Graph explaining the process of bucketing part 2

 

B now first calculates the coordinates of the buckets that are touched or covered by field of vision. Then, he checks all ants in those buckets for sight contact. It is obvious that this method is more effective than the naive implementation. The actual reduction in complexity depends on the bucket size as well as the size of the playfield and the distribution of the ants.
Additionally, the simulation now has to keep track of ants changing buckets by walking. This operation is not terribly costly and can be furtherly reduced by making the calcuation fuzzy, for example recalculating the buckets only every fifth step. The parameters can also be tweaked according to the simulations needs. We made good results with choosing a bucket size equaling the ants' radius of sight.

 
XHTML and CSS