Graphical Go Boards
The wiki formatting can easily be extended with new constructions, implemented in Python. Clearly graphical go boards are a useful feature and a proof of concept implementation has been done. It needs significant improvements both in terms of graphics and features. An example is shown here,
























That board is entered with this markup,
{{{
#!goban
+------
|....XO
|....XO
|XXXXXO
|OOOOOO
}}}
The Python implementation of the board looks like this (stored in wiki-macros/goban.py),
def execute(hdf, args, env): lines = args.splitlines() upper_edge = False if lines[0].find('-') >= 0: upper_edge = True lines = lines[1:] lower_edge = False if lines[-1].find('-') >= 0: lower_edge = True lines = lines[:-1] result = '<br />' for k in range(len(lines)): row = lines[k] for j in range(len(row)): s = '' if row[j] == '.': if k == 0 and upper_edge: if j == 1 and row[0] == '|': s = 'ulc' elif j == len(row) - 2 and row[-1] == '|': s = 'urc' else: s = 'ts' elif k == len(lines) - 1 and lower_edge: if j == 1 and row[0] == '|': s = 'llc' elif j == len(row) - 2 and row[-1] == '|': s = 'lrc' else: s = 'bs' else: if j == 1 and row[0] == '|': s = 'ls' elif j == len(row) - 2 and row[-1] == '|': s = 'rs' else: s = 'p' elif row[j] == 'O' or row[j] == 'o': s = 'w' elif row[j] == 'X' or row[j] == 'x': s = 'b' if s != '': result += '<img src="/gnugo-images/goban/' + s + '.gif">' result += '<br />' return '<P STYLE="line-height: 0px"\n' + result + '\n</P>\n'
Most of the code is involved in creating the names of the images borrowed from www.gongames.com (hosting a Swedish forum about go).
Attachments
-
sgfparser.py
(15.8 kB) - added by arend
3 years ago.
Ulrich Goertz' GPL'ed python sgf parser (taken from kombilo 0.5)
-
sgf2ascii.py
(3.0 kB) - added by arend
2 years ago.
A converter from SGF to the ascii go board format used here (depend sgfparser.py)
