static int[,] bfs(char[][] board, int[,] visited, vec root, vec start, vec end, int count, int countToCheck = 0) { Queue <vec> Q = new Queue <vec>(); visited[root.x, root.y] = count; Q.Enqueue(root); //Console.Write("\nIn bfs with root ("+root.x+","+root.y+")"); while (Q.Count > 0) { var current = Q.Dequeue(); var neighbours = getNeighbours(current, start, end); //Console.Write("\nNeighbours of ("+current.x+","+current.y+")"+board[current.x][current.y]+" are "); //foreach(var nb in neighbours) // Console.Write(" ("+nb.x+","+nb.y+")"/*+board[nb.x][nb.y]*/); foreach (var nb in neighbours) { if (visited[nb.x, nb.y] == countToCheck && board[current.x][current.y] == board[nb.x][nb.y]) { visited[nb.x, nb.y] = count; Q.Enqueue(nb); //Console.Write(" ("+nb.x+","+nb.y+")"+board[nb.x][nb.y]); } } //Console.WriteLine("HERE"); } return(visited); }
static int[,] bfs(char[][] board, int[,] visited, int i, int j, int x1, int y1, int x2, int y2) { Queue <vec> Q = new Queue <vec>(); var root = new vec(i, j); visited[i, j] = 1; Q.Enqueue(root); while (Q.Count > 0) { var current = Q.Dequeue(); var neighbours = getNeighbours(current, x1, y1, x2, y2); //Console.Write("\nNeighbours of ("+current.x+","+current.y+")"+board[current.x][current.y]+" are "); foreach (var n in neighbours) { //Console.Write(" ("+n.x+","+n.y+")"+board[n.x][n.y]); if (visited[n.x, n.y] == 0 && board[current.x][current.y] == board[n.x][n.y]) { visited[n.x, n.y] = 1; Q.Enqueue(n); //Console.Write(" ("+n.x+","+n.y+") "); } } //Console.WriteLine("HERE"); } return(visited); }
public static unsafe int Run() { if (!Sse2.IsSupported) { return(0); } vec v = new vec(); Vector128 <int> o = Vector128.Create(1); int vr16 = v.y; Sse2.Store(&v.x, o); return(vr16); }
static List <vec> getNeighbours(vec current, vec start, vec end) { List <vec> nec = new List <vec>(); int lx, ly, gx, gy; lx = current.x - 1; ly = current.y - 1; gx = current.x + 1; gy = current.y + 1; if (gx <= end.x) { nec.Add(new vec(gx, current.y)); if (gy <= end.y) { nec.Add(new vec(gx, gy)); nec.Add(new vec(current.x, gy)); } } else if (gy <= end.y) { nec.Add(new vec(current.x, gy)); } if (ly >= start.y) { nec.Add(new vec(current.x, ly)); if (lx >= start.x) { nec.Add(new vec(lx, ly)); nec.Add(new vec(lx, current.y)); } } else if (lx >= start.x) { nec.Add(new vec(lx, current.y)); } return(nec); }
static List <vec> getNeighbours(vec current, int x1, int y1, int x2, int y2) { List <vec> nec = new List <vec>(); int li, lj, gi, gj; li = current.x - 1; lj = current.y - 1; gi = current.x + 1; gj = current.y + 1; if (lj >= y1) { nec.Add(new vec(current.x, lj)); if (li >= x2) { nec.Add(new vec(li, lj)); nec.Add(new vec(li, current.y)); } } else if (li >= x2) { nec.Add(new vec(li, current.y)); } if (gi <= x1) { nec.Add(new vec(gi, current.y)); if (gj <= y2) { nec.Add(new vec(gi, gj)); nec.Add(new vec(current.x, gj)); } } else if (gj <= y2) { nec.Add(new vec(current.x, gj)); } return(nec); }
public Color getcolor(double x, double y) { vec z = new vec(x, y); z = plus(z.Umn(z, z), con); int q; for (q = 0; q < 160; q++) { double asb = z.abs(z); //if (q > ) if (asb > 2) { if (q > 80) { return(Color.FromArgb(255 - norm(100 - q * 4), 255 - norm(100 + q * 4), 255 - norm(100 + q * 6))); } return(Color.FromArgb(norm(100 - q * 4), norm(100 + q * 4), norm(100 + q * 6))); } z = plus(z.Umn(z, z), con); } return(Color.FromArgb(180, 15, 120)); }
private static int dist(int x, int y, vec v) => Max(Abs(x - v.x), Abs(y - v.y));
/** * Sets the entity's current location vector (i.e. teleports the entity). */ void SetLocation(vec);
return(getTerrainPos(vec, CommonSetting.findTerrainHeight));
/// <summary> /// Returns the component-wise compare of x >= y. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> protected bvec greaterThanEqual(vec x, vec y) { throw new NotImplementedException(); }
/// <summary> /// Returns the component-wise compare of x < y. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> protected bvec lessThan(vec x, vec y) { throw new NotImplementedException(); }
public double abs(vec a1) { return(Math.Sqrt(a1.a * a1.a + a1.b * a1.b)); }
/// <summary> /// Returns the component-wise compare of x == y. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> protected bvec equal(vec x, vec y) { throw new NotImplementedException(); }
static void Main(String[] args) { int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32); int n = temp[0]; int m = temp[1]; char[][] board = new char[n][]; for (int board_i = n - 1; board_i >= 0; board_i--) { string board_temp = Console.ReadLine(); board[board_i] = board_temp.ToCharArray(); } int q = Convert.ToInt32(Console.ReadLine()); int[,] visited = new int[n, m]; int count = 0; vec start = new vec(0, 0); vec end = new vec(n - 1, m - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (visited[i, j] == 0) { count++; visited = bfs(board, visited, new vec(i, j), start, end, count); } } } /* for(int i = 0; i < n; i++) * { * for(int j = 0; j < m; j++) * Console.Write(board[i][j] + " "); * Console.WriteLine(); * }*/ for (int a0 = 0; a0 < q; a0++) { string[] tokens_x1 = Console.ReadLine().Split(' '); int x2 = n - Convert.ToInt32(tokens_x1[0]); int y1 = Convert.ToInt32(tokens_x1[1]) - 1; int x1 = n - Convert.ToInt32(tokens_x1[2]); int y2 = Convert.ToInt32(tokens_x1[3]) - 1; int[,] visit = (int[, ])visited.Clone(); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { //Console.WriteLine("("+x+","+y+")"); if (x != x2 && y != y1 && visit[x, y] == visit[x + 1, y - 1]) { visit = bfs(board, visit, new vec(x + 1, y - 1), new vec(x1, y1), new vec(x2, y2), count, visit[x, y]); count++; } } //Console.WriteLine("HERE in outer loop"); } var hash = new HashSet <int>(); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { hash.Add(visit[x, y]); } //Console.WriteLine("HERE in outer loop"); } //Console.WriteLine("x and y "+x1+y1+x2+y2); Console.WriteLine(hash.Count); } }
private static void raycast() { if (!prepTris()) { return; } int width = frame.GetLength(0); int height = frame.GetLength(1); vec[] os = new vec[width * height]; vec[] ds = new vec[width * height + 1]; ds[0] = ConsoleSettings.cameraRot.toVec(); vec eyeVec = eye.toVec(); //float f = 0.0155f / 1.75f; float f = 0.01f; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Vector pos = dir + new Vector((x - (width / 2)) * f, (y - (height / 2)) * f); //pos *= rotMat; os[x + (y * width)] = eyeVec; ds[x + (y * width) + 1] = pos.toVec(); } } List <vec> lights = new List <vec>(); if (gTris == null || gTris.Count == 0) { return; } foreach (Vector l in ConsoleRenderer.Lights) { lights.Add(l.toVec()); } lightX += 0.01f; float[] ous = new float[width * height * 3]; if (lastTriCount != gTris.Count) { origins = new ComputeBuffer <vec>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, os); dirs = new ComputeBuffer <vec>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, ds); outs = new ComputeBuffer <float>(context, ComputeMemoryFlags.WriteOnly, ous.Length); lig = new ComputeBuffer <vec>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, lights.ToArray()); } else { commands.WriteToBuffer(os, origins, false, eventList); commands.WriteToBuffer(ds, dirs, false, eventList); commands.WriteToBuffer(lights.ToArray(), lig, false, eventList); } renderKernel.SetMemoryArgument(0, gTris); renderKernel.SetMemoryArgument(1, lig); renderKernel.SetMemoryArgument(2, gOptions); renderKernel.SetMemoryArgument(3, origins); renderKernel.SetMemoryArgument(4, dirs); renderKernel.SetMemoryArgument(5, gTexture); renderKernel.SetMemoryArgument(6, outs); commands.Execute(renderKernel, null, new long[] { width *height }, null, eventList); commands.ReadFromBuffer(outs, ref ous, true, eventList); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { frame[x, y, 0] = ous[(x + (y * width)) * 3]; frame[x, y, 1] = ous[((x + (y * width)) * 3) + 1]; frame[x, y, 2] = ous[((x + (y * width)) * 3) + 2]; } } //eventList.Clear(); }
private static bool prepTris() { int width = frame.GetLength(0); int height = frame.GetLength(1); List <tris> tris = new List <tris>(); List <vec> poss = new List <vec>(); List <vec> rots = new List <vec>(); int[] options = new int[4]; vec[] cam = new vec[3]; cam[0] = eye.toVec(); Vector look = new Vector(0, 0, 1, 0); Vector up = new Vector(0, 1, 0, 0); look *= Matrix4x4.rotationXMatrix(ConsoleSettings.cameraRot.x); look *= Matrix4x4.rotationYMatrix(ConsoleSettings.cameraRot.y); cam[1] = look.toVec(); cam[2] = up.toVec(); foreach (Mesh m in ConsoleRenderer.Meshes) { foreach (Triangle t in m.tris) { tris.Add(t.toTris()); poss.Add(m.position.toVec()); rots.Add(m.rotation.toVec()); } } options[0] = tris.Count; options[1] = width; options[2] = height; if (tris.Count <= 0) { return(false); } if (lastTriCount != tris.Count) { gTris = new ComputeBuffer <tris>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, tris.ToArray()); gOptions = new ComputeBuffer <int>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, options); gCam = new ComputeBuffer <vec>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, cam); gPos = new ComputeBuffer <vec>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, poss.ToArray()); gRot = new ComputeBuffer <vec>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, rots.ToArray()); gTexture = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, texture); } else { commands.WriteToBuffer(tris.ToArray(), gTris, false, eventList); commands.WriteToBuffer(options, gOptions, false, eventList); commands.WriteToBuffer(cam, gCam, false, eventList); commands.WriteToBuffer(rots.ToArray(), gRot, false, eventList); commands.WriteToBuffer(poss.ToArray(), gPos, false, eventList); commands.WriteToBuffer(texture, gTexture, false, eventList); } prepTrisKernel.SetMemoryArgument(0, gTris); prepTrisKernel.SetMemoryArgument(1, gOptions); prepTrisKernel.SetMemoryArgument(2, gRot); prepTrisKernel.SetMemoryArgument(3, gPos); prepTrisKernel.SetMemoryArgument(4, gCam); commands.Execute(prepTrisKernel, null, new long[] { tris.Count }, null, eventList); return(true); }
/*public vec Umn(vec a, vec b) * { * return new vec(a.a * b.b, b.a * a.b); * }*/ public vec plus(vec a, vec b) { return(new vec(a.a + b.a, a.b + b.b)); }
public string solveIt(string AIMAproblem, out Model proposal) { string solution = ""; string DIMACSsolution = ""; translator.Clear(); proposal = new Model(); string DIMACSproblem = translator.AIMAToDIMACS(AIMAproblem); StringReader sr = new StringReader(DIMACSproblem); vec <Solver.Lit> lits = new vec <Solver.Lit>(); Solver S = new Solver(); Solver.solverReport = ""; for (; ;) { lits.clear(); string w; while ((w = ReadWordStatic(sr)) != null) { if (w == "%") { break; } int parsed_lit = int.Parse(w); if (parsed_lit == 0) { break; } int var = Math.Abs(parsed_lit) - 1; while (var >= S.nVars()) { S.newVar(); } lits.push((parsed_lit > 0) ? new Solver.Lit(var) : ~new Solver.Lit(var)); } if (w == null) { break; } S.addClause(lits); } S.verbosity = 1; S.solve(); Solver.reportf(S.okay() ? "SATISFIABLE\n" : "UNSATISFIABLE\n"); S.printStats(); /* * if (S.okay()) * { * for (int i = 0; i < S.nVars(); i++) * if ((S.model[i] != Solver.lbool.Undef0) && (S.model[i] != Solver.lbool .Undef1)) * Solver.reportf("{0}{1}\n", (S.model[i] == Solver.lbool.True) ? " " : "-", i + 1); * } */ wasSAT = S.okay(); if (S.okay()) { for (int i = 0; i < S.nVars(); i++) { if ((S.model[i] != Solver.lbool.Undef0) && (S.model[i] != Solver.lbool.Undef1)) { DIMACSsolution += String.Format("{0}{1} ", (S.model[i] == Solver.lbool.True) ? " " : "-", i + 1); } } } if (S.okay()) { for (int i = 0; i < S.nVars(); i++) { if ((S.model[i] != Solver.lbool.Undef0) && (S.model[i] != Solver.lbool.Undef1)) { //DIMACSsolution += String.Format("{0}{1} ", (S.model[i] == Solver.lbool.True) ? " " : "-", i + 1); if (S.model[i] == Solver.lbool.True) { proposal = proposal.Extend(translator.varName(i + 1), true); Console.WriteLine("+{0}", translator.varName(i + 1)); } else { proposal = proposal.Extend(translator.varName(i + 1), false); //Console.WriteLine("-{0}", translator.varName(i + 1)); } } } } solution = translator.DIMACSToAIMA(DIMACSsolution); solverReport = Solver.solverReport; return(solution); }
/// <summary> /// Returns the component-wise compare of x != y. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> protected bvec notEqual(vec x, vec y) { throw new NotImplementedException(); }
public static void Main(string[] args) { if (args.Length < 1) { Console.Error.WriteLine("usage: minisat [-s|-u] <file1.cnf> ..."); return; } bool expect = false; bool expect_res = false; int pos = 0; if (args[pos] == "-s") { expect = true; expect_res = true; pos++; } if (args[pos] == "-u") { expect = true; expect_res = false; pos++; } for (; pos < args.Length; pos++) { StreamReader sr = File.OpenText(args[pos]); vec <Solver.Lit> lits = new vec <Solver.Lit>(); Solver S = new Solver(); for (;;) { lits.clear(); string w; while ((w = ReadWord(sr)) != null) { if (w == "%") { break; } int parsed_lit = int.Parse(w); if (parsed_lit == 0) { break; } int var = Math.Abs(parsed_lit) - 1; while (var >= S.nVars()) { S.newVar(); } lits.push((parsed_lit > 0) ? new Solver.Lit(var) : ~new Solver.Lit(var)); } if (w == null) { break; } S.addClause(lits); } if (expect) { S.verbosity = 0; S.solve(); if (S.okay() == expect_res) { Solver.reportf("."); } else { Solver.reportf("\nproblem: {0}\n", args[pos]); } } else { S.verbosity = 1; S.solve(); Solver.reportf(S.okay() ? "SATISFIABLE\n" : "UNSATISFIABLE\n"); S.printStats(); } #if false if (S.okay()) { for (int i = 0; i < S.nVars(); i++) { if (S.model[i] != l_Undef) { Solver.reportf("{0}{1}\n", (S.model[i] == l_True)?" ":"-", i + 1); } } } #endif } }
public vec Umn(vec a1, vec b1) { return(new vec(a1.a * b1.a - a1.b * b1.b, a1.a * b1.b + b1.a * a1.b)); }