/// <summary> /// Method for creating a view model of a user list /// </summary> /// <param name="users">users</param> /// <param name="totalCount">total counts</param> /// <param name="totalPages">total pages</param> /// <returns></returns> public static UserListVm Create(IEnumerable <UserListItemVm> users, RegionNode allRegions, int totalCount, int totalPages) => new UserListVm { Result = users, AllRegions = allRegions, TotalCount = totalCount, TotalPages = totalPages, };
private RegionNode(Region CurrentRegion, float Score, RegionNode Parent) { this.currentRegion = CurrentRegion; this.score = Score; this.parent = Parent; }
public RegionNode CreateNode(RegionModel regionModel) { var result = new RegionNode(regionModel.Name); foreach (var residentModel in regionModel.Residents) { var node = this.CreateNodeOnceResolved(residentModel); result.RegisterResident(node); } return(result); }
public RegionModel CreateRegion(Computations computations, RegionNode node) { var residents = new List <IRegionModelResident>(); foreach (var child in node.GetResidents()) { var model = this.CreateModelOnceResolved(computations, child); residents.Add(model); } var result = this.modelBuilder.CreateRegionModel( node.Name, computations.BaseActiveFormula, residents ); return(result); }
/// <summary> /// Creates the map object. /// </summary> /// <param name="regionId">The region identifier.</param> /// <param name="languageKey">The language key.</param> /// <returns> /// Boolean result true if new object was created. /// </returns> public bool CreateMapObject(int regionId, string languageKey) { if (string.IsNullOrEmpty(languageKey)) { return false; } if (regionId != 0) { var cityNode = new CityNode { LanguageKey = languageKey, RegionNodeId = regionId }; DataContext.AddDataObject(cityNode); } else { var regionNode = new RegionNode { LanguageKey = languageKey }; DataContext.AddDataObject(regionNode); } try { DataContext.SaveChanges(); } catch (Exception) { return false; } return true; }
public RegionNode(Region region = null, RegionNode parent = null) { this.region = region ?? new Region(); this.parent = parent; }
/// <summary> /// Creates the translation with region node. /// </summary> /// <param name="objectTranslationData">The object translation data.</param> public void CreateTranslationWithRegionNode(MapObjectTranslationData objectTranslationData) { if (objectTranslationData.CityNodeId != 0) { return; } if (!DataContext.RegionNodes.Any(e => e.LanguageKey == objectTranslationData.LanguageKey)) { var newCity = new RegionNode { LanguageKey = objectTranslationData.LanguageKey }; DataContext.AddDataObject(newCity); DataContext.SaveChanges(); } var newTranslation = new MapObjectTranslation { LanguageKey = objectTranslationData.LanguageKey, LanguageId = objectTranslationData.LanguageId, Value = objectTranslationData.Value }; DataContext.AddTranslationObject(newTranslation); DataContext.SaveChanges(); }
public static RegionNode CreateNode(Region CurrentRegion, float Score, RegionNode parent) { return(new RegionNode(CurrentRegion, Score, parent)); }
private IEnumerable <Region> GetPathAStar(Region startRegion, Region targetRegion, Faction fac, float fortLimit) { this.DoneRegion = new Dictionary <int, int>(); BetterPQueue <RegionNode> Queue = new BetterPQueue <RegionNode>(); var startnode = RegionNode.CreateNode(startRegion, 0f, null); Queue.Push(startnode, startnode.Score); var breaK = false; while (!Queue.isEmpty()) { var node = Queue.getMin(); if (node.CurrentRegion.Equals(targetRegion)) { Queue.Push(node, node.Score); while (node != null) { yield return(node.CurrentRegion); node = node.Parent; } break; } if (!DoneRegion.ContainsKey(node.CurrentRegion.id)) { this.DoneRegion.Add(node.CurrentRegion.id, 1); } if (node.CurrentRegion.links.Count == 2) { List <Region> temp = new List <Region>(); var region = node.CurrentRegion; DoneRegion.Remove(region.id); while (region.links.Count == 2) { if (region.id == targetRegion.id) { while (temp.Count != 0) { yield return(temp.Last()); temp.RemoveLast(); } while (node != null) { yield return(node.CurrentRegion); node = node.Parent; } breaK = true; break; } if (breaK) { break; } if (DoneRegion.ContainsKey(region.id)) { break; } DoneRegion.Add(region.id, 1); if (!DoneRegion.ContainsKey(GetRegionLink(region, region.links.ToList()[0]).id)) { temp.Add(GetRegionLink(region, region.links.First())); region = GetRegionLink(region, region.links.First()); } else if (!DoneRegion.ContainsKey(GetRegionLink(region, region.links.ToList()[1]).id)) { temp.Add(GetRegionLink(region, region.links.First())); region = GetRegionLink(region, region.links.First()); } else { break; } } if (!breaK) { if (region.links.Count > 2) { var sumSight = (float)pawns.FindAll((obj) => temp.Contains(obj.GetRegion())).Count * 100; foreach (Region r in temp) { sumSight += StudyObjectsCount(r) + StudyWalkSpeedRegion(r); } var Rtemp = RegionNode.CreateNode(temp[0], sumSight + (float)GetOclicdianDistanceRegionAtoB(temp[0], targetRegion) + (float)GetOclicdianDistanceRegionAtoB(temp[0], node.CurrentRegion) , node); temp.RemoveAt(0); while (temp.Count > 0) { Rtemp = RegionNode.CreateNode(temp[0], sumSight + (float)GetOclicdianDistanceRegionAtoB(temp[0], targetRegion) + (float)GetOclicdianDistanceRegionAtoB(temp[0], Rtemp.CurrentRegion) , Rtemp); temp.RemoveAt(0); } Queue.Push(Rtemp, Rtemp.Score); } else if (region.links.Count == 1) { continue; } } } else { foreach (RegionLink link in node.CurrentRegion.links) { var newregion = GetRegionLink(node.CurrentRegion, link); if (DoneRegion.ContainsKey(newregion.id)) { continue; } var temp = RegionNode.CreateNode(newregion, StudyRegion( newregion, fac, fortLimit) + node.Score + (float)GetOclicdianDistanceRegionAtoB(newregion, targetRegion) + (float)GetOclicdianDistanceRegionAtoB(newregion, node.CurrentRegion) + 10f , node); Queue.Push(temp, temp.Score); } foreach (IntVec3 cell in new IntVec3[] { //node.CurrentRegion.extentsLimit.TopRight //,node.CurrentRegion.extentsLimit.BottomLeft //,node.CurrentRegion.extentsLimit.Cells.First() //,node.CurrentRegion.extentsLimit.Cells.Last(), //TODO Need to be Tested for which one is right LOL node.CurrentRegion.extentsClose.TopRight , node.CurrentRegion.extentsClose.BottomLeft , node.CurrentRegion.extentsClose.Cells.First() , node.CurrentRegion.extentsClose.Cells.Last() }) { if (cell.IsValid) { continue; } if (!cell.Walkable(map)) { continue; } if (cell.GetRegion(map) == null) { continue; } if (DoneRegion.ContainsKey(cell.GetRegion(map).id)) { continue; } var temp = RegionNode.CreateNode(cell.GetRegion(map), StudyRegion( cell.GetRegion(map), fac, fortLimit) + node.Score + (float)GetOclicdianDistanceRegionAtoB(cell.GetRegion(map), targetRegion) + (float)GetOclicdianDistanceRegionAtoB(cell.GetRegion(map), node.CurrentRegion) , node); Queue.Push(temp, temp.Score); } } if (breaK) { break; } } yield return(null); }
public void Resolve(RegionNode node) { this.ResultOpt = null; }
protected void FillRegions(RegionNode[][] regions) { foreach (RegionNode[] regionArray in regions) { foreach (RegionNode node in regionArray) { Entity entityToAdd = null; if (rand.NextDouble() < 0.00) { var newFood = new Food(node.ContainedRegion.RegionBounds.Location); newFood.Location = node.ContainedRegion.RegionBounds.Location + new Autonomy.Model.Utility.Geometry.Vector2D(1, 1); entityToAdd = newFood; } else if (rand.NextDouble() < 1.50) { var newTrogo = new Trogo(node.ContainedRegion.RegionBounds.Location); newTrogo.Location = node.ContainedRegion.RegionBounds.Location + new Autonomy.Model.Utility.Geometry.Vector2D(1, 1); entityToAdd = newTrogo; } if (entityToAdd != null) { node.ContainedRegion.AddEntity(entityToAdd); AllEntities.Add(entityToAdd); } } } }
protected RegionNode[][] ConstructRegions() { const float LEFT = 0.0f; const float TOP = 0.0f; const float WIDTH = 25.0f; const float HEIGHT = 25.0f; const int NUM_WIDE = 60; const int NUM_TALL = 60; RegionNode[][] regions = new RegionNode[NUM_WIDE][]; // first create all of the region nodes for (int i = 0; i < NUM_WIDE; i++) { regions[i] = new RegionNode[NUM_TALL]; for (int j = 0; j < NUM_TALL; j++) { regions[i][j] = new RegionNode() { ContainedRegion = new GridRegion(i * WIDTH + LEFT, j * HEIGHT + TOP, WIDTH, HEIGHT) }; AllGridRegions.Add(regions[i][j].ContainedRegion as GridRegion); } } // now link them together for (int i = 0; i < NUM_WIDE; i++) { for (int j = 0; j < NUM_TALL; j++) { if (i + 1 < NUM_WIDE) { regions[i][j].AddAdjacent(regions[i + 1][j]); } if (j + 1 < NUM_TALL) { regions[i][j].AddAdjacent(regions[i][j + 1]); } } } return regions; }
private void Awake() { _regionNode = GetComponent <RegionNode>(); _mapRegionSprite = GetComponent <SpriteRenderer>(); }
public Region[] findFurthestRegions(int amount) { RegionNode root = new RegionNode(region_tree_root); Stack <RegionNode> bottom = new Stack <RegionNode>(); Stack <RegionNode> top = new Stack <RegionNode>(); // traverses tree from bottom->top, pushing nodes to a stack so we can traverse them top->bottom later bottom.Push(root); while (bottom.Count > 0) { RegionNode curr = bottom.Pop(); top.Push(curr); foreach (RegionNode child in curr.children) { bottom.Push(child); } } RegionNode diameterNode = null; // root node of the subtree with the largest diameter int maxDiameter = 0; // gets the node in the region tree where the two furthest-most leaf nodes are from one another while (top.Count > 0) { RegionNode curr = top.Pop(); int diameter; // if this node is a leaf node, set height/diameter to 1 if (curr.children.Count == 0) { curr.height = 1; diameter = 1; } // if this node only has one child, set height/diameter to child height + 1 else if (curr.children.Count == 1) { curr.height = curr.children[0].height + 1; diameter = curr.height; } // otherwise, find the two tallest children, set height to the height of the tallest child, and set diameter to the sum of the tallest children + 1 else { curr.children.Sort( // sorts children by height delegate(RegionNode a, RegionNode b) { return(a.height.CompareTo(b.height)); }); curr.children.Reverse(); // sorts from tallest->smallest curr.height = curr.children[0].height + 1; diameter = curr.children[0].height + curr.children[1].height + 1; Debug.Log("diameter:" + diameter); } if (diameter > maxDiameter) { maxDiameter = diameter; diameterNode = curr; } } Debug.Log("Max diameter: " + maxDiameter); // once the diameter root has been found, get the farthest-most regions Region spawnRegion = diameterNode.find_nth_furthest_region(0); Region endRegion = diameterNode.find_nth_furthest_region(1); return(new Region[] { spawnRegion, endRegion }); }
public MainWindow() { InitializeComponent(); using (var ele = new eveLocationEntities()) { #region Regions var regions = ele.mapRegions; regions.Load(); foreach (var region in regions) { var node = new RegionNode { Name = region.regionName, NodeID = region.regionID, IsSelected = false }; _locationNodes.Nodes.Add(node); } #endregion #region Systems var systems = ele.mapSolarSystems; systems.Load(); foreach (var system in systems) { var node = new SystemNode { Name = system.solarSystemName, NodeID = system.solarSystemID, ParentNodeID = system.regionID, IsFiltered = false }; _locationNodes.Nodes.Add(node); } #endregion } using (var eie = new eveInventoryEntities()) { #region Market Groups var groups = eie.invMarketGroups; groups.Load(); //var groups = _eaw.GetMarketGroups().Result; foreach (var group in groups) { //var tmp = @group.ParentGroup?.InferredId ?? 0; var node = new MarketGroupNode { Name = group.marketGroupName, NodeID = group.marketGroupID, ParentNodeID = group.parentGroupID }; _marketItemNodes.Nodes.Add(node); } #endregion #region Market Items var items = eie.invTypes; items.Load(); //var items = _eaw.GetMarketTypes().Result; foreach (var item in items) { switch (item.marketGroupID) { case 2155: continue; case null: continue; case 354496: continue; case 354341: continue; case 356922: continue; case 354395: continue; case 354396: continue; } var node = new MarketItemNode { Name = item.typeName, NodeID = item.typeID + 2000000000000000, ParentNodeID = item.marketGroupID }; _marketItemNodes.Nodes.Add(node); } #endregion } locationTreeView.ItemsSource = _locationNodes.Nodes; locationTreeView.Columns["Name"].SortOrder = ColumnSortOrder.Ascending; locationTreeView.View.NodeChanged += NodeChecked; marketItemTreeView.ItemsSource = _marketItemNodes.Nodes; marketItemTreeView.Columns["Name"].SortOrder = ColumnSortOrder.Ascending; }
// finds <amount> spawnpoints + 1 endpoint, for initial placement of players/level end. endpoint is always at 0th position in list // traverses region tree to find the two furthest away regions public List <Pos> findSpawnpoints(int amount) { RegionNode root = new RegionNode(region_tree_root); Stack <RegionNode> bottom = new Stack <RegionNode>(); Stack <RegionNode> top = new Stack <RegionNode>(); // traverses tree from bottom->top, pushing nodes to a stack so we can traverse them top->bottom later bottom.Push(root); while (bottom.Count > 0) { RegionNode curr = bottom.Pop(); top.Push(curr); foreach (RegionNode child in curr.children) { bottom.Push(child); } } RegionNode diameterNode = null; // root node of the subtree with the largest diameter int maxDiameter = 0; // gets the node in the region tree where the two furthest-most leaf nodes are from one another while (top.Count > 0) { RegionNode curr = top.Pop(); int diameter; // if this node is a leaf node, set height/diameter to 1 if (curr.children.Count == 0) { curr.height = 1; diameter = 1; } // if this node only has one child, set height/diameter to child height + 1 else if (curr.children.Count == 1) { curr.height = curr.children[0].height + 1; diameter = curr.height; } // otherwise, find the two tallest children, set height to the height of the tallest child, and set diameter to the sum of the tallest children + 1 else { curr.children.Sort( // sorts children by height delegate(RegionNode a, RegionNode b) { return(a.height.CompareTo(b.height)); }); curr.children.Reverse(); // sorts from tallest->smallest curr.height = curr.children[0].height + 1; diameter = curr.children[0].height + curr.children[1].height + 1; Debug.Log("diameter:" + diameter); } if (diameter > maxDiameter) { maxDiameter = diameter; diameterNode = curr; } } Debug.Log("Max diameter: " + maxDiameter); // once the diameter root has been found, get the farthest-most regions Region spawnRegion = diameterNode.find_nth_furthest_region(0); Region endRegion = diameterNode.find_nth_furthest_region(1); // throws random locations at the map until all suitable player spawn/level end locations are found List <Pos> spawnPositions = new List <Pos>(); int x, y; // gets all spawn positions while (spawnPositions.Count < amount) { do { x = rng.Next(0, width - 1); y = rng.Next(0, height - 1); } while (map_raw[x, y] != spawnRegion.ID || !IsWalkable(new Pos(x, y))); spawnPositions.Add(new Pos(x, y)); } // gets end point do { x = rng.Next(0, width - 1); y = rng.Next(0, height - 1); } while (map_raw[x, y] != endRegion.ID); spawnPositions.Insert(0, new Pos(x, y)); return(spawnPositions); }
public void Resolve(RegionNode regionNode) { this.Result = this.creator.CreateRegion(this.computations, regionNode); }