public void SetUp() { _grid = new GridFake(); _gridManager = new GridManager(_grid); _calculatePath = new CalculatePath(_gridManager, 1); _startingNode = new PathfindingNode(0f, 0f); }
private void CalculatePath() { _pathCalculator = new CalculatePath(_mob.Grid.GetGrid(), _mob.gameObject.name.GetHashCode()); _path = _pathCalculator.GetPathToDestination(_mob.transform.position.x, _mob.transform.position.z, _playerPos.x, _playerPos.z); _nextNodeIndex = 0; }
//will add any potential neighbouring nodes to the potential path list if they haven't already, will check to see if the path has reached the goal void CalculateNeighbours() { List <STR_ID> neighbours = currentNode.ReturnNeighbours(); for (int i = 0; i < neighbours.Count; i++) { SCR_NodeClass neighbourNode = nodeManager.ReturnNode(neighbours[i]); STR_ID currentNeighbourID = neighbourNode.returnID(); STR_ID currentNodeID = currentNode.returnID(); if (currentNodeID.Compare(currentNeighbourID) == false) { if (listOfNodes.Contains(neighbourNode)) { if (neighbourNode.ReturnRoomType() != RoomType.BlockedRoute) { var current = new CalculatePath(neighbourNode, currentNode); if (neighbourNode.ReturnRoomType() == RoomType.InitialFightRoom || neighbourNode.ReturnRoomType() == RoomType.ChallangeRoom) { if (!finalPathPoints.Contains(neighbourNode)) { closed.Add(current); } } if ((!open.Contains(current)) && (!closed.Contains(current))) { if (CheckOpenList(currentNodeID, currentNeighbourID) == false && CheckClosedList(currentNodeID, currentNeighbourID) == false) { open.Add(current); } } } } } } closed.Add(open[currentPos]); Vector3 endPos = goal.returnID().body.transform.position; STR_ID currentID = currentNode.returnID(); Vector3 currentPosition = currentNode.returnID().body.transform.position; if (currentNode == goal) { pathfound = true; pathEnd = closed.Count - 1; } open.Remove(open[currentPos]); }
public override State Update() { State state = this; bool calculateArrival = generator.MoveNext(); outer.fastMarchingMethod.DisplayArrival(); if (calculateArrival) { outer.IncrementStep(); } else { state = new CalculatePath(outer, outer.origin); //state = new Idle(); } return(state); }
public double Calculating(List <Tree> Forest, List <Double> rowData, int countData) { CalculatePath path = new CalculatePath(); double h = 0; double E = 0; double C = 0; double anomalyScore = 0; for (int i = 0; i < Forest.Count; i++) { h += path.PathLength(rowData, Forest[i], 0); } E = h / Forest.Count; C = ((2 * (Math.Log(countData - 1) + 0.5772156649)) - ((double)(2 * (countData - 1)) / countData)); anomalyScore = Math.Pow(2, -1 * (E / C)); //anomalyScore = (anomalyScore - 0.35) * 1.8; return(anomalyScore); }
void NeighbourCheck(float check, float value, Vector2 pos, bool GreaterThan) { if ((check > value && GreaterThan) || (check < value && GreaterThan == false)) { GameObject ThisGrid = Grid[(int)pos.x, (int)pos.y]; if (ThisGrid != null) { if ((ThisGrid.GetComponent <GridSquare>().ObjectAbove() == false)) { var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } } } }
void NeighbourCheck() { //retrieve the x and y co-ordinates of the current cell int xPos = (int)CurrentGrid.x; int yPos = (int)CurrentGrid.y; //value representing each of the cells neighbours Vector2 pos = Vector2.zero; //////// Check each of the cells honeycomb neighbours and if they are not a mountain tile, are of a land state or already in the lists then add the cell to the open list if (xPos > 0) { if (grid.HexGrid[xPos - 1, yPos].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos - 1, yPos]) { pos = new Vector2(xPos - 1, yPos); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos - 1, yPos].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos - 1, yPos] == false) { waterFound = true; } } if (xPos < (grid.gridWidth - 1)) { if (grid.HexGrid[xPos + 1, yPos].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos + 1, yPos]) { pos = new Vector2(xPos + 1, yPos); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos + 1, yPos].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos + 1, yPos] == false) { waterFound = true; } } if (yPos % 2 != 0) { if (yPos > 0) { if (grid.HexGrid[xPos, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos - 1]) { pos = new Vector2(xPos, yPos - 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos - 1] == false) { waterFound = true; } } if (xPos < (grid.gridWidth - 1) && yPos > 0) { if (grid.HexGrid[xPos + 1, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos + 1, yPos - 1]) { pos = new Vector2(xPos + 1, yPos - 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos + 1, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos + 1, yPos - 1] == false) { waterFound = true; } } if (xPos < (grid.gridWidth - 1) && yPos < (grid.gridHeight - 1)) { if (grid.HexGrid[xPos + 1, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos + 1, yPos + 1]) { pos = new Vector2(xPos + 1, yPos + 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos + 1, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos + 1, yPos + 1] == false) { waterFound = true; } } if (yPos < (grid.gridHeight - 1)) { if (grid.HexGrid[xPos, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos + 1]) { pos = new Vector2(xPos, yPos + 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos + 1] == false) { waterFound = true; } } } if (yPos % 2 == 0) { if (yPos > 0 && xPos > 0) { if (grid.HexGrid[xPos - 1, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos - 1, yPos - 1]) { pos = new Vector2(xPos - 1, yPos - 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos - 1, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos - 1, yPos - 1] == false) { waterFound = true; } } if (yPos > 0) { if (grid.HexGrid[xPos, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos - 1]) { pos = new Vector2(xPos, yPos - 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos, yPos - 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos - 1] == false) { waterFound = true; } } if (yPos < (grid.gridHeight - 1)) { if (grid.HexGrid[xPos, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos + 1]) { pos = new Vector2(xPos, yPos + 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos, yPos + 1] == false) { waterFound = true; } } if (xPos > 0 && yPos < (grid.gridHeight - 1)) { if (grid.HexGrid[xPos - 1, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos - 1, yPos + 1]) { pos = new Vector2(xPos - 1, yPos + 1); var current = new CalculatePath(pos, CurrentGrid); if (CheckList(pos, Closed) == false && CheckList(pos, Open) == false) { Open.Add(current); } } else if (grid.HexGrid[xPos - 1, yPos + 1].transform.GetChild(0).gameObject.tag != "Mountain" && islandLandMass[xPos - 1, yPos + 1] == false) { waterFound = true; } } } //////// }