-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial: Creating a TicTacToe Bot
As an introduction to Merknera this tutorial will guide you through creating a bot to play Tic-Tac-Toe in JavaScript using node.js. The aim of this tutorial is to give you an introduction into creating a bot, registering and having it play its first games - this should give you a good understanding of how JSON-RPC works in the context of Merknera and how to test your bot using ngrok and postman.
A simple an non-effective implementation will be implemented and it will be left as an exercise of the reader to improve upon this.
You will need to have the following software download and installed before continuing with this tutorial:
- Create a new directory and navigate to it at the command line.
- Run
npm init
and following the on-screen instructions. - Run
npm install json-rpc2 --save
to install and add the dependency to our package.json file created for us in step 2.
When orchestrating a game Merknera acts as a client and makes calls to the bots participating in the game and the bots act as a server. We will start by implementing the 4 server methods required by Tic-Tac-Toe to play a game: Status.Ping
, TicTacToe.NextMove
, TicTacToe.Complete
& TicTacToe.Error
.
Status.Ping
is the easiest so we will start with that.
Status.Ping is called whenever the Merknera server starts to find out which bots are online and it also calls Status.Ping prior to any move being played, this enables Merknera to ensure the bot is still online and to wake up any bots that might be hosted on a free service such as Heroku that goes to sleep after periods of inactivity. Full documentation can be found here
We need to be able to accept a method of Status.Ping
with no parameters and return with a result of "ping": "OK"
.