public override Direccion GetDireccion() { Goal goal = new Goal(); foreach (Targeter targeter in targeters) { goal.UpdateChannels(targeter.GetGoal()); } foreach (Decomposer decomposer in decomposers) { goal = decomposer.Decompose(goal); } for (int i = 0; i < constraintSteps; i++) { Camino path = actuator.GetPath(goal); foreach (Constraint constraint in constraints) { if (constraint.WillViolate(path)) { goal = constraint.Suggest(path); break; } return(actuator.GetOutput(path, goal)); } } return(base.GetDireccion()); }
//Algortmo de resolucion del laberinto public Point moveAgent(params Point[] directions) { if (Camino.Count == 1) { Camino.Push(directions[0]); CeldasMarcadas.Add(directions[0]); return(directions[0]); } else { foreach (Point point in directions) { if (!CeldasMarcadas.Contains(point)) { CeldasMarcadas.Add(point); Camino.Push(point); return(point); } } Camino.Pop(); foreach (Point punto in directions) { if (punto.Equals(Camino.Peek())) { return(punto); } } return(end); } }
void Estado(GameObject detectado) { x = detectado.GetComponent <Camino>(); if (x.getEsCamino()) { detectado.GetComponent <MeshRenderer>().material.color = Color.green; } else { caminoEquivocado = true; detectado.GetComponent <MeshRenderer>().material.color = Color.red; } }
public virtual Direccion GetOutput(Camino path, Goal goal) { return(new Direccion()); }
public void selectFicha() { bool onlyOne = false; for (int i = 0; i < Constants.Map.w; i++) { for (int j = 0; j < Constants.Map.h; j++) { if (!(i % 2 == 0 && j == Constants.Map.h - 1) && !onlyOne) //condicio basica del mapa + nomes una escollida { if (selectorMap[i][j].gameObject.GetComponent <Trigger>().isTriggered) // esta trigerejada pel ratoli { if (pathCount < Constants.Map.path_size && localMap[i][j].type == Ficha.Ficha_Type.VACIO) // te que estar vuida i tenir path disponible { bool auxBool = true; if (pathCount > 0) // { auxBool = isTouching(localPath[localPath.Count - 1], localMap[i][j]); } if (auxBool) { Vector2 auxPos = localMap[i][j].position; //guardes posicio, destrueixes objecte Object.Destroy(localMap[i][j].gameObject); if (pathCount == 0) //decideixes quin nou objecte el substituira { localMap[i][j] = new Start(pathFolder, true); } else if (pathCount == Constants.Map.path_size - 1) { localMap[i][j] = new End(pathFolder, true); } else { localMap[i][j] = new Camino(pathFolder, true); } localMap[i][j].position = auxPos; //actualitzes posicio e index localMap[i][j].i = i; localMap[i][j].j = j; localPath.Add(localMap[i][j]); //afegeix a Path pathCount++; localMap[i][j].setPathIndex(localPath.Count - 1); onlyOne = true; } } } } } } if (pathCount == Constants.Map.path_size)//aqui predeterminem el del enemic { Vector2 auxPos = othersMap[0][1][3].position; Object.Destroy(othersMap[0][1][3].gameObject); othersMap[0][1][3] = new Start(pathFolder, false); othersPath[0].Add(othersMap[0][1][3]); othersMap[0][1][3].position = auxPos; auxPos = othersMap[0][2][2].position; Object.Destroy(othersMap[0][2][2].gameObject); othersMap[0][2][2] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][2][2]); othersMap[0][2][2].position = auxPos; auxPos = othersMap[0][3][2].position; Object.Destroy(othersMap[0][3][2].gameObject); othersMap[0][3][2] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][3][2]); othersMap[0][3][2].position = auxPos; auxPos = othersMap[0][4][2].position; Object.Destroy(othersMap[0][4][2].gameObject); othersMap[0][4][2] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][4][2]); othersMap[0][4][2].position = auxPos; auxPos = othersMap[0][5][3].position; Object.Destroy(othersMap[0][5][3].gameObject); othersMap[0][5][3] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][5][3]); othersMap[0][5][3].position = auxPos; auxPos = othersMap[0][6][3].position; Object.Destroy(othersMap[0][6][3].gameObject); othersMap[0][6][3] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][6][3]); othersMap[0][6][3].position = auxPos; auxPos = othersMap[0][7][4].position; Object.Destroy(othersMap[0][7][4].gameObject); othersMap[0][7][4] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][7][4]); othersMap[0][7][4].position = auxPos; auxPos = othersMap[0][8][4].position; Object.Destroy(othersMap[0][8][4].gameObject); othersMap[0][8][4] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][8][4]); othersMap[0][8][4].position = auxPos; auxPos = othersMap[0][9][4].position; Object.Destroy(othersMap[0][9][4].gameObject); othersMap[0][9][4] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][9][4]); othersMap[0][9][4].position = auxPos; auxPos = othersMap[0][10][3].position; Object.Destroy(othersMap[0][10][3].gameObject); othersMap[0][10][3] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][10][3]); othersMap[0][10][3].position = auxPos; auxPos = othersMap[0][11][3].position; Object.Destroy(othersMap[0][11][3].gameObject); othersMap[0][11][3] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][11][3]); othersMap[0][11][3].position = auxPos; auxPos = othersMap[0][12][2].position; Object.Destroy(othersMap[0][12][2].gameObject); othersMap[0][12][2] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][12][2]); othersMap[0][12][2].position = auxPos; auxPos = othersMap[0][13][3].position; Object.Destroy(othersMap[0][13][3].gameObject); othersMap[0][13][3] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][13][3]); othersMap[0][13][3].position = auxPos; auxPos = othersMap[0][13][4].position; Object.Destroy(othersMap[0][13][4].gameObject); othersMap[0][13][4] = new Camino(pathFolder, false); othersPath[0].Add(othersMap[0][13][4]); othersMap[0][13][4].position = auxPos; auxPos = othersMap[0][13][5].position; Object.Destroy(othersMap[0][13][5].gameObject); othersMap[0][13][5] = new End(pathFolder, false); othersPath[0].Add(othersMap[0][13][5]); othersMap[0][13][5].position = auxPos; for (int i = 0; i < Constants.Map.w; i++) { for (int j = 0; j < Constants.Map.h; j++) { if (!(i % 2 == 0 && j == Constants.Map.h - 1)) { othersMap[0][i][j].i = i; othersMap[0][i][j].j = j; } } } for (int i = 0; i < Constants.Map.path_size; i++) { othersPath[0][i].setPathIndex(i); } localPathFolder.AddComponent <LineRenderer>(); localPathFolder.GetComponent <LineRenderer>().startWidth = localPathFolder.GetComponent <LineRenderer>().endWidth = Constants.Map.Local.path_width; localPathFolder.GetComponent <LineRenderer>().material = new Material(Shader.Find("Sprites/Default")); localPathFolder.GetComponent <LineRenderer>().startColor = new Color(0, 0, 1); localPathFolder.GetComponent <LineRenderer>().endColor = new Color(1, 1, 0); localPathFolder.GetComponent <LineRenderer>().positionCount = Constants.Map.path_size; othersPathFolder.AddComponent <LineRenderer>(); othersPathFolder.GetComponent <LineRenderer>().startWidth = othersPathFolder.GetComponent <LineRenderer>().endWidth = Constants.Map.Others.path_width; othersPathFolder.GetComponent <LineRenderer>().material = new Material(Shader.Find("Sprites/Default")); othersPathFolder.GetComponent <LineRenderer>().startColor = new Color(0, 0, 1); othersPathFolder.GetComponent <LineRenderer>().endColor = new Color(1, 1, 0); othersPathFolder.GetComponent <LineRenderer>().positionCount = Constants.Map.path_size; Vector3[] localPoints = new Vector3[Constants.Map.path_size]; Vector3[] othersPoints = new Vector3[Constants.Map.path_size]; for (int i = 0; i < Constants.Map.path_size; i++) { localPath[i].gameObject.transform.SetParent(localPathFolder.transform); othersPath[0][i].gameObject.transform.SetParent(othersPathFolder.transform); localPoints[i] = new Vector3(localPath[i].position.x, localPath[i].position.y, Constants.Layers.zPath); othersPoints[i] = new Vector3(othersPath[0][i].position.x, othersPath[0][i].position.y, Constants.Layers.zPath); } localPathFolder.GetComponent <LineRenderer>().SetPositions(localPoints); othersPathFolder.GetComponent <LineRenderer>().SetPositions(othersPoints); created = true; } }
public virtual bool WillViolate(Camino camino) { return(true); }
public virtual Goal Suggest(Camino camino) { return(new Goal()); }