public static List<Tile> FindPath(Tile originTile, Tile destinationTile, Vector2[] occupied) { List<Tile> closed = new List<Tile>(); List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { //open = open.OrderBy(x => x.costOfPath).ToList(); TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Distinct(); current.listOfTiles.Remove(originTile); return current.listOfTiles; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (t.impassible || occupied.Contains(t.gridPosition)) continue; TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } return null; }
public static List<Tile> FindHighlight(Tile originTile, int movementPoints, Vector2[] occupied) { List<Tile> closed = new List<Tile>(); List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.costOfPath > movementPoints + 1) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbours) { if (t.impassible || occupied.Contains(t.gridPosition)) continue; TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } closed.Remove(originTile); closed.Distinct(); return closed; }
public static List<Tile> FindPath(Tile originTile, Tile destinationTile) { List<Tile> closed = new List<Tile>(); List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Remove (originTile); return current.listOfTiles; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (t.impassible) continue; TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } return null; }
public static List <Tile> FindHighlight(Tile originTile, int movementPoints, Vector2[] occupiedTile, bool attacking) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); if (attacking) { originPath.addTileAttack(originTile); } else { originPath.addTile(originTile); } open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.costOfPath > movementPoints + 1) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (t.impassible || occupiedTile.Contains(t.gridPosition)) { continue; } TilePath newTilePath = new TilePath(current); if (attacking) { newTilePath.addTileAttack(t); open.Add(newTilePath); } else { newTilePath.addTile(t); open.Add(newTilePath); } } } closed.Remove(originTile); closed.Distinct(); return(closed); }
public static List <Tile> FindPath(Tile originTile, Tile destinationTile) { // Closed List will contain the path as we build it List <Tile> closed = new List <Tile>(); // Open List will contain the available tiles List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); //Debug.Log("Tile removed"); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Distinct(); current.listOfTiles.Remove(originTile); Debug.Log("This is logged"); Debug.Log("Number of Tiles is:" + current.listOfTiles.Count()); // 2 tiles return(current.listOfTiles); Debug.Log("This is not logged"); } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (!t.isPassable) { continue; } TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } Debug.Log("This is also logged"); Debug.Log("And the function returns null"); return(null); }
//Aqui que vamos calcular o caminho caminho mais curto até o destino a partir da origem public static List <Tile> FindPathTilesReturn(Tile origem, Tile destino) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); UnidadeNoTabuleiro unidadeAtual = BatalhaController.instancia.unidadesNoTabuleiro[BatalhaController.instancia.unidadeAtualIndex]; TilePath originPath = new TilePath(); originPath.addTile(origem); open.Add(originPath); while (open.Count > 0) { open = open.OrderBy(x => x.custoDoCaminho).ToList(); TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.ultimoTile)) { continue; } if (current.ultimoTile == destino) { current.listaDeTiles.Remove(origem); return(current.listaDeTiles); } closed.Add(current.ultimoTile); foreach (Tile t in current.ultimoTile.vizinhos) { if (t.instransponivel) { continue; } if (unidadeAtual.gridDeMovimento && t.ocupado) { continue; } if (unidadeAtual.gridDeMovimento && t.classesRestritas.Contains(unidadeAtual.unidadeAssociada.classe)) { continue; } TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } return(null); }
// this ignores anything in the occupied array, and ignores impassible tiles public static List <Tile> FindPath(Tile originTile, Tile destinationTile, Vector2[] occupied) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Distinct(); current.listOfTiles.Remove(originTile); return(current.listOfTiles); } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbours) { if (t.impassible || occupied.Contains(t.gridPosition)) { continue; } TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } foreach (Tile t in closed) { Debug.Log("closed tile" + t.gridPosition); } return(null); }
/* public static List<Tile> FindHighlight(Tile originTile, int movementPoints) { * return FindHighlight(originTile, movementPoints, new Vector2[0], false); * } * public static List<Tile> FindHighlight(Tile originTile, int movementPoints, bool staticRange) { * return FindHighlight(originTile, movementPoints, new Vector2[0], staticRange); * } * public static List<Tile> FindHighlight(Tile originTile, int movementPoints, Vector2[] occupied) { * return FindHighlight(originTile, movementPoints, occupied, false); * } */ public static List <Tile> FindHighlight(Tile originTile, int movementPoints) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); //if (staticRange) originPath.addStaticTile(originTile); //else originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } // each tile cost is 1, could change this later if (1 > movementPoints + 1) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (!t.isPassable || t.isOccupied) { continue; } TilePath newTilePath = new TilePath(current); //if (staticRange) newTilePath.addStaticTile(t); //else newTilePath.addTile(t); open.Add(newTilePath); } } closed.Remove(originTile); closed.Distinct(); return(closed); }
public static List<Tile> FindPath(Tile originTile, Tile destinationTile) { // Closed List will contain the path as we build it List<Tile> closed = new List<Tile>(); // Open List will contain the available tiles List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); //Debug.Log("Tile removed"); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Distinct(); current.listOfTiles.Remove(originTile); Debug.Log("This is logged"); Debug.Log("Number of Tiles is:" + current.listOfTiles.Count()); // 2 tiles return (current.listOfTiles); Debug.Log("This is not logged"); } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (!t.isPassable) continue; TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } Debug.Log("This is also logged"); Debug.Log("And the function returns null"); return null; }
// this method is different because it needs to find a path between impassible tiles. public static List <Tile> FindPathBetweenRooms(Tile originTile, Tile destinationTile, List <List <Tile> > map) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Distinct(); current.listOfTiles.Remove(originTile); return(current.listOfTiles); } closed.Add(current.lastTile); current.lastTile.generateNeighbours(map); Debug.Log(current.lastTile.gridPosition + " with nb of " + current.lastTile.neighbours.Count); foreach (Tile t in current.lastTile.neighbours) { TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } return(null); }
public static List<Tile> FindHighlight(Tile originTile, int movementPoints, Vector2[] occupied, bool staticRange, bool dontremoveorigin) { List<Tile> closed = new List<Tile>(); List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); if (staticRange) originPath.addStaticTile(originTile); else originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.costOfPath > movementPoints + 1.5f) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (t.impassible || occupied.Contains(t.gridPosition)|| (GameManager.instance.GetComponent<GameManager>(). playerTurns[GameManager.instance.GetComponent<GameManager>().PlayerTurnIndex].GetPhalanx()==true&&t.frontLiners<16)) continue; TilePath newTilePath = new TilePath(current); if (staticRange) newTilePath.addStaticTile(t); else newTilePath.addTile(t); open.Add(newTilePath); } } closed.Remove(originTile); closed.Distinct(); if (dontremoveorigin && !occupied.Contains(originTile.gridPosition)) closed.Add(originTile); return closed; }
private static void NormalExpand(TilePath current, List <Tile> enemyLocation, List <Tile> neighbours, List <TilePath> open) { for (int i = 0; i < neighbours.Count; i++) { if (enemyLocation.Contains(neighbours[i])) { continue; } else if (Mathf.Abs(current.lastTile.height - neighbours[i].height) >= minHeightToClimb) { continue; } TilePath newTilePath = new TilePath(current); newTilePath.addTile(neighbours[i]); open.Add(newTilePath); } }
public static List <Tile> FindHighlight(Tile originTile, int movementPoints) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.costOfPath > movementPoints + 1) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (t.impassible) { continue; } TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } closed.Remove(originTile); return(closed); }
public static List <Tile> FindPath(Tile originTile, Tile destinationTile) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Remove(originTile); return(current.listOfTiles); } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (t.impassible) { continue; } TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } return(null); }
/* public static List<Tile> FindHighlight(Tile originTile, int movementPoints) { return FindHighlight(originTile, movementPoints, new Vector2[0], false); } public static List<Tile> FindHighlight(Tile originTile, int movementPoints, bool staticRange) { return FindHighlight(originTile, movementPoints, new Vector2[0], staticRange); } public static List<Tile> FindHighlight(Tile originTile, int movementPoints, Vector2[] occupied) { return FindHighlight(originTile, movementPoints, occupied, false); } */ public static List<Tile> FindHighlight(Tile originTile, int movementPoints) { List<Tile> closed = new List<Tile>(); List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); //if (staticRange) originPath.addStaticTile(originTile); //else originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } // each tile cost is 1, could change this later if (1 > movementPoints + 1) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if (!t.isPassable || t.isOccupied) continue; TilePath newTilePath = new TilePath(current); //if (staticRange) newTilePath.addStaticTile(t); //else newTilePath.addTile(t); open.Add(newTilePath); } } closed.Remove(originTile); closed.Distinct(); return closed; }
public static TilePath FindPath(GameTile originTile, GameTile destinationTile) { List <GameTile> closed = new List <GameTile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { return(current); } closed.Add(current.lastTile); foreach (GameTile tile in current.lastTile.neighbors) { TilePath newTilePath = new TilePath(current); newTilePath.addTile(tile); open.Add(newTilePath); } } closed.Remove(originTile); return(null); }
// this method is different because it needs to find a path between impassible tiles. public static List<Tile> FindPathBetweenRooms(Tile originTile, Tile destinationTile, List<List<Tile>> map) { List<Tile> closed = new List<Tile>(); List<TilePath> open = new List<TilePath>(); TilePath originPath = new TilePath(); originPath.addTile(originTile); open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.lastTile == destinationTile) { current.listOfTiles.Distinct(); current.listOfTiles.Remove(originTile); return current.listOfTiles; } closed.Add(current.lastTile); current.lastTile.generateNeighbours(map); Debug.Log (current.lastTile.gridPosition + " with nb of " + current.lastTile.neighbours.Count); foreach (Tile t in current.lastTile.neighbours) { TilePath newTilePath = new TilePath(current); newTilePath.addTile(t); open.Add(newTilePath); } } return null; }
public static List <Tile> FindHighlight(Tile originTile, int movementPoints, Vector2[] occupied, bool staticRange) { List <Tile> closed = new List <Tile>(); List <TilePath> open = new List <TilePath>(); TilePath originPath = new TilePath(); if (staticRange) { originPath.addStaticTile(originTile); } else { originPath.addTile(originTile); } open.Add(originPath); while (open.Count > 0) { TilePath current = open[0]; open.Remove(open[0]); if (closed.Contains(current.lastTile)) { continue; } if (current.costOfPath > movementPoints + 1) { continue; } closed.Add(current.lastTile); foreach (Tile t in current.lastTile.neighbors) { if ( //t.impassable || occupied.Contains(t.gridPosition)) { continue; } TilePath newTilePath = new TilePath(current); if (staticRange) { newTilePath.addStaticTile(t); } else { newTilePath.addTile(t); } open.Add(newTilePath); } } closed.Remove(originTile); // closed.Remove(alliedUnitTiles), which is something we'll have to define and add to the method that determines that stuff, // just like it determines that we can't move past occupied tiles // we'll have to hope this doesn't obliterate pathing. // if it does i'm not sure what to do yet closed.Distinct(); return(closed); }
//Esse highlight vai "atirar" pra todo lado, sem um destino especifico, apenas indo até os pontosDeMovimento deixarem public static List <Tile> FindHighlight(Tile tileDeOrigem, int pontosDeMovimento) { List <Tile> closed = new List <Tile>(); //aqui são aqueles Tiles que ja foram "computados" e que vão voltar pro BatalhaController List <TilePath> open = new List <TilePath>(); //Tiles que ainda não foram processados UnidadeNoTabuleiro unidadeAtual = BatalhaController.instancia.unidadesNoTabuleiro[BatalhaController.instancia.unidadeAtualIndex]; TilePath caminhoDeOrigem = new TilePath(); //Começando um um novo caminho caminhoDeOrigem.addTile(tileDeOrigem); //Esse caminho parte da origem open.Add(caminhoDeOrigem); //Guardando esse caminho nas tiles opens, porque se tu der closed na origem so vai da pra fazer o primeiro caminho while (open.Count > 0) //Enquanto houver tiles ainda não processados.... { TilePath atual = open[0]; open.Remove(open[0]); if (closed.Contains(atual.ultimoTile)) { continue; //Se esse tile ja foi fechado, não há porque computar } if (atual.custoDoCaminho > pontosDeMovimento + 1) { continue; //Se acabou os pontos de movimento } closed.Add(atual.ultimoTile); foreach (Tile t in atual.ultimoTile.vizinhos) { if (t.instransponivel) { continue; } if ((t.ocupado && !unidadeAtual.gridDeAtaque)) { continue; } if (unidadeAtual.gridDeMovimento && t.classesRestritas.Contains(unidadeAtual.unidadeAssociada.classe)) { continue; } TilePath newTilePath = new TilePath(atual); newTilePath.addTile(t); open.Add(newTilePath); } } //Salvador, aqui vai verificar se caso os pontos de movimento forem muito poucos, adicionar todos os vizinhos //da origem pra evitar atolamento, isso não ignora tiles instraponiveis ou ocupados, apenas o custo da caminho if (unidadeAtual.gridDeMovimento) { //Checar se tem algo na lista de tiles além dos vizinhos do tile de origem //Caso tenha e porque ele pode ser mover em alguma direção além dessa sem estar atolado if (closed.Count == 0 || closed.Any(x => tileDeOrigem.vizinhos.Any(y => x != y))) { foreach (Tile vizinho in tileDeOrigem.vizinhos) { if (vizinho.instransponivel || vizinho.ocupado || vizinho.classesRestritas.Contains(unidadeAtual.unidadeAssociada.classe)) { continue; } closed.Add(vizinho); } } } closed.Remove(tileDeOrigem); return(closed); }