diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2014-08-24 12:52:10 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2014-08-24 12:52:10 +0200 |
commit | 6c2cc134abf3f32d1d6ec172c6201f8d990c88ab (patch) | |
tree | 98b03151505f8fc058977f906e93e9a799b02217 /qml/python/board.py |
Initial commit
Diffstat (limited to 'qml/python/board.py')
-rw-r--r-- | qml/python/board.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/qml/python/board.py b/qml/python/board.py new file mode 100644 index 0000000..48f3ff0 --- /dev/null +++ b/qml/python/board.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +try: + import pyotherside +except: + print("no pyotherside module loaded") + +import sgfparser +from game import Game + +counter = 0 + +path = "" +cursor = None + +def setPath(qtPath): + global path + path = qtPath + +def loadBoard(filename): + global cursor + + sgfPath = os.path.join(path,"../content","sgf",filename); + pyotherside.send('log', sgfPath) + try: + f = open(sgfPath) + s = f.read() + f.close() + except IOError: + pyotherside.send('log', "Cannot open %s" % filename) + return + + try: + cursor = sgfparser.Cursor(s) + except sgfparser.SGFError: + pyotherside.send('log', 'Error in SGF file!') + return + pyotherside.send('log', 'File %s loaded' % filename) + pyotherside.send('log', 'Found %d problems' % cursor.root.numChildren) + return cursor.root.numChildren + +def getGame(n): + global cursor + + cursor.game(n) + + game = Game(cursor) + game.normalize() + pyotherside.send('log', "Game loaded !!") + + return { + "tree": game.tree, + "size": game.get_size(), + "side": game.side, + } |