SVG Go Player

As part of an on-going project with Victoria I started to write a Python script that can convert an SGF (Smart Game Format: files recording Go (and other) games) into an SVG (my favourite image format) that would one to replay the game.

The Python script makes use of another program I'm working on to parse the SGF into an object it can work with. It creates and SVG with that display the board and contains all the stones, but not visible. A script then makes the stones visible when the next button is clicked and hides them when the back button is clicked.

The tricky part is to calculate when stones need to be removed as prisoners (and when to add them back if you're using the back button). For this, the SVG script has an array of moves in which stone are removed and an array of arrays, containing the number of the stones that are taken prisoner on each of these moves. For example, the first array, prisonerTurns, might contain 42 in its first position and the second array, prisonerStones, might contain [21, 23], which would mean that on move 42, the stones played on moves 21 and 23 should be removed as prisoners.

The script checks for prisoners like so:

var p = prisonerTurns.indexOf(current_move);
if (p != -1) {   
  for (var stone=0; stone<prisonerStones[p].length; stone++){
    toggleStoneVisibility(prisonerStones[p][stone], 'hidden');

To populate the array, I had to write a separate script that plays out the play and checks for liberties. I decided to write a new script rather than making use of one of the many I already have because, as I don't need to check for legal moves when replaying a game, I could make the search for prisoners more efficient. I also wanted to try out a recursive method of testing chains of stones for liberties, which seemed to work very well.



very nice!  are you distributing the python code? I've taken a wack at something similar in tcl/tk - but your blog on-line version is wonderful.

you might check-out these Go resouces: KGS at and

Thanks for your wonderful tutorials and for sharing your experience!


Post new comment

The content of this field is kept private and will not be shown publicly.