/// <summary> /// Find the shortest trace from -> to in map (M matrix) /// M[i,j] = 0 or 1 /// M[i,j] = 1 <-> M[i,j] is enable for moving /// Heuristic function H(x) = length of vector (x - to) /// </summary> /// <param name="M">Map matrix</param> /// <param name="from">Start point</param> /// <param name="to">End point</param> /// <param name="X">Size of collum</param> /// <param name="Y">Size of row</param> /// <returns></returns> public static List <Vector2> MinTrace(int[,] M, Vector2 from, Vector2 to, int X, int Y) { int n = X * Y; float[,] C = new float[n, n]; for (int i = 0; i < Y; i++) { for (int j = 0; j < X; j++) { if (M[i, j] == 1) { if (i > 0) { if (M[i - 1, j] == 1) { C[i * X + j, (i - 1) * X + j] = 1; } } if (i < Y - 1) { if (M[i + 1, j] == 1) { C[i * X + j, (i + 1) * X + j] = 1; } } if (j > 0) { if (M[i, j - 1] == 1) { C[i * X + j, i *X + j - 1] = 1; } } if (j < X - 1) { if (M[i, j + 1] == 1) { C[i * X + j, i *X + j + 1] = 1; } } } } } FastTrace fast = new FastTrace(C, n, from.y * X + from.x, to.y * X + to.x, X, Y); List <int> result = fast.MinTrace(); if (result == null) { return(null); } List <Vector2> result_ = new List <Vector2>(); foreach (int q in result) { Vector2 v = new Vector2(q % X, q / X); result_.Add(v); } return(result_); }
public override void DidFinishLaunching(NSNotification notification) #endif { var args = new string[0]; FastTrace.WriteLine("Startup: Reached AppDelegate.DidFinishLaunching / AppDelegate.FinishedLaunching"); ErrorProtection.RunEarly(() => ProtectedStartup(args)); ErrorProtection.RunMain(_kernel.TryGet <IErrorReport>(), ProtectedRun); }
public static void Main(string[] args) { if (args.Contains("--debug-startup")) { FastTrace.EmitStartupTrace = true; } NSApplication.Init(); FastTrace.WriteLine("Startup: Finished NSApplication.Init in static Main"); using (var p = new NSAutoreleasePool()) { NSApplication.SharedApplication.Delegate = new AppDelegate(); // TODO: Offer a way of setting the application icon. //NSImage appIcon = NSImage.ImageNamed("monogameicon.png"); //NSApplication.SharedApplication.ApplicationIconImage = appIcon; NSApplication.Main(args); } }
/// <summary> /// Find the shortest trace from S point to T point with cost matrix C /// </summary> /// <param name="C">Cost matrix</param> /// <param name="n">Count point</param> /// <param name="S">Start point</param> /// <param name="T">End point</param> /// <param name="Heuristic">Heuristic function H(x)</param> /// <returns></returns> public static List <int> MinTrace(float[,] C, int n, int S, int T, Heuristic Heuristic) { FastTrace fast = new FastTrace(C, n, S, T, Heuristic); return(fast.MinTrace()); }
static void Main(string[] args) { float[,] C = new float[n, n]; for (int i = 0; i < Y; i++) { for (int j = 0; j < X; j++) { if (M[i, j] == 1) { if (i > 0) { if (M[i - 1, j] == 1) { C[i * X + j, (i - 1) * X + j] = 1; } } if (i < Y - 1) { if (M[i + 1, j] == 1) { C[i * X + j, (i + 1) * X + j] = 1; } } if (j > 0) { if (M[i, j - 1] == 1) { C[i * X + j, i *X + j - 1] = 1; } } if (j < X - 1) { if (M[i, j + 1] == 1) { C[i * X + j, i *X + j + 1] = 1; } } } } } Console.WriteLine("==============================================="); List <Vector2> min = FastTrace.MinTrace(M, new Vector2(5, 1), new Vector2(1, 8), X, Y); if (min != null) { foreach (Vector2 q in min) { Console.WriteLine("(y,x):" + q.y + "," + q.x); } } else { Console.WriteLine("null"); } Console.WriteLine("==============================================="); List <int> min2 = FastTrace.MinTrace(C, n, S, T, Heuristic); if (min2 != null) { foreach (int q in min2) { Console.WriteLine("(y,x):" + q / X + "," + q % X); } } else { Console.WriteLine("null"); } Console.WriteLine("==============================================="); }