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:
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.
turn = 1
gtp_command = input()
color,move = gtp_controler.resolve_input(gtp_command,main_board,evil_tesuji)
if color== 1 or color == 2: #Movement command
else: #Other commands
if color == 50:
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):
#Gets a coordinate and returns a Position
column = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U','V', 'W', 'X', 'Y', 'Z']
if coordinate == "PASS":
if coordinate == "RESIGN":
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.
__author__ = 'Pablo'
from Engine import Engine
#This class is for implementation of GTP Commands
#receives an input and resolves what to do.
move = move.upper()
#TODO: Quit hardcoding
Here is a screenshot of this working: