public Node(int x, int y, Tile tile, RacerEquipement equipement) { this.x = x; this.y = y; this.worldPosition = tile.transform.position; this.travelCost = tile.travelCost / equipement.GetSpeedFactorFor(tile.type); }
public GraphNode(int x, int y, Tile tile, RacerEquipement equipement) { this.x = x; this.y = y; this.worldPosition = tile.transform.position; this.edges = new List <GraphEdge>(); travelCost = tile.travelCost / equipement.GetSpeedFactorFor(tile.type); }
public PathGrid(Tile[,] tiles, RacerEquipement equipement) { gridSize = new Vector2Int(tiles.GetLength(0), tiles.GetLength(1)); nodes = new Node[gridSize.x, gridSize.y]; for (int x = 0; x < gridSize.x; x++) { for (int y = 0; y < gridSize.y; y++) { nodes[x, y] = new Node(x, y, tiles[x, y], equipement); } } }
public PathGraph(Tile[,] tiles, RacerEquipement equipement) { nodes = new List <GraphNode>(); graphSize = new Vector2Int(tiles.GetLength(0), tiles.GetLength(1)); for (int x = 0; x < graphSize.x; x++) { for (int y = 0; y < graphSize.y; y++) { nodes.Add(new GraphNode(x, y, tiles[x, y], equipement)); } } // Link edges for (int x = 0; x < graphSize.x; x++) { for (int y = 0; y < graphSize.y; y++) { if (x - 1 >= 0) { nodes[y + x * graphSize.y].edges.Add(new GraphEdge( nodes[y + x * graphSize.y], nodes[y + (x - 1) * graphSize.y], tiles[x, y].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x, y].type)) + tiles[x - 1, y].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x - 1, y].type)) )); } if (x + 1 < graphSize.x) { nodes[y + x * graphSize.y].edges.Add(new GraphEdge( nodes[y + x * graphSize.y], nodes[y + (x + 1) * graphSize.y], tiles[x, y].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x, y].type)) + tiles[x + 1, y].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x + 1, y].type)) )); } if (y - 1 >= 0) { nodes[y + x * graphSize.y].edges.Add(new GraphEdge( nodes[y + x * graphSize.y], nodes[y - 1 + x * graphSize.y], tiles[x, y].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x, y].type)) + tiles[x, y - 1].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x, y - 1].type)) )); } if (y + 1 < graphSize.y) { nodes[y + x * graphSize.y].edges.Add(new GraphEdge( nodes[y + x * graphSize.y], nodes[y + 1 + x * graphSize.y], tiles[x, y].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x, y].type)) + tiles[x, y + 1].travelCost / (2f * equipement.GetSpeedFactorFor(tiles[x, y + 1].type)) )); } } } }
public DijkstraEngine(Tile[,] tiles, RacerEquipement equipement) { this.tiles = tiles; graph = RebuildPathGraph(tiles, equipement); }
public PathGraph RebuildPathGraph(Tile[,] tiles, RacerEquipement equipement) { return(new PathGraph(tiles, equipement)); }
public AStarEngine(Tile[,] tiles, RacerEquipement equipement) { this.tiles = tiles; grid = RebuildPathGrid(tiles, equipement); }