This short HOWTO is for students of the AI for Games course at the University of Bradford who wish to use Mono.
I'll assume you already know why you'd want to do this course, or use Mono, so I won't attempt to convince you on either point.
GameForFastTesting to run games for you. And if you're awfully smart you can write a player that queries a human for instructions.
You will need:
gmcs (mcs doesn't support .NET 2.0)
mono, if you intend to execute anything
In Debian (or derivatives, like Ubuntu): apt-get install mono-gmcs mono as root should do the trick.
Let's start with a simple example from the Tanks game (2006/7, second assignment):
namespace GridWorld
{
public class UpTank : BasePlayer {
public UpTank() : base() {
Name = "UpTank";
}
public override ICommand GetTurnCommands(IPlayerWorldState igrid) {
return new Command(Command.Move.Up, false);
}
}
}
I named the file UpTank.cs because it's a tank that moves up.
If you stick the provided libraries in a directory called lib, the command to build our tank should look like this:
gmcs -r:lib/Tanks.dll,lib/GridWorldEngine.dll,lib/GameInterface.dll -target:library UpTank.cs
-r:lib/Tanks.dll,lib/GridWorldEngine.dll,lib/GameInterface.dll
-r option tells gmcs where the extra libraries are. One or more of these will probably need changing for each assignment.
-target:library
gmcs that we're making a library. Otherwise it would whine about an entry point.
After that you should have UpTank.dll sitting next to UpTank.cs. Try running it in the GUI thing in the lab, or upload it to the server.
Let's say you want to make a nice little executable to make use of GameForFastTesting, which is a class in the GridWorld namespace that plays games for you.
Game.cs is a little file containing a class called Game inside the GridWorld namespace. I won't give you it because it requires a lot of setting up, but here's a snippet:
namespace GridWorld {
class Game {
public static void Main() {
...
}
}
}
Compilation is pretty much the same process, except you end up with something that's executable:
gmcs -r:lib/Tanks.dll,lib/GridWorldEngine.dll,lib/GameInterface.dll,UpTank.dll -main:GridWorld.Game Game.cs
-r:lib/Tanks.dll,lib/GridWorldEngine.dll,lib/GameInterface.dll,UpTank.dll
UpTank).
-main:GridWorld.Game
gmcs where the entry point is - we want to enter our piece of software in the Main method of the Game class of the GridWorld namespace.
Now we should have Game.exe sitting next to Game.cs. Now let's execute it with one of the following commands:
MONO_PATH=lib mono Game.exe
MONO_PATH=lib ./Game.exe
MONO_PATH=lib
linkedto some stuff in the
lib directory, and now we have to make reference to that once more so it can find its stuff. This is a normal environmental variable so you can run MONO_PATH=lib; mono Game.exe as two separate commands. Multiple paths in the variable should be separated by colons.
Now you should have some running code (or a load of exceptions). Rejoice, for you have broken free of Microsoft's monoculture just a little (Mono, monoculture, get it?).
And now a thanks to the course's sponsors, Microsoft, without whom this course would not have been possible. We love you and all of your products (we just don't want to use them).
Did you find this helpful? Yeah, no? Did I make stupid mistakes?
Email me: tom@holizz.com (I'd use my Bradford address, only I'm graduating soon - I hope).
This HOWTO is GPLed (see source). Copy and improve.