void VisitNode(Node visitedNode) { if (visitedNode.isObstacle || visitedNode.visited) { //Debug.Log("O era obstaculo, o estaba visitado"); return; } else if (visitedNode.isEnd) { if (isBFS) { openList.Enqueue(visitedNode); } else if (isDFS) { openLstStack.Push(visitedNode); } Debug.Log("Encontre el final! es: (" + currentNode.coords + ", " + currentNode.coords.y + ")"); visitedNode.GetComponent <Renderer>().material.SetColor("_Color", Color.green); visitedNode.parent = currentNode; DrawPath(visitedNode); algoritm = ALGORITM.DEFAULT; return; } if (isBFS) { openList.Enqueue(visitedNode); } else if (isDFS) { openLstStack.Push(visitedNode); } visitedNode.GetComponent <Renderer>().enabled = true; visitedNode.GetComponent <Renderer>().material.SetColor("_Color", Color.cyan); visitedNode.parent = currentNode; }
void DFS_PF() { { Debug.Log("Buscando Path con DFS"); if (openLstStack.Count > 0) { currentNode = openLstStack.Pop(); currentNode.visited = true; //Debug.Log("Estoy checando el nodo: " + currentNode.iID); //currentNode.GetComponent<Renderer>().material.SetColor("_Color", Color.magenta); if (currentNode.isEnd) { Debug.Log("Encontre el final! es: (" + currentNode.coords + ", " + currentNode.coords.y + ")"); algoritm = ALGORITM.DEFAULT; return; } float x, y; //ESTE x = currentNode.coords.x + 1; y = currentNode.coords.y; if (currentNode.coords.x < 9) { VisitNode(GetNode(x, y)); } //SUD-ESTE x = currentNode.coords.x + 1; y = currentNode.coords.y + 1; if (currentNode.coords.x < 10 && currentNode.coords.y < 10) { VisitNode(GetNode(x, y)); } //SUR x = currentNode.coords.x; y = currentNode.coords.y + 1; if (currentNode.coords.y < 9) { VisitNode(GetNode(x, y)); } //SUD-OESTE x = currentNode.coords.x - 1; y = currentNode.coords.y + 1; if (currentNode.coords.y < 10 && currentNode.coords.x > 0) { VisitNode(GetNode(x, y)); } //OESTE x = currentNode.coords.x - 1; y = currentNode.coords.y; if (currentNode.coords.x > 0) { VisitNode(GetNode(x, y)); } //NOR-OESTE x = currentNode.coords.x - 1; y = currentNode.coords.y - 1; if (currentNode.coords.x > 0 && currentNode.coords.y > 0) { VisitNode(GetNode(x, y)); } //NORTE x = currentNode.coords.x; y = currentNode.coords.y - 1; if (currentNode.coords.y > 0) { VisitNode(GetNode(x, y)); } //NOR-ESTE x = currentNode.coords.x + 1; y = currentNode.coords.y - 1; if (currentNode.coords.y > 0 && currentNode.coords.x < 10) { VisitNode(GetNode(x, y)); } if (!currentNode.isStart) { currentNode.GetComponent <Renderer>().material.SetColor("_Color", Color.yellow); } } else { Debug.Log("Esta vacĂa."); algoritm = ALGORITM.DEFAULT; } } }
void AStar_PF() { Debug.Log("Pues se activo A*"); algoritm = ALGORITM.DEFAULT; }