public void BFSMediumTest() { int row = 70; int col = 70; int speed = 5; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Node[,] graph = gra.graph; Assert.NotNull(gra.graph); BreadthFirstSearch bfs = new BreadthFirstSearch(); bfs.BFS(gra, graph[0, 0], speed); List <Node> reachableNodes = bfs.traveableNodes(); int reach; for (int i = 0; i < reachableNodes.Count; i++) { reach = reachableNodes[i].posX + reachableNodes[i].posY; Assert.IsTrue(reach <= speed); } speed = 20; bfs.BFS(gra, graph[50, 50], speed); reachableNodes = bfs.traveableNodes(); for (int i = 0; i < reachableNodes.Count; i++) { // reach = reachableNodes[i].posX + reachableNodes[i].posY - 100; reach = reachability(reachableNodes[i], graph[50, 50]); Assert.IsTrue(reach <= speed); } speed = 10; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { bfs.BFS(gra, graph[i, j], speed); reachableNodes = bfs.traveableNodes(); for (int k = 0; k < reachableNodes.Count; k++) { reach = reachability(reachableNodes[k], graph[i, j]); Assert.IsTrue(reach <= speed); } } } Debug.Log("Testing complete"); }
public void BFSinitialTest() { int row = 5; int col = 5; int speed = 2; GameObject obj = new GameObject(); createBoardManager(obj, row, col); Graph gra = addGraphObject(obj); gra.CreateGraph(); Node[,] graph = gra.graph; Assert.NotNull(gra.graph); BreadthFirstSearch bfs = new BreadthFirstSearch(); bfs.BFS(gra, graph[0, 0], speed); List <Node> reachableNodes = bfs.traveableNodes(); int reach; for (int i = 0; i < reachableNodes.Count; i++) { reach = reachableNodes[i].posX + reachableNodes[i].posY; Assert.IsTrue(reach <= speed); } Debug.Log("Testing is finished"); }
void Start() { destinationPosition = destination.transform.position; agentPosition = agent.transform.position; nodesGenerator.genNodesGrid(ref nodeGrid); nodesGenerator.SetNearestNode(ref nodeGrid, ref agentPosition, ref originNode); Debug.Log("ORIGIN: " + originNode.position); nodesGenerator.SetNearestNode(ref nodeGrid, ref destinationPosition, ref goalNode); currentNode = originNode; openedNodes.Add(currentNode); pathToGoal.Add(destinationPosition); switch (pathFindingType) { case TypeOfPathFinding.BreadthFirstSearch: breadthFirstSearch.BFS(ref currentNode, ref openedNodes, ref goalNode, ref goalFound); break; case TypeOfPathFinding.DepthFirstSearch: depthFirstSearch.DFS(ref currentNode, ref openedNodes, ref goalNode, ref goalFound); break; case TypeOfPathFinding.Dijkstra: dijkstra.DijkstraAlgorithm(ref currentNode, ref openedNodes, ref goalNode, ref goalFound); break; case TypeOfPathFinding.AStar: aStar.AStarAlgorithm(ref currentNode, ref openedNodes, ref goalNode, ref goalFound); break; default: break; } }
public bool FindPath(Point food, Screen screen) { try { State start = new State(this.Head); State goal = new State(food); State result; if (algorithm == Algorithms.BreadthFirstSearch) { result = BreadthFirstSearch.BFS(start, goal, screen); } else { result = DepthFirstSearch.DFS(start, goal, screen); } if (result != null)//tìm thấy đường đi { this.stepIndex = 0; while (result.Previous != null) { path[stepIndex] = result.Coordinates; stepIndex++; result = result.Previous; } return(true); } return(false); } catch { return(false); } }
public List <Node> FindTargeteableGrid(Graph graphs, Node starts, int speeds) { return(bfs.BFS(graphs, starts, speeds)); }