1. Computing & Technology

Discuss in my forum

Entering the Google Ant AI Challenge plus problems encountered entering a C# Bot

By , About.com Guide

Screenshot

Before starting you will need to install Python if you haven't got it. This is only for Windows users as Mac and Linux users should have it already installed. The aichallenge website gives links to installers or you can go direct to the Python 2.72 install page.

Python is a useful and more importantly cross-platform language. It's handy for quick and dirty programming tasks and if you want to know more about it take a look at python.about.com

You don't actually need Mono for the C# entry. If you have Visual Studio 2010 or Visual C# 2010 Express you can use those to write your code.

Now register with the AI challenge web site, verify the link in the email that you're sent and grab a starter pack. If you have a preference for languages other than C,C++ or C# there are plenty to go on. However many have restrictions such as incompleteness and the big four not surprisingly are C++, C#, Python and Java. I picked C# for my entry.

To get quickly registered as an entrant, once you have downloaded the starter pack immediately submit it. If you look for the bot aboutCPlus, you'll see it's near the bottom of the first 900 after playing 6 games in the ten minutes. Plenty of room for improvement! Make sure you remember the name of your bot, because unless you are in the top 100, you'll need to search for it!

Working on Your Bot

Download and unzip the Tools and create a folder containing them. There's a folder sample_bots that has csharp, java, php and python bots, though currently only one C# bot in GreedyBot.cs. The csharp p starter package includes eight source .cs code files that are needed to implement the game infrastructure.

Create a C# project, make a copy of GreedyBot, renaming it to your own bot name, then add the eight start source code files to the project and you will find that it still doesn't actually compile. There are a number of errors which look like the two were developed separately or got out of sync.

I've fixed the various bugs and got it running on my PC using Visual Studio. Out of interest I also installed Mono and MonoDevelop just to see if the errors were any way connected to it not being compiled with Mono but they weren't. Both Mono and Windows C# reported the same bugs.

Running the Bot

I struggled for 30 minutes before it dawned on me why it kept failing to start. Stupidly I had configured the build so the exe appeared in the same folder as the project folder - So my bot which was really the fixed GreedyBot that I called aBoutBot and the folder aboutBot were both in the same folder. Python apparently got confused between the two and kept trying to excute the folder! So make sure the exe goes somewhere else. You can alter the C# project settings so it gets output wherever you want it.

To run the bot locally you need to run the file play_one_game.cmd in the Tools folder. This contains the correct invocations for Python to do its stuff. Examining the original file you'll see that each Python coded bot needs a parameter like this to run it.

"python ""%~dp0sample_bots\python\RandomBot.py"""

If you compile a C/C++ or C# exe so that it's output in the sample_bot folder then to have it run, use something like this, where aboutBot is the name without the extension.

"%~dp0sample_bots\aboutBot"

In case you're curious about the %~dp0 prefix, it's batch parameter modifiers and is a way of capturing the current directory in a batch file. This blog post explains it.

After running the local contest, it will load your default browser and replay the contest. You can zoom in and out and watch how your Bot performs against others. The system allows up to ten bots on a map.

Writing a Superior Bot

Having spent a bit of time getting the bot to compile and then run plus writing this means I haven't devised the ultimate killer Ant controlling bot yet but it's early days. The GreedyBot clone isn't however going to win many prizes so it's back to the drawing board!

The maps are made up of squares, basically

  • Land
  • Water
  • Hill
  • Unseen

and Land can have an ant (living or dead) or food.

The Bot receives lists of what can be seen by Ants (within a cerrtain radius of each live Ant) as a series of lists for water, food, ant hills, live and dead ants. The Ants then receive move orders (horizontal and vertical), gathering food killing other ants and trying to find/destroy other hills.

So if you think you could write a strong Bot have a go. It's free. Just watch out if you meet AboutBot!

©2012 About.com. All rights reserved.

A part of The New York Times Company.