Slither.io-bot icon indicating copy to clipboard operation
Slither.io-bot copied to clipboard

Javascript is bottleneck

Open ksofiyuk opened this issue 9 years ago • 19 comments
trafficstars

I think if we want to create a really good bot need to use general purpose programming languages. I have some complex algorithmic solution for slither, but it seems impossible to implement it using Javascript with realtime performance.

Is there a simple way to connect the game interface with external libraries that are written in Python or C++?

P.S. I'm new in Javascript, but have a lot of experience with C++ and Python programming.

ksofiyuk avatar May 08 '16 10:05 ksofiyuk

We could use custom created client programs to connect to the server....

have a lot of experience with C++ and Python programming.

P.S: same here... JavaScript seems like a snail compared to C++ ..

ermiyaeskandary avatar May 08 '16 11:05 ermiyaeskandary

There are no existing clients written in Python or C++ or anything like that matter. Either JavaScript or HTML... :( Unless you want to make one ...

ermiyaeskandary avatar May 08 '16 12:05 ermiyaeskandary

Javascript is bottleneck

It is. Especially because it allows just one thread, which is also needed for the slither.io calculations. And I got more experience with other languages too..

A custom client program would be pretty nice :)) 👍

K00sKlust avatar May 08 '16 14:05 K00sKlust

Nice but hard :)

ermiyaeskandary avatar May 08 '16 14:05 ermiyaeskandary

Isn't there a way to build a small programm with a webview running slither.io and bury all logic in c/c++ and only use a small js interface?

Fredyy90 avatar May 08 '16 14:05 Fredyy90

Accident - sorry

ermiyaeskandary avatar May 08 '16 14:05 ermiyaeskandary

@Fredyy90 It would be possible but we would still be communicating using JavaScript. Are you saying the back end would be ... And then the frontend would be js ?

ermiyaeskandary avatar May 08 '16 14:05 ermiyaeskandary

I guess we only need Js in this setup to get the data from slither.io out, to process it in c/c++ and a way to return calculated the output stuff, like mouse coordinates, speedboost etc.

Fredyy90 avatar May 08 '16 15:05 Fredyy90

Here is a crazy idea (because I do not know C++).

A quick Googling gave me these links: https://discuss.atom.io/t/electron-and-c-dll/17615/2 https://nodejs.org/api/addons.html#addons_hello_world

Now here's how I see it working: Scenario 1 Make a desktop application (with ElectronJS) that is a WebView to slither.io and the user will have to use the app to play the game with the bot.

Scenario 2 An ElectronJS app on users computer will act as a WebSocket server that the browser extension can then talk to. This means that the user doesn't have to use a different application to play the game, but still requires installing an app for the complex calculations at back-end.

mirorauhala avatar May 08 '16 16:05 mirorauhala

@FliiFe Is'nt that what you did for Apos's bot ?

ermiyaeskandary avatar May 08 '16 17:05 ermiyaeskandary

@ErmiyaEskandary It's kinda. But the backend was just sending a list of scripts to load. Implementing script in a backend is, for sure, a good idea, but that would require a lot of work.

tjbcg avatar May 08 '16 17:05 tjbcg

Agreed.

ermiyaeskandary avatar May 08 '16 18:05 ermiyaeskandary

@mirorauhala good suggestions. I would add:

Scenario 3 Use asm.js to compile C++ (or other) down to fast javascript.

All of these options are interesting but complicated.

ChadSki avatar May 08 '16 21:05 ChadSki

I found this StackOverflow discussion about using node-webkit (now "NW.js") to modify a website like Greasemonkey / Tampermonkey does.

With NW.js, the client-side and server-side are the same thing, so our AI could use node.js features. This also provides indirect access to C++.

ChadSki avatar May 12 '16 06:05 ChadSki

Experimental SIMD technology might be useful. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SIMD

The bonus of SIMD is that it's not terribly complicated to use -- it would still work in the browser.

tl;dr it lets you do more math at the same time.

Four math operations: SISD math

One math operation: SIMD math

ChadSki avatar May 14 '16 22:05 ChadSki

@ChadSki Great idea, but it looks like we will have to wait a bit... capture du 2016-05-15 12-03-25

tjbcg avatar May 15 '16 10:05 tjbcg

@ChadSki Oh, and about asm, that wouldn't work since we access game variables and we modify them.

tjbcg avatar May 15 '16 10:05 tjbcg

asm wouldn't work since we access game variables and we modify them.

Why wouldn't it work? asm.js code can fully interop with normal javascript.

Example interop between javascript and C++ (compiled to asm.js with emscripten).

ChadSki avatar May 15 '16 23:05 ChadSki

This looks handy for the asm.js route: https://github.com/gasman/bonsai-c

bonsai-c is a tool for writing programs, not porting them. By building a C compiler from the ground up, rather than bolting a Javascript backend onto a mature C compiler, we can tailor it to the needs of Javascript programmers. You can use it to write a function for calculating fibonacci numbers, and you will get back an asm.js-compliant Javascript module with an obvious entry point, for calculating fibonacci numbers. You will not get a mountain of runtime code to implement file handling and malloc and a million other things you didn't ask for.

They have a great example of C-js interop here: https://github.com/gasman/bonsai-c/tree/master/examples/mandelbrot

To use bonsai, it looks like you run the .c -> .asm.js transpiler on your local dev machine, then add the generated code to your git commit. The transpiler runs on node.js and can be installed with npm.

ChadSki avatar May 28 '16 01:05 ChadSki