void AddNodesToFrontier(int x, int y) { if (x >= 0 && x < gridWidth && y >= 0 && y < gridHeight) { Vector3 next = new Vector3(x, y); float new_cost = costSoFar[current] + gridScript.GetMovementCost(pos[x, y]); if (!costSoFar.ContainsKey(next) || new_cost < costSoFar[next]) { costSoFar[next] = new_cost; float priority = new_cost + hueristic.Hueristic(x, y, start, goal, gridScript); frontier.Enqueue(next, priority); cameFrom[next] = current; } } }
private void AddNodesToFrontier(int x, int y) //this is important to understand heuristics { if (x < 0 || x >= _gridWidth || y < 0 || y >= _gridHeight) { return; } var next = new Vector3(x, y); var new_cost = _costSoFar[_current] + gridScript.GetMovementCost(_pos[x, y]); if (_costSoFar.ContainsKey(next) && (new_cost >= _costSoFar[next])) { return; // check in all the added nodes, who has the least cost, this is complex } _costSoFar[next] = new_cost; //store value var priority = new_cost + hueristic.Hueristic(x, y, _start, _goal, gridScript); //the heuristics is the step next to next step, it's like an adjustment/weight to future moves _frontier.Enqueue(next, priority); _cameFrom[next] = _current; }
private void AddNodesToFrontier(int x, int y) { if (x < 0 || x >= _gridWidth || y < 0 || y >= _gridHeight) { return; } var next = new Vector3(x, y); var new_cost = _costSoFar[_current] + gridScript.GetMovementCost(_pos[x, y]); if (_costSoFar.ContainsKey(next) && !(new_cost < _costSoFar[next])) { return; } _costSoFar[next] = new_cost; var priority = new_cost + hueristic.Hueristic(x, y, _start, _goal, gridScript); _frontier.Enqueue(next, priority); _cameFrom[next] = _current; }