private static LookupMove GetRecord(int steps,int index,SQLiteConnection conn) { DbCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM block_colors WHERE num_steps='"+steps+"' ORDER BY pos ASC LIMIT "+index+",1"; DbDataReader reader = cmd.ExecuteReader(); LookupMove m = null; if (reader.Read()) { string pos = (string)reader["pos"]; char[] c = pos.ToCharArray(); int[,] p = new int[9,9]; int run = 0; for (int i = 0; i < 3; i++) for (int j = 3; j < 6; j++) p[i, j] = (int)c[run++] - (int)'0'; for (int i = 3; i < 6; i++) for (int j = 0; j < 9; j++) p[i, j] = (int)c[run++] - (int)'0'; for (int i = 6; i < 9; i++) for (int j = 3; j < 6; j++) p[i, j] = (int)c[run++] - (int)'0'; m = new LookupMove(p, (string)reader["move"], (int)((long)(reader["num_steps"]))); } reader.Dispose(); cmd.Dispose(); return m; }
static void Main(string[] args) { string currentDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); currentDir = currentDir.Replace("file:\\", ""); string connString = "Data Source=" + currentDir + "/pattern.sqlite;Pooling=True"; SQLiteConnection conn = new SQLiteConnection(connString); conn.Open(); string createTableSql = "CREATE TABLE IF NOT EXISTS \"block_colors\" (\"pos\" char(45) PRIMARY KEY,\"move\" char(2) NOT NULL, \"num_steps\" INTEGER NOT NULL, \"checked\" INTEGER NOT NULL);"; ExecuteDbCommand(createTableSql, conn); //ExecuteDbCommand("DELETE FROM block_colors;", conn); int[,] p = new int[9, 9] { {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,1,1,1,0,0,0}, {0,0,0,1,1,1,0,0,0}, {0,0,0,1,1,1,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0} }; //q = new Queue<LookupMove>(); LookupMove perfect = new LookupMove(p, "", 0); try { ExecuteDbCommand("INSERT INTO block_colors (pos,move,num_steps,checked) VALUES ('" + perfect.pos + "','" + perfect.move + "','" + perfect.level + "','0');", conn); //q.Enqueue(perfect); } catch (SQLiteException e) { } isRunning = true; OutputClass o = new OutputClass(); new Thread(new ThreadStart(o.output)).Start(); count = GetNum(conn); while (true) { //if (q.Count == 0) break; //LookupMove m = q.Dequeue(); LookupMove m = GetNext(conn); if (m == null) break; LookupMove[] newMoves = new LookupMove[] { m.next(0,'U'),m.next(1,'U'), m.next(2,'U'), m.next(0,'D'),m.next(1,'D'), m.next(2,'D'), m.next(0,'R'),m.next(1,'R'), m.next(2,'R'), m.next(0,'L'),m.next(1,'L'), m.next(2,'L') }; for (int i = 0; i < newMoves.Length; i++) { try { ExecuteDbCommand("INSERT INTO block_colors (pos,move,num_steps,checked) VALUES ('" + newMoves[i].pos + "','" + newMoves[i].move + "','" + newMoves[i].level + "','0');", conn); count++; lastLevel = newMoves[i].level; //if (newMoves[i].level < 25) q.Enqueue(newMoves[i]); } catch (SQLiteException e) { } } ExecuteDbCommand("UPDATE block_colors SET checked='1' WHERE pos='" + m.pos + "'", conn); } isRunning = false; Console.WriteLine("DONE"); Console.ReadLine(); }