nodejs Game loop and external scripting files

Well first of all I'm new to nodejs and its looks amazing to me!

I really would like to build a game with bot players in nodejs. The idea is to have bots playing some game (like checkers for example).

The first question is:

  • Is nodejs suitable for this purpose? Please take in account that the main idea is not to build the game, but also to gain experience with async programming and especially nodejs (well because node is cool and awesome!).

Then I encountered another problem. While writing a web server in nodejs is simple (there are millions of example over the net), there are almost not example how to write an infinite loop without blocking the event loop, so question two:

  • How to write an infinite game loop, without blocking the main even loop? In C/C++ I'd do something like while(gIsRunning) {doStuff(); gIsRunning = gameEnded(); sleep(ms)/delay(ms); }

Of course in my case the game is infinite (because the players are bots) and should be run while I haven't killed node process manually.

Since the game is bot oriented, I'd like to be able to write bots in JS and include them into the main game engine. So third

  • Is it possible to write the bots as standalone JS script and load then into the main game engine run by node in some sort of limited environment (sandbox)? The future idea is to provide some basic API for bot development, and I dont want to run third-party bots with full functionality (fs, sockets etc). Also I dont want to manually inspect the code of every third party bot.

Think of this challenge as what known as "Google AI Challenge". Google develops some engine and provide SDK to develop bots that will be loaded by the engine and "play". I want to do the same but in nodejs, to write both the game engine and the SDK for bot development.

Sorry for making the question maybe too general for SO, and bounded to personal opinion (whether node is suitable or not, might be personal preferences).

Thank you a lot for any help!

To get you started with question one, you might be interested in HTML5/Node.js game called BrowserQuest by mozilla http://browserquest.mozilla.org/

Source code is here https://github.com/mozilla/BrowserQuest

One way to achieve the sandbox effect, you could run multiple node.js processes for the bots logic and use RPC library like https://github.com/substack/dnode that your main game loop process uses to obtain bots actions?