A Go AI in 2 hours

Journalists used to think computers would never beat humans at chess.

You probably remember Kasparov vs Deep Blue. Back in those days, journalists were beginning to come around to the reality that computers were going to be better than humans at chess. They didn’t like it. Their go-to way to console the human race was the older, deeper board game go. Computers would never beat humans at go.

Every six months, for the rest of their lives, Will and Scott meet and Will plays go against a computer program written by Scott. They’ve been doing it for almost 10 years.  Then, a couple years ago, my friend Dusty joined this bet; now Will simultaneously plays go against Dusty’s AI as well. I’ve spectated since then, until last time, when I started feeling ambitious and signed up as the third AI.

Today was match day, and it was the first day my AI would participate. When I woke up this morning, I had done exactly zero work. Also, I had slept in, so we were late to the match. So that gave me the duration of the other two go games to write the simplest program I could that was still technically a go AI. I didn’t aim high.

I went with Python because I think it’s the easiest language to rapidly prototype in. I used GoGUI to avoid writing a UI. GoGUI communicates with go AIs using GTP; it spawns a child process and talks to it over stdin and stdout.  The initial setup of downloading GoGui and getting a project ready took about 10 minutes, mostly spent on false paths. Then the first hour or so of work was spent writing a barebones protocol handler. This is not easy to do under time pressure! The protocol spec is too dense to get much out of without reading a lot, so I learned the protocol groundhog-day style; by running my program over and over again and making it one step further through the handshake each time. Logging was key. Once that was done, I had a bot that could do the initial handshake and convince GoGUI that it was a valid go AI, but it didn’t make any moves. It took a couple of seconds to write a bot that would always make the same move, but after the first time it makes the move, the move is illegal, so this didn’t really count as an AI. But it was very close.

The next couple of minutes were spent writing an internal representation of the board state so I could reliably make random *but still legal* moves.  If you’re a go player, you’re probably thinking I had to encode a bunch of go rules in order to avoid playing into atari. Turns out there’s a rules variant in which playing into atari – which is a suicide move – is still legal, albeit almost always terrible.

The good news was it was finished in time to participate in the match. The bad news is that while go programs are now smart enough to beat humans, they’re not yet good enough to beat humans by playing random moves. I lost spectacularly.

You can see my go bot, CotiGo, on github. Maybe someday it will be better. A nice low bar to cross will be making it good enough to beat me. I’m very bad at go.


One Response to A Go AI in 2 hours

  1. timothyfitz says:

    “If Will Harvey, as a person, is enhanced so that he can no longer compete using only the abilities of a 2003-era fully-organic human being, then this bet is temporarily halted until such a time as he is able to revert to a standard human.” – http://don.geddis.org/bets/go/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: