Creating a Go bot IV – The first move.

Well, now we have an empty board, we need to make our first move. My first approach is that every position has a value and the one with the highest value will be where our bot will play.

What is the easiest way to start doing that? Give a random number let’s say from 1 to 10 to every position, and -1000 to positions where it is forbidden to play (walls, places with stones, ko). Why -1000 and not -1 or something like that? Maybe in the near future from the first value, some things will rest points and -1 can be the place with highest value, so it is better to give an unreachable low value (I am writing as I am thinking).

So, where will be all those things? I am thinking in giving the bot a “brain” that will be a class or a bunch of classes that will receive the actual board, process it and return a move.

so, let’s create a class “Engine”. For starters I think on something like this:

This class has an engine that as a parameter for the constructor it gets his color.

So everytime it is his turn we call the putStone method that receives the board, it calls getValues that will give random values and -1000 to non playable places and returns the position with the highest score. In the future it will pass through a lot more methods, but now this is simple.

Maybe in the future, while adding more things, I will separate the engine in several classes, but for now it works.

So, let’s change the main.py to create the engine, show the board, let the engine play a stone and show the board again:

This is for a 9×9 board, so when I run this I get this:

Yes, I know it is not the best possible move, and it is not even a reasonable move playing 1-3 but as it is random, well, it is a move.

I wanted to run this again just to make sure it plays in other place, and it worked (will just paste the board with the move this time)

Next time I will add more parameters to make this play more “reasonable” openings.

Leave a Reply

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