public SearchNode(Data.System System, int cost, int pathCost, SearchNode next) { this.System = System; this.cost = cost; this.pathCost = pathCost; this.next = next; }
private Rectangle GetSystemScreenRect(Data.System system, Rectangle ScreenRectangle, int DrawSize) { var WorldPosition = (system.Coordinates - WorldOffset).RotateY(WorldRotationY); var ScreenPos = Translate(WorldPosition) + new Vector((ScreenRectangle.Width), (ScreenRectangle.Height)); //new Vector(system.Coordinates.Z, system.Coordinates.X) - Position; return(new Rectangle((int)((ScreenPos.X - ScreenRectangle.Width / 2)), (int)((ScreenPos.Y - ScreenRectangle.Height / 2)), DrawSize, DrawSize)); }
private static Data.System CreateSystemFromDatabase(XDocument document) { var header = document.Descendants("header").ToList(); if (header.Count == 0) { Console.WriteLine("System name not found in database."); return(null); } var systemName = header[0].Element("listname").Value; try { var system = SystemService.GetByName(systemName); Console.WriteLine("System already exists"); return(system); } catch (SystemNotFoundException) { Console.WriteLine($"Importing {systemName}"); var system = new Data.System { Name = systemName }; DataStore.Systems.Add(system); DataStore.SaveChanges(); return(SystemService.GetByName(systemName)); } }
private static void CreateGamesFromDatabase(Data.System system, XDocument document) { var gameElements = document.Descendants("game").ToList(); if (gameElements.Count > 0) { var gamesImported = 0; var duplicateGames = 0; foreach (var gameElement in gameElements) { if (CreateGame(system, gameElement)) { gamesImported++; } else { duplicateGames++; } DataStore.SaveChanges(); } Console.WriteLine($"{gameElements.Count} games found. {gamesImported} games imported. {duplicateGames} duplicate games skipped."); } else { Console.WriteLine("No games were found in the XML Database."); } }
private static SearchNode FindPathReversed(Data.System start, Data.System end, int MaxJumpCount = 0) { SearchNode startNode = new SearchNode(start, 0, 0, null); MinHeap openList = new MinHeap(); openList.Add(startNode); bool[] brWorld = new bool[GlobalData.Systems.Count - 1]; brWorld[GlobalData.Systems.FindIndex(a => a == start)] = true; int Jumps = 0; while (openList.HasNext()) { if (MaxJumpCount > 0 && Jumps >= MaxJumpCount) { return(null); } SearchNode current = openList.ExtractFirst(); if ((current.System.Coordinates - end.Coordinates).Length <= 3) { return(new SearchNode(end, current.pathCost + 1, current.cost + 1, current)); } var surroundings = surrounding(current.System); for (int i = 0; i < surroundings.Length; i++) { Surr surr = surroundings[i]; int brWorldIdx = GlobalData.Systems.FindIndex(a => a == surr.System); if (brWorld[brWorldIdx] == false) { brWorld[brWorldIdx] = true; int pathCost = current.pathCost + surr.Cost; int cost = pathCost + (int)(surr.System.Coordinates - end.Coordinates).Length; SearchNode node = new SearchNode(surr.System, cost, pathCost, current); openList.Add(node); Jumps++; } } } return(null); //no path found }
private static bool CreateGame(Data.System system, XElement gameElement) { var gameName = gameElement.Attribute("name")?.Value; if (GameService.Exists(gameName)) { return(false); } Console.WriteLine($"Importing {gameName}"); var genre = gameElement.Element("genre")?.Value; var manufacturer = gameElement.Element("manufacturer")?.Value; var rating = gameElement.Element("rating")?.Value; var game = new Game { Name = gameName, Description = gameElement.Element("description")?.Value, Crc = gameElement.Element("crc")?.Value, Manufacturer = manufacturer, Genre = genre, Rating = gameElement.Element("rating")?.Value, CloneOf = gameElement.Element("cloneof")?.Value, Enabled = gameElement.Element("enabled")?.Value.ToUpper() == "YES", System = system }; int year; if (int.TryParse(gameElement.Element("year")?.Value, out year)) { game.Year = year; AddTag(game, year.ToString()); } AddTag(game, system.Name); AddTag(game, genre); AddTag(game, manufacturer); AddTag(game, rating); GameService.Add(game); return(true); }
public Main(Data.System System) { InitializeComponent(); ApplyStyle(); this.DisplaySystem = System; this.Text = System.name; this.lName.Text = System.name; this.lGovernment.Text = System.government; this.lFaction.Text = System.power == "" ? "Uncontrolled" : System.power; this.lEconomy.Text = System.primary_economy; this.lPermit.Text = System.needs_permit ? "Yes" : "No special permit needed"; this.lPopulation.Text = string.Format("{0:n0}", System.population); this.lSecurity.Text = System.security; this.lState.Text = System.state; this.lCoordinates.Text = System.Coordinates.ToString(); this.lSOL.Text = string.Format("{0:n} Ly", System.Coordinates.Length); this.lDistCurrent.Text = UserData.System != null?string.Format("{0:n} Ly", (UserData.System.Coordinates - System.Coordinates).Length) : "unknown"; this.lNotes.Text = System.note == "" ? "-" : System.note; this.dataGridView1.DataSource = System.Stations; }
/// <summary> /// Method that switfly finds the best path from start to end. /// </summary> /// <returns>The starting breadcrumb traversable via .next to the end or null if there is no path</returns> /*public static SearchNode FindPath(World world, Point3D start, Point3D end) * { * //note we just flip start and end here so you don't have to. * return FindPathReversed(world, end, start); * } * * /// <summary> * /// Method that switfly finds the best path from start to end. Doesn't reverse outcome * /// </summary> * /// <returns>The end breadcrump where each .next is a step back)</returns> * private static SearchNode FindPathReversed(World world, Point3D start, Point3D end) * { * SearchNode startNode = new SearchNode(start, 0, 0, null); * * MinHeap openList = new MinHeap(); * openList.Add(startNode); * * int sx = world.Right; * int sy = world.Top; * int sz = world.Back; * bool[] brWorld = new bool[sx * sy * sz]; * brWorld[start.X + (start.Y + start.Z * sy) * sx] = true; * * while (openList.HasNext()) * { * SearchNode current = openList.ExtractFirst(); * * if (current.position.GetDistanceSquared(end) <= 3) * { * return new SearchNode(end, current.pathCost + 1, current.cost + 1, current); * } * * for (int i = 0; i < surrounding.Length; i++) * { * Surr surr = surrounding[i]; * Point3D tmp = new Point3D(current.position, surr.Point); * int brWorldIdx = tmp.X + (tmp.Y + tmp.Z * sy) * sx; * * if (world.PositionIsFree(tmp) && brWorld[brWorldIdx] == false) * { * brWorld[brWorldIdx] = true; * int pathCost = current.pathCost + surr.Cost; * int cost = pathCost + tmp.GetDistanceSquared(end); * SearchNode node = new SearchNode(tmp, cost, pathCost, current); * openList.Add(node); * } * } * } * return null; //no path found * }*/ public static SearchNode FindPath(Data.System start, Data.System end, int MaxJumpCount = 0) { //note we just flip start and end here so you don't have to. return(FindPathReversed(end, start, MaxJumpCount)); }
//Neighbour options private static Surr[] surrounding(Data.System System) { return((from sSystem in GlobalData.Systems where (System.Coordinates - sSystem.Coordinates).Length < UserData.Max_Jump_Distance select new Surr(sSystem)).ToArray()); }
public Surr(Data.System System) { this.System = System; Cost = 0; }
public Data.System Add(Data.System system) { _store.Systems.Add(system); return(system); }