How to use C++


I would like to use C++ for my algorithm, but in the git StarterKit repository, there are only Python, Rust and Java.
Is it possible? If yes how to do it?


I’m not really sure how to do this myself, I know people like arnby are using it.
Check out this thread maybe?

1 Like

Only Python, Rust and Java are normally supported.
However many top players (including myself) use “tricks” to use C or C++ for performances.
You should be aware that those tricks could stop working at any time with a game update:

So I would not advise new players to try to have C/C++ in their first approach to the game.
Start to consider C/C++ only if you have performance difficulties and you see no better way than using C/C++.

That being said in the thread @IWannaWin linked, I explain my way for using compiled C++ subprogram in Python.

1 Like

Another way to use C++ is by compiling a python extension. This directly interfaces with Python so (personally) I believe that it should always work since you import it just like a normal python module. As far as I have found there isn’t a ton of unofficial documentation about it so you probably need to be comfortable implementing code primarily only using the Python documentation (which is quite good) since there aren’t many tutorials about how to do it.

It should be noted that I do plan on writing a little intro about this soon (I have been quite busy as of late) since I think it’s a valuable and interesting skill people would benefit from learning how to use.

If you are interested in doing this I suggest reading into shared object (SO) files and into the ctypes python module.
To clarify:
You can use the ctypes module to import SO files. In these you can basically export c-type functions for python to use. In python you will just have to define the interface and you’re ready to go. One advantage is that you dont need to compile anything on the server, but can do all on your PC before uploading (at least if you are working on linux, not sure if its the same for shared object files for windows).

If you are interested in that approach (or anyone else is interested), I can maybe write a tutorial (if the people from c1games dont have any problems with that) or pm you a basic example to work with.

1 Like

As I said once in a different thread, if you are having performance problems, Rust is just as fast as C++, officially supported, and you won’t even get segfaults. You’ll have to learn it, of course, but this is a great time to do that, and Rust is a nice language to have in your arsenal.

I used the same method as @Zaustie to put a simulator on C++. You do have to port over a lot of the gamelib folder, which kinda sucks (and hurts your arm to type so many { } 's and ; 's).

This guide was fantastic and told me 95% of what to do. This tells you how to create a C++ class that you can use to call methods, but AFAIK those methods need to return primitives (or at least an array of primitives). Haven’t had any success on returning objects, but there’s always hacky workarounds to get what you want.