How to use Robocode in C++
Prerequisites:
1. Install Java
2. Install Robocode
3. Install Robocode .NET (see inside version folder)
How to create a robot:
1. in VS, File -> New -> Project… select SLR Class Library
2. in Solution Explorer, right-click on References -> Add Reference…
browse to Robocode libs folder (C:\robocode\libs\), click on robocode.dll
3. Go to Project properties
Switch Common Language Runtime Support to ‘Safe MSIL Common Language Runtime Support (/clr:safe)’
4. Start coding.
Create class derived from Robot or AdvancedRobot;
Implement Virtual Methods like Run and OnScannedRobot, e.g.
System::Void RoboTestCPP::Robot1::Run()
{
// -- Initialization of the robot --
// Here we turn the robot to point upwards, and move the gun 90 degrees
TurnLeft(Heading - 90);
TurnGunRight(90);
// Infinite loop making sure this robot runs till the end of the battle round
while (true)
{
// -- Commands that are repeated forever --
// Move our robot 5000 pixels ahead
Ahead(5000);
// Turn the robot 90 degrees
TurnRight(90);
// Our robot will move along the borders of the battle field
// by repeating the above two statements.
}
}
System::Void RoboTestCPP::Robot1::OnScannedRobot(Robocode::ScannedRobotEvent^ evnt)
{
// We fire the gun with bullet power = 1
Fire(1);
}
5. Compile
6. Go to Robocode, Options -> Preferences -> Development Options and Add folder to your dll