billyb2 / game

GNU Affero General Public License v3.0
2 stars 0 forks source link

Allowing bots written in any language #7

Open billyb2 opened 3 years ago

billyb2 commented 3 years ago

This is obviously more of a long term thing, but I've thought of a pretty easy way of allowing players to create bots in any programming language, from C to Java to Assembly, as long as they can create a binary.

Basically, as long as a program can compile to a binary, it could take an input from STDIn of a json ified version of all the data a player would normally receive, and output stuff like where it wants to move, using its ability, etc.

As an example: (The AsyncGetLine thing is a part of torrent.hpp, it's not necessary to understand as this is just unrunnable pseudo code but I thought it might be useful to attach anyway for future use) torrent.hpp.zip

int main() try {

    AsyncGetline ag;
    string input;

  while (true) {    
    input = ag.GetLine();

    if (!input.empty()) {
        //Do some deep and powerful calculations
        cout << "{ \"direction\": \"" << "1" << "\", \"attacking\": "  << "false"  << endl;

    }

}
catch (exception& e) {
  cerr << "Error: " << e.what() << endl;
}

The code above is pseudocode, and (probably) won't actually compile. Basically, after taking an input that the rust code gives, it outputs stuff like the direction that the bot wants to move in that the rust code receives. Code like this could be written in Java, C++, Kotlin, JavaScript, anything works (though for C and C++ we could use the foreign function interface.

billyb2 commented 3 years ago

Don't actually use the torrent.hpp file lol, it includes a bunch of extra stuff we don't need. The AsyncGetLine function within it is the most interesting part.

billyb2 commented 3 years ago

A good start