08/21/2011

Windward / C.U. Code War – A Factory is a very Dangerous Place for a Robot

The game is RoboRally. You need to write an A.I. for the game that is superior to that written by all of the other contestants.

Imagine that you're a supercomputer. Now imagine that you're bored. So you dream up a little contest for you and a couple of your supercomputing buddies. Your task is to move one of the stupid little robots out on the factory floor through a series of checkpoints scattered throughout the factory. The wrinkle, however, is that the factory floor is filled with all kinds of inconvenient (if not down-right deadly) obstacles located in various locations: conveyor belts, crushers, flame-throwers, pushers, teleporters, oil slicks, pits, et cetera. But the real fun comes when the robots cross each other's path, and suddenly your perfect route is something less than that...

Each turn is composed of 5 moves or phases. For each turn your AI will receive 9 cards and return 5 of them in order (these numbers will change, details below).

Each card has a unique priority number. The moves for a phase are done from highest to lowest priority.

When each robot moves, it will push any robots in its way.

If a robot in the way cannot be pushed (due to a wall), then the move does not occur.

After all robots move for a phase, then there are board moves due to gears and conveyor belts.

Your robot maintains its direction on a conveyor belt.

It is rotated with the belt when the belt moves it onto a turning belt square. When a robot moves to enter a turning conveyor square it is not rotated. This includes when a robot is on a conveyor belt the robot uses a move card to move onto the turning square.

After the board moves, all robots and fixed lasers fire.

Every time a laser hits your robot, you receive 1 damage.

Walls block a laser.

Robots block a laser, so a laser hits the first robot in it line, but no more.

If your robot is now on the square that contains the flag you are presently going for, you have now touched that flag and your goal is the next flag.

If your robot is on a flag or repair square, that is now your archive (re-entry) square.

You only get repaired 1 damage level if you end the turn (not phase) on a repair square.

You have 3 lives. You are killed if you move off the board or if you receive 10 damage from lasers.

When you are killed, you are done for the turn (not phase) and then come back on your archive square at the start of the next turn. When you return, your robot will have 2 damage upon return.

If you are damaged (not killed), you can set to power down at the end of a submitted turn.

For the next turn you will start with no damage and your unit will not move – but it can receive damage from lasers.

At the end of the turn it receives 2 additional damage and is then active for the subsequent turn.

Damage impacts the number of cards you get each turn. When the number of cards drops below 5, the remaining phase moves are locked in from what you had the previous turn. Card locking starts with phase 5 (table below).

Cards dealt = 9 – Damage level.

Cards locked = Damage level – 5.

At damage level 9 you cannot set any turn cards, but you can set power down at the end of the turn.

This game does not have pushers, pits, or option cards. You cannot continue a power down if your unit was badly damaged during power down.

Damage level

Cards dealt

Cards locked

0

9

0

1

8

0

2

7

0

3

6

0

4

5

0

5

4

1

6

3

2

7

2

3

8

1

4

9

0

5

10

Robot destroyed

Rules

You are on your honor to follow the below rules. If you are caught violating any, you will be disqualified and it will be posted why you were disqualified.

You may not read/write any data in any part of the code except your DLL. You may not use reflection or errors in the code to access the main program's data.

You may not create worker threads.

Your code must return on all calls in under 1 second. If it takes longer than a second the call will be aborted and you will get a random turn.

If you find an error in the code, you may either take advantage of it or tell us. If you tell us, we will fix it but will not announce the fix so others that assume the bug exists will not be able to use it.

You can Google, call friends, post on forums, etc. for any coding, general AI, algorithmic, or implementation issues. You can read anything about how to play RoboRally. But you cannot ask others for help on determining what approach to take.

In other words – do not post questions on board game forums asking what you should do in your AI.

There are two AIs out on the web - they are poorly designed and won't work with the rule changes we've made. Don't use them.

Final code must be delivered by 6:00.00. Not 6:01. Not 6:00.01. 6:00.00. You can (and should) provide versions during the course of the day. We will use the most recent one delivered at 6:00. You can deliver on a USB stick or email it to david@windward.net.

Links for after the game

Java Programmers

You are using J# which is 99% identical to Java 1.2 (there are a couple of library calls missing but you are unlikely to trip over them). You have to write and build the code in Visual Studio 2005 (Microsoft dropped support for J# after 2005).

You then run the main program using Visual Studio 2010. The main program cannot be loaded in VS 2010 because it uses .NET 4.0. When you run, it pulls in your player from the DLL you built using the setting in RoboRally.exe.config.

You can debug your code. Within Visual Studio 2010 open your source file and set a breakpoint. It will break on that line and you have the full debugger. But this only works if the DLL file is newer than the source file. If you edit the source file and don't rebuild the DLL, then it will not work.

Python Programmers

Writing a player in IronPython is very simple. The example AI "MyPlayerBrain.py" will get you started and show you how all the basics work.

The most important fact is that you provide a Python file with a class called "MyPlayerBrain". This class must inherit from "IPlayer", imported from "RobotRallyAPI" as in the example, and must implement the same methods and properties. The methods must all take the same number of arguments and return the same type of object as the example. The docstring of these methods in the example show you what arguments each method takes, and what these methods must return.

For example, the "Setup" method takes three arguments (in addition to "self"). These are "map", "you" and "robotStart". The method must return a "PlayerSetup" object.

Your player code is executed in an IronPython environment created by RoboRally. The environment already has references to the 'RoboRallyAPI' and 'System' assemblies. You can import from the "RobotRallyAPI" and "System" namespaces without having to add any references yourself. If you want to use any other assemblies (like `System.Drawing` for example) you'll need to add references to these yourself with a call to `clr.AddReference`.

A useful reference for examples of how to interact with .NET types from IronPython is the IronPython cookbook: http://www.ironpython.info/

Your player must be provided in a Python file with a class named "MyPlayerBrain". This class can use other python libraries (modules or packages). The directory containing your main Python file is in `sys.path` (the Python import path). Python modules or packages in the same directory as your main python file can be imported. This allows you to organise your code in more than a single file.

An important part of Python is the standard library. Some parts of the standard library are "built-in" to IronPython, like the `sys` module. Other parts usually have .NET equivalents that you can use instead. If you want to use the Python standard library you can get it from the standard IronPython distribution, available for download from here: http://ironpython.codeplex.com/releases/view/54498

Download the "IronPython Binaries" version, which is a zip-file. The standard library is contained in a directory called "Lib" inside the "IronPython Binaries" zip-file. If you put the "Lib" directory (the whole directory, not just its contents) in the same directory as your main Python file then your code will be able to import modules from it. (The "Lib" directory is automatically added to `sys.path` for you.)

If you want to debug your IronPython code when it is running, you will need "IronPython Tools for Visual Studio". This can be downloaded from: http://pytools.codeplex.com/