Ejemplo n.º 1
0
def get_eco(hash):
    if not ECO_OK:
        return None
    cur = conn.cursor()
    select = "select eco, opening, variation from openings where hash=? and lang=?"
    cur.execute(select, (memoryview(hash_struct.pack(hash)), lang))
    return cur.fetchone()
Ejemplo n.º 2
0
def get_eco(hash):
    if not ECO_OK:
        return None
    cur = conn.cursor()
    select = "select eco, opening, variation from openings where hash=? and lang=?"
    cur.execute(select, (memoryview(hash_struct.pack(hash)), lang))
    return cur.fetchone()
Ejemplo n.º 3
0
    def feed(pgnfile, lang):
        cf = load(protoopen(pgnfile))
        rows = []
        old_eco = ""
        ply_max = 0
        for i, game in enumerate(cf.games):
            model = cf.loadToModel(i)

            eco = cf._getTag(i, "ECO")[:3]

            opening = cf._getTag(i, "Opening")
            if opening is None:
                opening = ""

            variation = cf._getTag(i, "Variation")
            if variation is None:
                variation = ""

            base = int(old_eco != eco)

            ply = len(model.moves)
            ply_max = max(ply_max, ply)
            if ply == 0:
                cu = conn.cursor()
                cu.execute(
                    "select * from openings where eco=? and lang='en' and base=1",
                    (eco, ))
                res = cu.fetchone()
                if res is not None:
                    hash = res[0]
            else:
                hash = memoryview(hash_struct.pack(
                    model.boards[-1].board.hash))

            if opening:
                rows.append((hash, base, unicode(eco), unicode(lang),
                             unicode(opening), unicode(variation)))

            old_eco = eco

        c.executemany(
            "insert into openings(hash, base, eco, lang, opening, variation) values (?, ?, ?, ?, ?, ?)",
            rows)
        conn.commit()

        print("Max ply was %s" % ply_max)
Ejemplo n.º 4
0
    def feed(pgnfile, lang):
        cf = load(protoopen(pgnfile))
        rows = []
        old_eco = ""
        ply_max = 0
        for i, game in enumerate(cf.games):
            model = cf.loadToModel(i)

            eco = cf._getTag(i, "ECO")[:3]
            
            opening = cf._getTag(i, "Opening")
            if opening is None:
                opening = ""

            variation = cf._getTag(i, "Variation")
            if variation is None:
                variation = ""
            
            base = int(old_eco != eco)
            
            ply = len(model.moves)
            ply_max = max(ply_max, ply)
            if ply == 0:
                cu = conn.cursor()
                cu.execute("select * from openings where eco=? and lang='en' and base=1", (eco,))
                res = cu.fetchone()
                if res is not None:
                    hash = res[0]
            else:
                hash = memoryview(hash_struct.pack(model.boards[-1].board.hash))
                
            if opening:
                rows.append((hash, base, unicode(eco), unicode(lang), unicode(opening), unicode(variation)))
                
            old_eco = eco
                
        c.executemany("insert into openings(hash, base, eco, lang, opening, variation) values (?, ?, ?, ?, ?, ?)", rows)
        conn.commit()

        print("Max ply was %s" % ply_max)