private Chunk GetNeighbour(Neighbour neighbour) { switch (neighbour) { case Neighbour.Top: return(Top); case Neighbour.Bottom: return(Bottom); case Neighbour.Forward: return(Forward); case Neighbour.Backward: return(Backward); case Neighbour.Left: return(Left); case Neighbour.Right: return(Right); } return(null); }
public VodNod(int chain, int ring, bool flag) { Chain = chain; Ring = ring; Id = chain.ToString() + "-" + ring.ToString() + " "; if (flag == true) { IsSuperPeer = true; } else { IsSuperPeer = false; } Status = new Neighbour(); Trust = 0.5; OwnSlots = new List <Slot>(); NeighborSlot = new List <Slot>(); //myFrame = new Frame(); availableStorage = 8000; }
public Neighbour GetNeighborByID(short ID) { Neighbour result = null; Neighbors.NeighbourByID.TryGetValue(ID, out result); return(result); }
private void OnCollisionEnter(Collision _collision) { GameObject exp = Instantiate(explosionEffectPrefab, transform.position, transform.rotation); exp.transform.localScale = new Vector3(explosionRadius * 2, explosionRadius * 2, explosionRadius * 2); Collider[] hitColliders = Physics.OverlapSphere(transform.position, explosionRadius); foreach (Collider collider in hitColliders) { Neighbour player = collider.GetComponentInParent <Neighbour>(); if (player != null) { RegisterHittenPlayer(player); } } foreach (Neighbour playerHitten in allPlayerHitten) { playerHitten.TakeDamage(damage, (playerHitten.transform.position - transform.position).normalized * explosionForce); } Destroy(exp, 0.2f); Destroy(gameObject); }
internal void Deserialize <T>(HashSet <T> all_cells, Dictionary <int, T> id_to_cell, BinaryReader r) where T : Cell, new() { GlobalId = r.ReadInt32(); Id = r.ReadInt32(); AABB = new AABB(r); ParentAABB = new AABB(r); Flags = (MovementFlag)r.ReadInt32(); Replacement = r.ReadBoolean(); Disabled = r.ReadBoolean(); MovementCostMult = r.ReadSingle(); Threat = r.ReadSingle(); int neighbours_num = r.ReadInt32(); for (int i = 0; i < neighbours_num; ++i) { Neighbour neighbour = new Neighbour(null, Vec3.ZERO, MovementFlag.None); int neighbour_global_id = r.ReadInt32(); neighbour.cell = id_to_cell != null ? id_to_cell[neighbour_global_id] : all_cells.FirstOrDefault(x => x.GlobalId == neighbour_global_id); neighbour.border_point = new Vec3(r); neighbour.connection_flags = (MovementFlag)r.ReadInt32(); if (neighbour.cell != null) { Neighbours.Add(neighbour); } else { Console.WriteLine("Oops!"); } } AlignPlaneDirty = true; }
/// <summary> /// Adds a neighbour to this GraphNode. /// </summary> /// <param name="node">The neighbouring GraphNode.</param> /// <param name="cost"> /// The cost to travel from this GraphNode to <paramref name="node"/>. If not supplied the cost will /// be the distance between the two GraphNode objects. /// </param> public virtual void AddNeighbour(GraphNode node, Single cost = -1.0f) { //HPAStar.NavMesh.DebugCheckNode(node); // Create a new neighbour to wrap the node passed in. Neighbour temp = mUnusedNeighbours.Dequeue(); // Put it back into a default state. temp.Reset(); temp.mGraphNode = node; if (cost >= 0) { temp.mCostToTravel = cost; } else { // This assumes that nodes never move. temp.mCostToTravel = Vector2.Distance(node.pPosition, pPosition); } System.Diagnostics.Debug.Assert(node.pData != null, "Uninitialized node set as neighbour"); mNeighbours.Add(temp); }
// Use this for initialization void Start() { neighbourScript = GameObject.FindGameObjectWithTag("Neighbours").GetComponent <Neighbour>(); gameManagerScript = GameObject.FindGameObjectWithTag("Managers").GetComponent <GameManager>(); gameRate = gameManagerScript.gameRate; speedSlider.value = gameRate; }
private void SetWormBelowAttackLowerWall(HexagonController adjacent, Neighbour origin) { if (adjacent != null) { adjacent.WormBelowAttackLowerWall(origin); } }
public void CalculateNN() { if (runNN == true) { float before = Time.realtimeSinceStartup; Neighbour[] traversers = new Neighbour[pillars.Count]; float bestDistance = 99999f; for (int i = 0; i < pillars.Count; i++) { traversers[i] = new Neighbour { waypoints = pillars, startPosition = pillars[i], runTime = pillars.Count }; traversers[i].Move(); if (traversers[i].path < bestDistance) { bestDistance = traversers[i].path; } } GameObject.Find("NN Best").GetComponentInChildren <UnityEngine.UI.Text>().text = "NN's Best Path = " + bestDistance; runNN = false; float after = Time.realtimeSinceStartup; float duration = after - before; GameObject.Find("Time taken for NN").GetComponentInChildren <UnityEngine.UI.Text>().text = "Duration in seconds: " + duration; } }
public void addNeighbour(Neighbour neighbour) { if (!mNeighbours.Contains(neighbour)) { mNeighbours.Add(neighbour); } }
public async Task <CreateTravelResponse> CreateTravel(CreateTravelRequest request) { var jsonDataList = await Read(); if (jsonDataList != null) { jsonDataList.Add(request); } else { jsonDataList = new List <CreateTravelRequest> { request }; } var neigbour = new Neighbour(); var neighbourList = neigbour.CreateNeighbourList(request.ToFrom, request.ToWhere); request.NeighbourList = neighbourList; await Write(jsonDataList); return(new CreateTravelResponse { Id = request.Id }); }
public void AddCase(GameObject prefabCase, Neighbour pos, float height = -1) { Case newcase = AddCase(prefabCase, pos.position, height); newcase.neighbour = pos.gameObject; neighbours.Remove(pos); }
private void AddToFamily(FAMI family, Neighbour neigh, VM vm) { //was the neighbor already in a family? if (neigh.PersonData != null) { var famID = neigh.PersonData[(int)VMPersonDataVariable.TS1FamilyNumber]; var oldFam = Content.Content.Get().Neighborhood.GetFamily((ushort)famID); if (oldFam != null && oldFam.ChunkID != 0) { var oguids = oldFam.FamilyGUIDs.ToList(); oguids.Remove(neigh.GUID); oldFam.FamilyGUIDs = oguids.ToArray(); TryDeleteFamily(oldFam); } neigh.PersonData[(int)VMPersonDataVariable.TS1FamilyNumber] = (short)family.ChunkID; } var guids = family.FamilyGUIDs.ToList(); guids.Add(neigh.GUID); family.FamilyGUIDs = guids.ToArray(); //if the sim is on the lot, change their runtime person data to reflect the new family id. var runtime = (VMAvatar)vm.Context.ObjectQueries.Avatars.FirstOrDefault(x => ((VMAvatar)x).GetPersonData(VMPersonDataVariable.NeighborId) == neigh.NeighbourID); runtime?.SetPersonData(VMPersonDataVariable.TS1FamilyNumber, (short)family.ChunkID); }
/// <summary> /// Slower calculation of IsNeighbourAtBorder in cases elemsPerDim is not a power of 2. /// </summary> public static bool IsNeighbourAtBorderSlow(int id, Neighbour neighbour, int row = Chunk.kRow, int column = Chunk.kColumn, int totalElements = WorldGridInfo.kTotalVoxelsInChunk) { switch (neighbour) { case Neighbour.Forward: return(id + 1 >= totalElements || (id + 1) / row != id / row); case Neighbour.Backward: return(id - 1 < 0 || (id - 1) / row != id / row); case Neighbour.Top: return(id + row >= totalElements || (id + row) / column != id / column); case Neighbour.Bottom: return(id - row < 0 || (id - row) / column != id / column); case Neighbour.Right: return(id + column >= totalElements); case Neighbour.Left: return(id - column < 0); default: return(true); } }
/// <summary> /// Returns true if a neighbour in a given direction from a voxel/chunk/block at given id is at the border of the chunk or block it belongs to. /// Inspired by WorldGridInfo.VoxelIdToChunkVoxel() /// </summary> public static bool IsNeighbourAtBorder(int id, Neighbour neighbour, int elemsPerDim = WorldGridInfo.kVoxelsPerChunk, int elemsPerDimLog2 = WorldGridInfo.kVoxelsPerChunkLog2) { int pos = id; switch (neighbour) { case Neighbour.Top: case Neighbour.Bottom: pos >>= elemsPerDimLog2; break; case Neighbour.Right: case Neighbour.Left: pos >>= elemsPerDimLog2 * 2; break; } pos &= elemsPerDim - 1; switch (neighbour) { case Neighbour.Forward: case Neighbour.Top: case Neighbour.Right: return(pos == elemsPerDim - 1); case Neighbour.Backward: case Neighbour.Bottom: case Neighbour.Left: return(pos == 0); } return(false); }
private static void FillWithNeighbourOffsets(ref NativeArray <Neighbour> neighbourOffsetArray) { neighbourOffsetArray[0] = new Neighbour { Offset = new int2(-1, 0), Distance = 1f }; // Left neighbourOffsetArray[1] = new Neighbour { Offset = new int2(+1, 0), Distance = 1f }; // Right neighbourOffsetArray[2] = new Neighbour { Offset = new int2(0, +1), Distance = 1f }; // Up neighbourOffsetArray[3] = new Neighbour { Offset = new int2(0, -1), Distance = 1f }; // Down neighbourOffsetArray[4] = new Neighbour { Offset = new int2(-1, -1), Distance = 1.44f }; // Left Down neighbourOffsetArray[5] = new Neighbour { Offset = new int2(-1, +1), Distance = 1.44f }; // Left Up neighbourOffsetArray[6] = new Neighbour { Offset = new int2(+1, -1), Distance = 1.44f }; // Right Down neighbourOffsetArray[7] = new Neighbour { Offset = new int2(+1, +1), Distance = 1.44f }; // Right Up }
public List <Bakery> CollaborativeFiltering(string id) { //Protogtype Cal Correl From id User //Prototype Create Neiber Array from List Correl Neighbour[] ListNeibour = new Neighbour[1000]; ListNeibour = FindNeighBour(id); if (ListNeibour == null) { return(null); } //Prototype ListNeibour=NeibourArray //List chỉ số của neibour trong matrix user item List <int> ListPos = GetListItemNeibour(ListNeibour); //tối giản matrixuseritem double[][] ListNeibourFromListPos = MatrixNeibourPreCal(ListPos); //List predict cần tìm List <double> ListPreDict = ListPreDictPreCall(ListNeibourFromListPos, ListNeibour, id); var rowBakery = this.imatrix.getBakeryRow(); var ListBakery = new List <Bakery>(); List <int> pos = new List <int>(); ListBakery = this.imatrix.getHighNbyonvalue(rowBakery, ref ListPreDict, 5, ref pos); return(ListBakery); }
private void ResetLines() { for (int i = 0; i < neighbours.Count; i++) { Neighbour n = neighbours[i]; n.lineDrawn = false; } }
public void InheritNeighbor(Neighbour neigh) { if (neigh.PersonData != null) { PersonData = neigh.PersonData; } SetPersonData(VMPersonDataVariable.NeighborId, neigh.NeighbourID); }
public bool IsPassableRegion(Neighbour neighbour) { if (neighbour.Region.ID == DestinationID) { return(true); } return(neighbour.Region.CountryID.HasValue == false || NoCrossCountries.Contains(neighbour.Region.CountryID.Value) == false); }
private void GeneratePieceMesh(PieceData p) { //use HashSet to prevent double vertices HashSet <Vector2> vertices2DSet = new HashSet <Vector2>(); HashSet <Vector2> vertices2DColliderSet = new HashSet <Vector2>(); foreach (Neighbour n in p.neighbours) { //if this 'neighbour' is the boundary, set edgeType to straight if (n.id == -1) { n.edgeType = PEdge.EdgeType.Straight; } //else if the edgeType wasn't set to something yet, set it here //and also set the corresponding neighbours edgeType to the opposite type else if (n.edgeType == PEdge.EdgeType.Nothing) { PieceData neighbourPiece = GetPieceData(n.id); Neighbour meAsNeighbour = neighbourPiece.GetNeigbourWithID(p.id); if (randomBool(p.id)) { n.edgeType = PEdge.EdgeType.Shaped; meAsNeighbour.edgeType = PEdge.EdgeType.ShapedInverse; } else { n.edgeType = PEdge.EdgeType.ShapedInverse; meAsNeighbour.edgeType = PEdge.EdgeType.Shaped; } } PEdge edge = new PEdge(p.baseVertices[n.v1], p.baseVertices[n.v2], n.edgeType, meshDetail); PEdge edgeLowDetail = new PEdge(p.baseVertices[n.v1], p.baseVertices[n.v2], n.edgeType, colliderDetail); edge.points.ForEach(point => vertices2DSet.Add(point)); edgeLowDetail.points.ForEach(point => vertices2DColliderSet.Add(point)); } List <Vector2> vertices2D = vertices2DSet.ToList(); List <Vector2> vertices2DCollider = vertices2DColliderSet.ToList(); //create final visual mesh Triangulator triangulator = new Triangulator(vertices2D); int[] triangles = triangulator.Triangulate(); Vector3[] vertices = vertices2D.ConvertAll(v2 => new Vector3(v2.x, v2.y, 0f)).ToArray(); p.mesh = MeshFunctions.ExtrudeFlatPiece(vertices, triangles, thickness); ProjectUV(p.mesh, p.position); //create final collider mesh triangulator = new Triangulator(vertices2DCollider); int[] colliderTriangles = triangulator.Triangulate(); Vector3[] colliderVertices = vertices2DCollider.ConvertAll(v2 => new Vector3(v2.x, v2.y, 0f)).ToArray(); p.colliderMesh = MeshFunctions.ExtrudeFlatPieceNoSplit(colliderVertices, colliderTriangles, thickness); }
public static void AddGridNeighbourWithPosition(GridNode node, Neighbour direction, Vector3 pos, Grid grid) { GridNode neighbor = grid.GetNode(pos); if (neighbor != null) { node.AddStaticGridNeighbour(direction, node); } }
public Client() { Id = string.Empty; IsSuperPeer = false; Chain = -1; Ring = -1; Status = new Neighbour(); Content = CreateContnt(); }
private static Neighbours Given(Neighbour three) { var world = new Neighbours(); for (int i = 0; i < (int)three; i++) { world.AddAlive(); } return(world); }
public void UpdateSequence(Neighbour neighbour) { // Convert our sequence of ints to the 2D line representations to be drawn on the screen. pathLines.Clear(); pathLines.AddRange(TownHelper.GetTownSequencePath(neighbour.Sequence)); // Convert the fitness into a format that is easily digestable and update the value on screen // Format: 1234.56 totalDistanceString.StringText = neighbour.GetFitness().ToString("#.##"); }
public void RemoveWall(Neighbour neighbour) { //TODO: possible bug where opposite neighbour still thinks wall exists if (neighbour.hasWall) { Destroy(neighbour.wall); neighbour.hasWall = false; neighbour.wall = null; } }
public RegionNeigbourMapSummaryViewModel(Neighbour neighbour) { Distance = neighbour.Passage.Distance; RegionName = neighbour.Region.Name; if (RegionName.Length > 13) { RegionName = RegionName.Substring(0, 10) + "..."; } }
private float CalculateCost(Neighbour newNeighbour) { float newCost = newNeighbour.distanceAbsolute + Mathf.Abs(newNeighbour.distance.y); if (newCost > maxCost) { maxCost = newCost; } return(newCost); }
private static Maze ApplyRecursiveBacktracker(WallState[,] maze, Distance[,] distanceMatrix, int width, int height) { System.Random random = new System.Random(/*seed*/); Stack <Position> positionStack = new Stack <Position>(); Position position = new Position(random.Next(0, width), random.Next(0, height)); positionStack.Push(position); maze[position.getX(), position.getY()] |= WallState.VISITED; while (positionStack.Count > 0) { Position current = positionStack.Pop(); List <Neighbour> neighbours = GetUnvisitedNeighbours(current, maze, width, height); if (neighbours.Count > 0) { positionStack.Push(current); int randIndex = random.Next(0, neighbours.Count); Neighbour randomNeighbour = neighbours[randIndex]; Position neighbourPosition = randomNeighbour.getPosition(); maze[current.getX(), current.getY()] &= ~randomNeighbour.getSharedWall(); maze[neighbourPosition.getX(), neighbourPosition.getY()] &= ~GetOppositeWall(randomNeighbour.getSharedWall()); maze[neighbourPosition.getX(), neighbourPosition.getY()] |= WallState.VISITED; positionStack.Push(neighbourPosition); calculateDistance(distanceMatrix[neighbourPosition.getX(), neighbourPosition.getY()].getDistances(), distanceMatrix[current.getX(), current.getY()].getDistances(), width, height); } else if (positionStack.Count > 0) { Position previous = positionStack.Peek(); calculateDistance(distanceMatrix[previous.getX(), previous.getY()].getDistances(), distanceMatrix[current.getX(), current.getY()].getDistances(), width, height); } } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { for (int k = 0; k < width; k++) { for (int l = 0; l < height; l++) { if (distanceMatrix[i, j].getDistances()[k, l] == -1) { distanceMatrix[i, j].distances[k, l] = distanceMatrix[k, l].getDistances()[i, j]; } } } } } return(new Maze(maze, distanceMatrix)); }
// Try to connect grid_cell with this cell. Connection can be established only when any two cells of both grid cells are connected. This function should behave // properly when called multiple times for the same pair of grid cells! public void AddNeighbour(GridCell grid_cell) { if (GlobalId == grid_cell.GlobalId || !AABB.Overlaps2D(grid_cell.AABB, true)) { return; } // this is removed to properly handle merging //if (Neighbours.Exists(x => x.cell.Equals(grid_cell))) // return; bool any_cells_connected = false; MovementFlag connection_flags = MovementFlag.None; foreach (Cell our_cell in Cells) { foreach (Cell other_cell in grid_cell.Cells) { Vec3 border_point = default(Vec3); bool cells_connected = our_cell.AddNeighbour(other_cell, ref border_point); if (cells_connected) { any_cells_connected = true; MovementFlag flags = our_cell.Flags & other_cell.Flags; if (flags > connection_flags) { connection_flags = flags; } } } } if (any_cells_connected) { Neighbour n1 = Neighbours.FirstOrDefault(x => x.cell.GlobalId == grid_cell.GlobalId); // if they were not connected before, simply connect them if (n1 == null) { Neighbours.Add(new Neighbour(grid_cell, Vec3.ZERO, connection_flags)); grid_cell.Neighbours.Add(new Neighbour(this, Vec3.ZERO, connection_flags)); } // otherwise verify connection flags else if (n1.connection_flags < connection_flags) { Neighbour n2 = grid_cell.Neighbours.FirstOrDefault(x => x.cell.GlobalId == GlobalId); n1.connection_flags = connection_flags; n2.connection_flags = connection_flags; } } }
/// <summary> /// Constructor. /// </summary> public GraphNode() { // On average we suspect there will be 8 neighbours. mNeighbours = new List<Neighbour>(8); // The first GraphNode to be created will take the hit and allocate all Neighbour objects. if (mUnusedNeighbours == null) { // We need a LOT of Neighbours... const Int32 num = 500000; mUnusedNeighbours = new Queue<Neighbour>(num); for (Int32 i = 0; i < num; i++) { Neighbour temp = new Neighbour(); mUnusedNeighbours.Enqueue(temp); } } }
void generateMaze(int width, int height) { visited = new ArrayList (); int totalCells = (width * height) - 1; rows = new int[width][]; cols = new int[width][]; positions = new int[width][]; for(int i=0;i<=width-1;i++) { // Initialize all walls to 1 and visited to 0 rows[i] = new int[height]; cols[i] = new int[height]; positions[i] = new int[height]; for(int j=0;j<=height-1;j++) { rows[i][j] = 1; cols[i][j] = 1; positions[i][j] = 0; } } Neighbour here = new Neighbour (Random.Range (0, width - 1), Random.Range (0, height - 1)); here.x = 0; here.y = 0; while (totalCells > 0) { positions[here.x][here.y] = 1; ArrayList list = new ArrayList(); if(here.x-1 >= 0) { Neighbour left = new Neighbour(here.x-1, here.y); list.Add (left); } if(here.x+1 < width) { Neighbour right = new Neighbour(here.x+1, here.y); list.Add (right); } if(here.y-1 >= 0) { Neighbour top = new Neighbour(here.x, here.y-1); list.Add (top); } if(here.y+1 < height) { Neighbour down = new Neighbour(here.x, here.y+1); list.Add (down); } // Just to know if I found a valid neighbour bool found = false; while(list.Count>0 && !found) { int r = Random.Range (0,list.Count); Neighbour n = (Neighbour)list[r]; list.RemoveAt(r); if(n.x >= 0 && n.y >= 0 && n.x < width && n.y < height) { if( positions[n.x][n.y] == 0) { found = true; // Then is visited now positions[n.x][n.y] = 1; // And I need to know if I need to remove a col or a row (floor or wall, if you know what I mean); if(n.x > here.x) { cols[here.x][here.y] = 0; } else if (n.x < here.x) { cols[n.x][n.y] = 0; } else if(n.y > here.y) { rows[here.x][here.y] = 0; } else if(n.y < here.y) { rows[n.x][n.y] = 0; } here = n; totalCells--; visited.Add (here); } } } if(!found) { here = (Neighbour)visited[visited.Count-1]; visited.RemoveAt (visited.Count-1); } } }