public RouteCondition(CheckFunc condition, object data){ if (condition == null) { throw new ArgumentException("condition may not be null"); } Condition = condition; Data = data; }
private static int PlayGame(char[][] map, CheckFunc func, int peepCount) { bool settled = false; while (!settled) { (map, settled) = PlayRound(map, func, peepCount); } return(map.SelectMany(x => x).Count(x => x == '#')); }
private static (char[][] Map, bool Settled) PlayRound(char[][] map, CheckFunc func, int peepCount) { char[][] newMap = new char[map.Length][]; bool settled = true; for (int y = 0; y < map.Length; y++) { newMap[y] = new char[map[y].Length]; for (int x = 0; x < map[y].Length; x++) { char next = GetNext(map[y][x], GetCount(map, x, y, func), peepCount); if (map[y][x] != next) { settled = false; } newMap[y][x] = next; } } return(newMap, settled); }
static void Main(string[] args) { Console.Title = "LMAOnline v4.2 - GSN Edition"; Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; GlobalFunc.iniReadHandle(); CheckFunc.checkfolders(); CheckFunc.loadXeX(); if (!CheckFunc.LoadBinFiles()) { GlobalFunc.Write("Failed to load proper bin files!"); GlobalFunc.DelayedRestart(3, true); return; } if (!CheckFunc.CheckMySQL()) { GlobalFunc.Write("MySQL Connection Error!"); GlobalFunc.DelayedRestart(3); return; } Console.Clear(); Console.WriteLine("\n ///////////////////////////////////"); Console.WriteLine(" // LMAOnline V4 Has Been Started //"); Console.WriteLine(" ///////////////////////////////////"); Console.WriteLine(" ///////////////////////"); Console.WriteLine(" // This Shit's Funny //"); Console.WriteLine(" ///////////////////////"); Console.WriteLine(" _____________________________"); Console.WriteLine(" Thread: Starting... SUCCESS"); Console.WriteLine(" Port: {0}... SUCCESS", GlobalVar.i_svrPort.ToString()); Console.WriteLine(" chal_resp Bytes: {0}", GlobalVar.by_chalBytes.Length); Console.WriteLine(" HV Bytes: {0}", GlobalVar.by_hvBytes.Length); Console.WriteLine(" xexChecks: {0}", GlobalVar.b_overRideChecks.ToString().ToUpper()); Console.WriteLine(" Using .ini: {0}", GlobalVar.b_usingINI.ToString().ToUpper()); Console.WriteLine(" _____________________________\n\n"); Console.WindowWidth = 100; Console.WindowHeight = Console.LargestWindowHeight; Console.Title = String.Format("{0} [#] Listening: {1} [#] Server: {2}", Console.Title, GlobalVar.i_svrPort, GlobalVar.s_dbName.ToUpper()); new Handle(); GlobalVar.TimeStarted = DateTime.Now; }
/// <summary> /// Performs Linear Sweep calculation for distance fields. /// Note that it requires two passes to calculate negative and positive distance fields /// </summary> /// <param name="pixelData">input pixels</param> /// <param name="imageWidth">width</param> /// <param name="imageHeight">heigth</param> /// <param name="closestPoints">output array with Voronoi point indices</param> /// <param name="extraPass">perform additional sanity check pass</param> /// <returns>array of nearest distances</returns> public static float[] AnalyzeGrayscale <T>(T[] pixelData, int imageWidth, int imageHeight, CheckFunc <T> checker, int[] closestPoints = null, bool extraPass = true, bool normalize = true) { #if PROFILE System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); #endif Vector3i[] points = new Vector3i[pixelData.Length]; // pre processing - fill the array with int.MaxValue for empty cells and 0 with occupied int index = 0; for (ushort y = 0; y < imageHeight; y++) { for (ushort x = 0; x < imageWidth; x++) { points[index] = new Vector3i(x, y, checker(pixelData[index]) ? 0 : int.MaxValue); index++; } } #if PROFILE sw.Stop(); Console.WriteLine("Pre processing: {0}", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); #endif // forward processing. We need to skip first row and column so it's easier to have two loops for that for (int y = 1; y < imageHeight; y++) { for (int x = 1; x < imageWidth; x++) { index = x + y * imageWidth; if (points[index].Z <= 1) { continue; } CheckObstacle(ref points[index], x, y, points[index - 1]); // x - 1 CheckObstacle(ref points[index], x, y, points[index - imageWidth]); // y - 1 CheckObstacle(ref points[index], x, y, points[index - imageWidth - 1]); // x - 1, y - 1 if (x < imageWidth - 1) { CheckObstacle(ref points[index], x, y, points[index - imageWidth + 1]); // x + 1, y - 1 } } } #if PROFILE sw.Stop(); Console.WriteLine("Forward processing: {0}", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); #endif //backward processing. We need to skip last row and column for (int y = imageHeight - 2; y >= 0; y--) { for (int x = imageWidth - 2; x >= 0; x--) { index = x + y * imageWidth; if (points[index].Z <= 1) { continue; } CheckObstacle(ref points[index], x, y, points[index + 1]); // x + 1 CheckObstacle(ref points[index], x, y, points[index + imageWidth]); // y + 1 CheckObstacle(ref points[index], x, y, points[index + imageWidth + 1]); // x + 1, y + 1 if (x > 0) { CheckObstacle(ref points[index], x, y, points[index + imageWidth - 1]); // x - 1, y + 1 } } } #if PROFILE sw.Stop(); Console.WriteLine("Backward processing: {0}", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); #endif if (extraPass) { // final pass. sometimes needed for (int y = 1; y < imageHeight - 1; y++) { for (int x = 1; x < imageWidth - 1; x++) { index = x + y * imageWidth; if (points[index].Z <= 1) { continue; } CheckObstacle(ref points[index], x, y, points[index - 1]); // x - 1 CheckObstacle(ref points[index], x, y, points[index - imageWidth]); // y - 1 CheckObstacle(ref points[index], x, y, points[index - imageWidth - 1]); // x - 1, y - 1 CheckObstacle(ref points[index], x, y, points[index - imageWidth + 1]); // x + 1, y - 1 CheckObstacle(ref points[index], x, y, points[index + 1]); // x + 1 CheckObstacle(ref points[index], x, y, points[index + imageWidth]); // y + 1 CheckObstacle(ref points[index], x, y, points[index + imageWidth + 1]); // x + 1, y + 1 CheckObstacle(ref points[index], x, y, points[index + imageWidth - 1]); // x - 1, y + 1 } } #if PROFILE sw.Stop(); Console.WriteLine("Final pass processing: {0}", sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); #endif } else { // process corners CheckObstacle(ref points[0], 1, 0, points[imageWidth + 1]); // (0, 0) CheckObstacle(ref points[imageWidth - 1], imageWidth - 1, 0, points[imageWidth - 2]); // (imagewidth - 1, 0) CheckObstacle(ref points[imageWidth * (imageHeight - 1)], 0, imageHeight - 1, points[imageWidth * (imageHeight - 1) + 1]); // (0, imageheight - 1) CheckObstacle(ref points[imageWidth - 1 + imageWidth * (imageHeight - 1)], imageWidth - 1, imageHeight - 1, points[imageWidth * (imageHeight - 1) + imageWidth - 2]); // (imagewidth - 1, imageheight - 1) } // distance calculation float[] values = new float[points.Length]; if (normalize) { for (int i = 0; i < points.Length; i++) { values[i] = (float)Math.Sqrt(points[i].Z); // calculate correct distance } } else { for (int i = 0; i < points.Length; i++) { values[i] = points[i].Z; // leave squared distance } } #if PROFILE sw.Stop(); Console.WriteLine("Distance calculation: {0}", sw.ElapsedMilliseconds); #endif if (closestPoints != null) { for (int i = 0; i < points.Length; i++) { closestPoints[i] = points[i].X + points[i].Y * imageWidth; } } return(values); }
public LogicNode(CheckFunc func, string[] arg0) { this.func = func; this.arg0 = arg0; }
private static int GetCount(char[][] map, int x, int y, CheckFunc func) => CountAllDirections((xOff, yOff) => func(map, x, y, xOff, yOff));
public RouteCondition(CheckFunc condition) : this(condition, null){ }
public CheckFunWrap(CheckFunc func, int argNeed) { this.func = func; this.argNeed = argNeed; }