CSIS 441: Artificial Intelligence Blog

Daniel Russell's Ant Colony Project

Posted: March 29 2013

This semester I'll be completing a final project for CSIS441, and I've also decided to extend it across CSIS330 (Data Structures & Algorithms). 330's final project required an app written to work in Android. Therefore, I will attempt to combine both AI concepts and those taught in Data Structures & Algorithms as well as having the final product intuitive to use on an Android-powered touchscreen device.

My general idea is that I will have ant colonies which will try to collect resources using pathfinding, and will have to make decisions based on locations, value, enemies etc (different ants would be able to communicate the information to each other about resources). In the final version, the user would be able to place down the anthills and resources throughout the terrain before starting the simulation. If a member of an opposing colony were to see another, they could decide whether to fight or flight.

After doing some research, it appears a similar project was carried out by Google 2 years ago with its annual AI Challenge (which can be found here: http://aichallenge.org/). This had competitors upload their search algorithms to the server and everyone would watch their colonies battle it out. This was using a rather simple interface however, whereas I would like to create a somewhat detailed world for these ants to navigate through. I think having to worry about all 3 dimensions of movement will be a challenge.

When prototyping the search, I will most likely practice using Google's challenge before moving into the final product. I will be using the Unity Engine to do this. It's a recently popular game development engine which started out very small but is soon to be on par with other very well known professional engines like Unreal. There's a lot of visual manipulation that goes on within the "scene" window itself but how everything behaves is controlled by scripting, which in my case will be written in C#. I don't know C# very well at the time but it seems similar enough to Java to adapt quickly.

So far I've been getting to know the Unity Engine and trying to create the terrain the ants will move about on. I've used the 3D Modeling software Blender to create a desert like area (giant scale sandbox). Yes, I know ants very rarely find themselves making colonies in a sandbox, but I like the aesthetic, haha. I haven't gotten too far because of being busy with other things (mostly NXT robot project), but here's a quick snap of the workspace:


Posted: April 5 2013

My strategy this week was to get the visuals looking good. That way I have an appropriate environment set up for me to properly test any code I write. So, I spent a large part of today and last night putting together that environment.


There it is, doesn't it look great? Well unfortunately I have to scrap most of it because when I exported to Android it looked like mud. I approached this thinking that any platform would present the same exact scene, but I was obviously wrong. It is not just Unity's fault however, because I was not using default terrain texturing. I had found a special shader script that gives the sand some great bump mapping.

One thing that is a problem though is the 3D model I imported from Blender. There's nothing special about it; just 4 rectangles (it's the border to the sandbox). But weirdly enough when on Android, there's tons of jagged and wiggly edges. I'll have to research that problem a bit.

Thankfully though, Unity has the ability to switch to a specific platform on the PC. That means from now on, anything I see on my screen will show up 100% the same on the Android tablet. And yes, those are spiders. At the moment they're just placeholders for the ants. However, they do give me an idea...

Posted: April 14 2013

Since last week I've solved a ton of problems related to cross-platform issues. I have it working and looking exactly the same on Android and Web Player/PC/Linux/Mac. To take a look, I've had the latest developmental build up on the sidebar of the page (Now with added instructions!). I'll update it whenever something significant changes.

Through trial and error, then research I've learned a lot about scripting and thinking in terms of game design and the Unity Engine. When I first started, the libraries and the way I was supposed to interact with them were a mystery to me. I've got a little steam going now and I hope I don't hit any walls (besides the little hurdles I face every single step). Certain things which are very easy in the simple Java development I've done so far such as calling another class or object to get data from it become extremely convoluted in Unity. It took me around an hour or two to figure out how to do it. And I'd made it even harder on myself by not keeping to one language (I was mixing Javascripts and C# scripts).

I have some GUI going now, and I took the hard route. I'm dedicated to making this work on Android as part of my CSIS330 project, so I had to optimize it for the situation. There's a built-in method which will activate when you touch OR click on a GUI element:

void OnGUI () {
		// Do whatever here

Unfortunately, this is apparently unefficient on mobile devices, so after a while I managed to get this together (separate methods for click and touch):

function Update () {
	if(Input.touchCount > 0 ) { 
		for(var i : int = 0; i < Input.touchCount; i++) { 
			var touch : Touch = Input.GetTouch(i);
			if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)) { 
				if (isClicked == true) // if on, turn off
					isClicked = false;
					isClicked = true;	

function OnMouseDown() {

	if (isClicked == true)
		isClicked = false;
	else {
		foodbutton.isClicked = false; // Turns off other summon buttons
		isClicked = true;	

Of course there's a few extra stuff in there (toggle for on/off switch and checking if other buttons are on) but regardless it's a big difference. This is just a tiny taste of the trials I've gone through trying to make this work. The buttons I've added allow the user to place anthills and food (currently a hamburger). I've only just gotten that today, so the logic isn't in place yet to react to the food. My task list for this week is:

Posted: April 20 2013

If you look at my To-Do list on the last post, you'd see I've only made it halfway through. I created a simple but effective wandering script. To put it simply, it walks in a direction, changing the angle of movement every 3 seconds. This works perfectly fine if I drag the prefab object into the editor and start the game. However, if I try using the AntHill button to spawn the object, it will only walk forward and never change direction. This makes absolutely no sense to me, I'm sure it's executing the script because I put debug logs in each of the methods. I thought it might be the change direction function not working for some reason, but I've tried about 5 different ways to change the rotation of an object. It's simply incredible that many different ways to do it even exist! Haha

I've wasted several hours on this one problem since spawning in the anthills was a part of the original plan. No one any the support forums were able to figure out my problem, and the code is absolutely simple so I have no doubt there's no problem in there now. At this point it's starting to seem like it's actually a bug in the engine. So from now on I'll just have two anthills on opposite sides of the level, and the user can choose to place the food wherever they'd like.

I've updated the developmental build (link on sidebar) [4/21: Up now] with the new features (wandering, food spawn, Start button). Over the next week I'll develop the interactions with the food. The ants' smell sensor will have a much larger radius than the sight sensor currently used to detect enemy ants. Once an ant senses food, it will snap out of the wandering activity, approach the food, take some (shrink the food object), then head back to the hill. At the hill, it will leave the coordinates of the food it found for other ants to utilize. At least, that's what I'm aiming for right now.

Edit: Now I've put up the demo, forgot to do it last time. So as you can see it's laid out now where the two hills are on opposite sides of the sandbox. They'll wander about and if they see one from the enemy colony, they will kill them. At the moment, it's kinda funny because at least 90% of the time both die in a kamikaze attack.

Posted: April 29 2013


Like the title says, I'm done! Sort of. Everything's working as planned now except for the problem I mentioned in last week's post. No matter what, spawned-in ants will not perform like the ants which existed initially. You can check out the final build on the sidebar to see how they behave.

Since last week I've added a few features:

I consider myself as done for the semester. I might put a little into it before the final presentation but it would be hard to balance it between all my other exams and projects. There are two bugs in the final build:

Sometimes, some ants will behave oddly after getting food; they will either just get stuck at the food until someone else eats it all or will either get stuck or very slowly make their way back home. It seems this is the fault of RAIN Indie's Behavior Trees having a random glitch. The tool is quite new, so I can't blame them. It appears that with those ants, they are being pulled by two different forces: the Wander code saying go home and the behavior tree saying move towards the food even though there's no reason at that point the Move should be triggering.

The only other bug I can find is the one I've mentioned before about the spawned ants not wandering as they should. I continued to look for answers to this problem and found none.

Resources I've used for this project:

Preview of next project: