Halite Home

How to get started with C++


#1

I just wanted to know how can I get started with C++?

I downloaded and extracted the C++ starter package and then put the halite.exe in that folder. Then i ran runGame.bat and it is just stuck. Where as python started saying Turn 1, Turn 2 ...

PS: I am choosing C++ as it is faster than Python, am I wrong ?


#2

C++ should take a little longer to get started since it has to compile the executable first but it shouldn't take too long (~10 seconds for the starter package).


#3

I am using windows and it dint respond for like 2 - 3 minutes after that i closed it


#4

If you don't have G++ installed on Windows, it will fail building the bot.
I use visual studio. To build a bot using visual studio, change the scripts to do this:

cl /EHsc /Zi MyBot.cpp

You also need to run "vcvars32.bat" when you open the command line window.
Separately: G++ and MSVC complain about different things for warnings, so it's a good idea to upload your code to some Linux box and run g++ -std=c++11 on it before you submit, to make sure it compiles cleanly.

Finally, there is a problem with the Windows runner, where the spawned processes stay alive forever after the game is finished. You need to ctrl-shift-escape to bring up the Task Manager, and kill the bot processes manually.
For me, that got old really quickly, so I added some code that spawns a thread that test-and-clears a boolean flag once a second, and then the program sets the flag in the main loop, and if the flag hasn't been set for 3 seconds, the thread calls exit(). That worked around the problem for me. I have to #ifdef it out for competition code, as Windows thread functions aren't available on Linux. (And I can't link to pthreads, because Makefile support isn't in yet.)

You can test for MSVC as such:

#ifdef _MSC_VER
visual_studio_code();
#else
gcc_code();
#endif