getHeuristicDistanceFrom method

  1. @override
num getHeuristicDistanceFrom(
  1. SimpleState node, {
  2. FindPathParams<Action<State>>? params,
})

Returns the heuristic distance from node to the goal.

Implementation

@override
num getHeuristicDistanceFrom(SimpleState node, {FindPathParams? params}) {
  num result = 0;
  Set stateKeys = _getMapKeysUnion(facts!, node.facts);
  for (var key in stateKeys) {
    if (!facts!.containsKey(key) || !node.facts!.containsKey(key)) {
      continue;
    } else if (facts![key] != node.facts![key]) {
      var value = facts![key];
      var otherValue = node.facts![key];
      if (value is num && otherValue is num) {
        result += ((value as int) - (otherValue as int)).abs();
      } else {
        result += DEFAULT_COST;
      }
    }
  }
  return result;
}