Creating a Go Bot part VI – GTP

The next step to create the go bot is to make it compatible with GTP (Go Text Protocol) which is a standard for go bots and online go. This protocol have an “oficial website” that is well documented.

The idea is that the gtp engine is between the main loop and the engine, something like this:

MAIN <——GTP—–>Evil-Tesuji

I don’t remember if I said this earlier, but the engine name is “Evil Tesuji”.

There is a lot of refactor, but let’s put some code. It is not the best one, is just the first version of this and heavy refactoring will be needed in the near future.

From gtp protocol I implemented three commands:

  • Version: Gives the version of the engine.
  • Play: puts a stone in the board
  • Genmove: Waits a play for some color.

As long as I understand, gtp commands comes from the standard input, so, first I need to input waiting for command.

So let me explain some things of the code:

First I wait for an input, and then I send it to my gtp engine. My Gtp engine will do lots of things and return a color and a position. Then that color will be put in the board array. There are some exceptions like version, pass or resign moves.

If I send version command, color code is 50 so it goes to print the version. Same will happen in the future with machine name and all descriptions, they will have different color codes.

On the other hand resign will have position -10000 and pass -5000. For that I changed coordinate_to_position method (I am quitting all camel case):


For gtp, code is kind of self explanatory, you can choose between the available commands and each one will go to a method to resolve and return a color and a position. On genmove command it calls the engine and makes it play something with the chosen color.


Here is a screenshot of this working:


Leave a Reply

Your email address will not be published. Required fields are marked *