Recently I spotted question if it's possible to create robot in C++. Here is the answer. Ok, I know, it's not like real C++ with pointers etc, this is managed version of C++, which is safe enough to be runnable in Robocode.
- Download VS 2008 Express C++
- Create new CLR-> Class Library (DLL) project
- Go to project properties, Common Properties, Add New Reference, and add robocode.dll from lib folder of your robocode installation.
- Go to project properties, Configuration properties, General, Common Language Runtime support and set it to Safe MSIL (/clrsafe)
- Go to AssemblyInfo.cpp and delete line with [assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
- Go to [myCppRobot].h and insert code below
- Compile it, drop the DLL into Robocode and enjoy!
#pragma once
using namespace System;
using namespace Robocode;
namespace myCppR {
public ref class MyCplusplusRobot : Robot {
public:
virtual void Run() override {
while(true) {
Ahead(100);
TurnLeft(100);
}
}
};
}