def single_import_renju_pattern(index): renju_db = DBWrapper(db_path="./data/renju.db") pattern_db = DBWrapper(db_path="./data/patterns.db") row = renju_db.query("select * from renju limit 1 offset ?", index)[0] position = RenjuGame(board=stream_to_board(row["board"]), player=row["player"]) pattern = ','.join(map(str, position.get_patterns())) action = row["action"] while True: try: pattern_db.execute("insert INTO pattern(pattern, player, action) VALUES (?, ?, ?)", pattern, row["player"], action) break except: logger.warn("fail to insert into pattern_db, try again")
def __init__(self): self.db = DBWrapper(db_path="./data/patterns.db") self.db.execute("CREATE TABLE IF NOT EXISTS pattern(id INTEGER PRIMARY KEY AUTOINCREMENT, \ pattern TEXT NOT NULL, \ player SMALLINT, \ action SMALLINT)") self.ids = map(lambda row: row["id"], self.db.query("select id from pattern")) self.fetch_index = 0
def __init__(self): self.db = DBWrapper(db_path="./data/renju.db") self.db.execute("CREATE TABLE IF NOT EXISTS renju(id INTEGER PRIMARY KEY AUTOINCREMENT, \ gid INTEGER NOT NULL, \ mid SMALLINT NOT NULL, \ board TEXT NOT NULL, \ player SMALLINT, \ action SMALLINT)") self.db.execute("CREATE INDEX IF NOT EXISTS renju_gid ON renju(gid)") self.ids = map(lambda row: row["id"], self.db.query("select id from renju")) self.fetch_index = 0