Exemplo n.º 1
0
import os
import glob

from abstractboard import get_gameinfo_from_file, apply_gameinfo_to_sgfmodel
from sgfmodels import Collection, Sgf, CollectionSgf, db

default_cols = ['Pro10','IMeijin','Kisei','ITengen','Gosei','Honinbo','Shusaku','Meijin','CJSuperGo','Tengen','Judan','Oza','NihonKiin','Ing']

#collectionslist = CollectionsList()

if not Sgf.table_exists():
    Sgf.create_table()
if not Collection.table_exists():
    Collection.create_table()
if not CollectionSgf.table_exists():
    CollectionSgf.create_table()

for entry in default_cols:
    sgfs = glob.glob('./games/' + entry + '/*.sgf')
    sgfmodels = []
    collections = []
    colsgfmodels = []
    for sgf in sgfs:
        with open(sgf) as fileh:
            sgfstr = fileh.read()
        model = Sgf()
        model.filename = sgf
        model.sgf = sgfstr

        colmod = list(Collection.select().where(Collection.name == entry))
        if len(colmod) == 0:
Exemplo n.º 2
0
    def new_board(self, sgf_model=None, collection_model=None, from_file='', mode='Play', gridsize=19, handicap=0, goto=True):
        toast('Loading sgf', False)
        load_from_file = False

        t1 = time()

        # Get a collection and collectionsgf to contain and represent the board 
        filen = from_file
        if sgf_model is not None:
            sgf = sgf_model
            if sgf.filename:
                filen = sgf.filename
            load_from_file = True
        elif collection_model is not None:
            sgf = Sgf()
            sgf.save()
            collectionsgf = CollectionSgf(collection=collection_model, sgf=sgf)
            collectionsgf.save()
            
            load_from_file = False
            if from_file != '':
                load_from_file = True
                filen = from_file
                sgf.filename = filen
        else:
            collection = get_default_collection()
            print 'default collection is', collection
            sgf = Sgf()
            sgf.save()
            print 'made sgf'
            collectionsgf = CollectionSgf(collection=collection,
                                          sgf=sgf)
            collectionsgf.save()
            print 'made collectionsgf'

            load_from_file = False
            if from_file != '':
                load_from_file = True
                filen = from_file
                sgf.filename = filen

        t2 = time()

        print 't2 - t1 is...', t2-t1

        if filen == '':
            sgf.auto_filename()
            load_from_file = False

        t3 = time()

        # Work out what screen name is free to put it in
        i = 1
        while True:
            if not self.has_screen('Board %d' % i):
                name = 'Board %d' % i
                break
            i += 1

        s = Screen(name=name)
        self.add_widget(s)
        if goto:
            self.current = name

        t4 = time()


        if self.view_mode[:6] == 'tablet':
            pbv = TabletBoardView(sgf_model=sgf)
        else:
            pbv = PhoneBoardView(sgf_model=sgf)
        pbv.board.sgf_model = sgf

        # if platform() == 'android':
        #     #set_board_height(pbv.boardcontainer)
        #     pbv.boardcontainer.set_board_height()

        if sgf.gridsize:
            gridsize = sgf.gridsize
        pbv.board.gridsize = gridsize

        t5 = time()
        
        print ' LOAD FROM FILE!?'
        if load_from_file:
            print 'YES'
            print 'Trying to load from', filen
            try:
                pbv.board.load_sgf_from_file('',[filen])
            except:
                print 'Exception occurred, making popup'
                popup = Popup(content=Label(text=
                                            ('Unable to open SGF. Please check'
                                             'the file exists and is a valid SGF.'),
                                            title='Error opening file'),
                              size_hint=(0.85, 0.4),
                              title='Error')
                print 'popup made'
                popup.open()
                #self.close_board(name)
                return False

        pbv.board.reset_gridsize(gridsize)
        pbv.board.add_handicap_stones(handicap)

        pbv.board.time_start()
        s.add_widget(pbv)
        pbv.screenname = name
        pbv.managedby = self
        pbv.spinner.text = mode
        pbv.board.touchoffset = self.touchoffset
        pbv.board.coordinates = self.coordinates
        pbv.board.board_path = boardname_to_filepath(self.boardtype)
        pbv.board.display_markers = self.display_markers
        pbv.board.cache = App.get_running_app().cache
        pbv.board.get_game_info()
        self.boards.append(name)

        if self.view_mode[:6] == 'tablet':
            pbv.board.comment_pre_text = 'This [b]tablet mode[/b] is currently experimental. It should work fine, but is still being tested and will be subject to change (more efficient layout etc.) and speed optimisation before being finalised.\n-----\n'

        t6 = time()
        print 'timings are'
        print t6-t1, t6-t5, t5-t4, t4-t3, t3-t2, t2-t1

        self.refresh_open_games()
        self.collectionindex_to_refresh = True
        if collection_model is not None:
            if collection_model.name not in self.collections_to_refresh:
                self.collections_to_refresh.append(collection_model.name)
        pbv.board.save_sgf()

        return pbv
Exemplo n.º 3
0
    "ITengen",
    "Gosei",
    "Honinbo",
    "Shusaku",
    "Meijin",
    "CJSuperGo",
    "Tengen",
    "Judan",
    "Oza",
    "NihonKiin",
    "Ing",
]

# collectionslist = CollectionsList()

if not Sgf.table_exists():
    Sgf.create_table()

models = []
for entry in default_cols:
    # collection = Collection(name=entry,defaultdir='./games/' + entry)
    # for sgf in sgfs:
    #     info = get_gameinfo_from_file(sgf)
    #     game = collection.add_game(False)
    #     game.filen = sgf
    #     game.gameinfo = info
    #     game.save()

    sgfs = glob.glob("./games/" + entry + "/*.sgf")
    for sgf in sgfs:
        with open(sgf) as fileh: