How to code a pathfinder where the path weight changes depending on how long you move on a certain terrain?

I am working on an isometric game and I have a basic understanding of how A* pathfinding works and how we can pass in the effective “weight” for a tile to alter how favorable the said tile is.

However, I wanted to implement something where the “weight” is not constant but changes: (there could be many of other cases but)

  • The more the unit continues on a certain type of tile the “weight” gets lighter and more favorable.

  • Suppose there are 2 long strips of tiles one of type1 and other of type2 with type1 giving a weight of 2 for each tile while the tile of type2 has weight of 4 initially but decreases by 1 (down to a minimum of 1) for each type2 tile moved over in succession (but this “buff” gets reset if you move into some other type of tile) - shown in img below:

  • If the strip is even just 7 tiles long, moving along only the type2 tiles is technically shorter(13 weight as opposed to 14 weight of going along type1 tiles) but due to how the basic A* pathfinding method works the algorithm ends up giving the path only along type1 tiles.

  • Is it possible to somehow modify things so that this sort of functionality can be implemented without having to check “ALL” the possible paths.

I mean you can just modify the data? What’s the problem here?

I assume you have some 2D array or whatever of position data with weights, or some kind of weight for each triangle in a mesh, or whatever. So if things change in the game, you change that data.

If you want different entities to move differently through the world, you just need to send in whatever data about your entity that’s relevant to path cost calculation to your A* implementation.

If you want to update the path calculation as your agent is moving, you’ll need to figure out when that needs to happen, and then re-calculate the path. This is the hardest part, as it’ll mean that you calculate a lot more often, which can become expensive, but generally you want to re-calculate a path from your current position to the end whenever anything that influences movement can have changed.